<?php

namespace common\logic\Subscription\ProductSubscription\Repository;

use common\logic\AbstractRepository;
use common\logic\Subscription\Subscription\Model\Subscription;

class ProductSubscriptionRepository extends AbstractRepository
{
    protected ProductSubscriptionRepositoryQuery $query;

    public function loadDependencies(): void
    {
        $this->loadQuery(ProductSubscriptionRepositoryQuery::class);
    }

    /**
     * Retourne les options de base nécessaires à la fonction de recherche.
     */
    public function getDefaultOptionsSearch(): array
    {
        return [
            self::WITH => ['product'],
            self::JOIN_WITH => [],
            self::ORDER_BY => '',
            self::ATTRIBUTE_ID_PRODUCER => ''
        ];
    }

    public function findProductSubscriptionsBySubscription(Subscription $subscription): array
    {
        return $this->createDefaultQuery()
            ->filterBySubscription($subscription)
            ->find();
    }
}