<?php

namespace domain\Distribution\ProductDistribution;

use domain\Distribution\Distribution\Distribution;
use domain\Product\Product\Product;
use domain\_\AbstractRepository;

class ProductDistributionRepository extends AbstractRepository
{
    protected ProductDistributionRepositoryQuery $query;

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

    public function getDefaultOptionsSearch(): array
    {
        return [
            self::WITH => ['product','distribution'],
            self::JOIN_WITH => [],
            self::ORDER_BY => '',
            self::ATTRIBUTE_ID_PRODUCER => ''
        ] ;
    }

    public function findOneProductDistribution(Distribution $distribution, Product $product): ?ProductDistribution
    {
        return $this->createDefaultQuery()
            ->filterByDistribution($distribution)
            ->filterByProduct($product)
            ->findOne();
    }

    public function findProductDistributionsByDistribution(Distribution $distribution): array
    {
        return $this->createDefaultQuery()
            ->filterByDistribution($distribution)
            ->find();
    }

    public function countProductDistributionsByDistribution(Distribution $distribution): int
    {
        return $this->createDefaultQuery()
            ->filterByDistribution($distribution)
            ->count();
    }
}