<?php

namespace common\logic\Config\TaxRate\Repository;

use common\logic\AbstractRepository;
use common\logic\Config\TaxRate\Model\TaxRate;

class TaxRateRepository extends AbstractRepository
{
    protected TaxRateRepositoryQuery $query;

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

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

    public function findOneTaxRateById(int $id): ?TaxRate
    {
        return TaxRate::searchOne(['id' => $id]);
    }

    public function findTaxRates(): array
    {
        return TaxRate::find()->all();
    }

    // getTaxRateArray
    public function findTaxRatesAsArray(): array
    {
        $taxRateArrayReturn = [];
        $taxRateArray = $this->findTaxRates();

        foreach($taxRateArray as $taxRate) {
            $taxRateArrayReturn[$taxRate->id] = $taxRate;
        }

        return $taxRateArrayReturn;
    }
}