<?php

namespace common\logic\Distribution\PointSaleDistribution\Repository;

use common\logic\AbstractRepository;
use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Distribution\PointSaleDistribution\Model\PointSaleDistribution;
use common\logic\PointSale\PointSale\Model\PointSale;

class PointSaleDistributionRepository extends AbstractRepository
{
    protected PointSaleDistributionRepositoryQuery $query;

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

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

    public function findOnePointSaleDistribution(Distribution $distribution, PointSale $pointSale): ?PointSaleDistribution
    {
        return $this->createDefaultQuery()
            ->filterByDistribution($distribution)
            ->filterByPointSale($pointSale)
            ->findOne();
    }

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

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