<?php

namespace Modules\DemandeAchat\Service;

use Helpers\Filter\FiltreAvance\GeneratorCs;
use Helpers\Trad\ITrad;
use Modules\DemandeAchat\Repository\DemandeAchat;
use Skeleton\Router;

class GestionDemandeAchatService
{
    private \PDO $pdo;
    private ITrad $trad;

    /**
     * __construct
     *
     * @param  \PDO $pdo
     * @param  ITrad $trad
     * @return void
     */
    public function __construct(\PDO $pdo, ITrad $trad)
    {
        $this->pdo = $pdo;
        $this->trad = $trad;
    }

    /**
     * setAdvancedFilters
     *
     * @param  array<mixed> $post
     * @return array<mixed>
     */
    public function setAdvancedFilters(array $post): array
    {
        $filtreAvance = new GeneratorCs(
            $post,
            'DA_ENTET',
            'DA_ENTET.NO_DA',
            $this->pdo,
            $this->trad
        );
        $filtreAvance->setFiltre(
            'DA_LIGNE.CODE_ART',
            'liste',
            $this->trad->t('Article'),
            '',
            'Ajax.liste.articles',
            'Articles',
        );
        $filtreAvance->setFiltre(
            'DA_ENTET.DTE_EMISS',
            'date',
            $this->trad->t('Date d\'émission'),
        );
        $filtreAvance->setFiltre(
            'DA_ENTET.DTE_VAL',
            'date',
            $this->trad->t('Date de validation'),
        );
        $filtreAvance->setFiltre(
            'DA_ENTET.DTE_LIV',
            'date',
            $this->trad->t('Date de livraison'),
        );
        $filtreAvance->setFiltre(
            'DA_ENTET.TOTAL_DA',
            'numeric',
            $this->trad->t('Montant HT')
        );
        $filtreAvance->setFiltre(
            'FOU',
            'liste',
            $this->trad->t('Fournisseur'),
            '',
            'Ajax.liste.fournisseur',
            'Fourniss',
            null,
            true
        );
        $filtreAvance->setFiltre(
            'ACD',
            'liste',
            $this->trad->t('Accord-cadre'),
            '',
            'Ajax.liste.accadre',
            'Acccadre',
            null,
            true
        );

        return [
            'filtreAvance' => $filtreAvance->getFiltres(),
            'initFiltreAvance' => $filtreAvance->getInit(),
        ];
    }
}
