<?php

namespace Modules\Additional\Specifique\Client94\Modules\Facture\Repository;

use Helpers\QueryBuilder\AbsRepository;
use PDO;

class AjaxFacture extends AbsRepository
{
    
    /**
     * getCsParamdico
     *
     * @param  string $company
     * @param  string $invoiceDate
     * @param  string $cdcCs0
     * @return array<mixed>
     */
    public function getCsParamdico(string $company, string $invoiceDate, string $cdcCs0): array
    {
        $query = "SELECT DISTINCT ALPHA2 AXE1, ALPHA3 AXE3 
        FROM PARAMDICO WITH(NOLOCK)
        WHERE TYPEDICO = 'GRIMALGO13' 
            AND ID1 = :SOCIETE
            AND ID2 = :DATE_FAFO 
            AND ALPHA1 = :CDC_AXE0_CS";

        $params = [
            ':SOCIETE'      => [
                'value'     => $company,
                'option'    => \PDO::PARAM_STR
            ],
            ':DATE_FAFO'    => [
                'value'     => $invoiceDate,
                'option'    => \PDO::PARAM_STR
            ],
            ':CDC_AXE0_CS'  => [
                'value'     => $cdcCs0,
                'option'    => \PDO::PARAM_STR
            ]
        ];

        $this->pdo->prepare($query);

        $data = $this->pdo->prepare($query);
        foreach ($params as $key => $param) {
            $data->bindParam($key, $param['value'], $param['option']);
        }

        $data->execute();

        $return = $data->fetch(PDO::FETCH_ASSOC);

        return $this->lightReturn($return);
    }
}
