<?php

namespace Modules\Contrat\Repository;

use Helpers\Filter\FilterTable;
use Helpers\QueryBuilder\AbsRepository;
use Modules\Ajax\Repository\Listes;

class RFARepository extends AbsRepository
{

    /**
     * @param array<mixed> $post
     * @return array<mixed>
     */
    public function getListe(string $idacc, $post = [])
    {
        $req = "select 
                ACD_RFA.CODE_ACD, ACD_RFA.RFA_ID,
                ACD_RFA.LIBELLE, ACD_RFA.DTE_DEBUT, ACD_RFA.DTE_FIN, ACD_RFA.BASE_CALCUL, ACD_RFA.TACITE_RECOND,ACD_RFA.SOLDE, ACD_RFA.COMMENTAIRE, 
                ACD_RFA_LIG.TYPE_RFA, ACD_RFA_LIG.VALEUR_RFA
                from ACD_RFA with (nolock)
                left join ACD_RFA_LIG with (nolock) on ACD_RFA_LIG.CODE_ACD = ACD_RFA.CODE_ACD and ACD_RFA_LIG.RFA_ID = ACD_RFA.RFA_ID
                where ACD_RFA.CODE_ACD = :codeAcd";

        $arrayReq = ['codeAcd' => $idacc];
        
        $req = $this->applyFilter($req, $arrayReq, $post);

        $paginatorGestion = new \Helpers\Pagination\PaginatorGestion();
        $paginatorGestion->injecterSqlCount($req, $post, $arrayReq, $this->pdo);

        return $this->fetchAssocAll($req, $arrayReq);
    }

    /**
    * @param array<string> $post
    */
    public function export(string $idacc, array $post) :\PDOStatement
    {
        $req = "select 
                ACD_RFA.CODE_ACD, ACD_RFA.RFA_ID,
                ACD_RFA.LIBELLE, ACD_RFA.DTE_DEBUT, ACD_RFA.DTE_FIN, ACD_RFA.BASE_CALCUL, ACD_RFA.TACITE_RECOND,ACD_RFA.SOLDE, ACD_RFA.COMMENTAIRE, 
                ACD_RFA_LIG.TYPE_RFA, ACD_RFA_LIG.VALEUR_RFA
                from ACD_RFA with (nolock)
                left join ACD_RFA_LIG with (nolock) on ACD_RFA_LIG.CODE_ACD = ACD_RFA.CODE_ACD and ACD_RFA_LIG.RFA_ID = ACD_RFA.RFA_ID
                where ACD_RFA.CODE_ACD = :codeAcd";

        $arrayReq = ['codeAcd' => $idacc];
        
        return $this->createStatement(
            $this->applyFilter($req, $arrayReq, $post),
            $arrayReq
        );
    }

    /**
     * @return array<mixed>
     */
    public function getRFA(string $idRFA)
    {
        $req = "select 
                ACD_RFA.CODE_ACD, ACD_RFA.RFA_ID,
                ACD_RFA.LIBELLE, ACD_RFA.DTE_DEBUT, ACD_RFA.DTE_FIN, ACD_RFA.BASE_CALCUL, ACD_RFA.TACITE_RECOND,ACD_RFA.SOLDE, ACD_RFA.COMMENTAIRE, 
                ACD_RFA_LIG.TYPE_RFA, ACD_RFA_LIG.VALEUR_RFA
                from ACD_RFA with (nolock)
                left join ACD_RFA_LIG with (nolock) on ACD_RFA_LIG.CODE_ACD = ACD_RFA.CODE_ACD and ACD_RFA_LIG.RFA_ID = ACD_RFA.RFA_ID
                where 1=1 and ACD_RFA.RFA_ID = :idRFA";

        $arrayReq = [':idRFA' => $idRFA];
        
        return $this->fetchAssocOne($req, $arrayReq);
    }
}
