<?php

namespace common\logic\Subscription\ProductSubscription\Repository;

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

class ProductSubscriptionRepository extends AbstractRepository
{
    protected ProductSubscriptionRepositoryQuery $query;

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

    /**
     * Retourne les options de base nécessaires à la fonction de recherche.
     */
    public function getDefaultOptionsSearch(): array
    {
        return [
            'with' => ['product'],
            'join_with' => [],
            'orderby' => '',
            'attribute_id_producer' => ''
        ];
    }

    public function findProductSubscriptionsBySubscription(Subscription $subscription): array
    {
        return ProductSubscription::searchAll([
            'id_subscription' => $subscription->id
        ]);
    }
}