<?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->query = $this->loadService(PointSaleDistributionRepositoryQuery::class);
    }

    public function getDefaultOptionsSearch(): array
    {
        return [
            'with' => ['distribution', 'pointSale'],
            'join_with' => [],
            'orderby' => '',
            'attribute_id_producer' => ''
        ] ;
    }

    public function findOnePointSaleDistribution(Distribution $distribution, PointSale $pointSale): ?PointSaleDistribution
    {
        return PointSaleDistribution::searchOne([
            'id_distribution' => $distribution->id,
            'id_point_sale' => $pointSale->id
        ]);
    }

    public function findPointSaleDistributionsByDistribution(Distribution $distribution): array
    {
        return PointSaleDistribution::searchAll([
            'id_distribution' => $distribution->id
        ]) ;
    }

    public function countPointSaleDistributionsByDistribution(Distribution $distribution): int
    {
        return PointSaleDistribution::searchCount([
            'id_distribution' => $distribution->id
        ]);
    }
}