<?php

namespace domain\Feature\Feature;

use domain\_\AbstractRepository;

class FeatureRepository extends AbstractRepository
{
    protected FeatureRepositoryQuery $query;

    public function loadDependencies(): void
    {
        $this->loadQuery(FeatureRepositoryQuery::class);
    }
    
    public function getDefaultOptionsSearch(): array
    {
        return [
            self::WITH => ['featureProducers'],
            self::JOIN_WITH => [],
            self::ORDER_BY => 'position ASC',
            self::ATTRIBUTE_ID_PRODUCER => ''
        ];
    }

    public function findOneFeatureById(int $id): ?Feature
    {
        return $this->createQuery()
            ->filterById($id)
            ->findOne();
    }

    public function findOneFeatureByAlias(string $alias): ?Feature
    {
        return $this->createQuery()
            ->filterByAlias($alias)
            ->findOne();
    }

    public function findPaidFeatures(): array
    {
        return $this->createDefaultQuery()
            ->filterIsPaidFeature()
            ->find();
    }
}