<?php

namespace Entity\Model;

use Helpers\QueryBuilder\QueryBuilder;

class SousFamille extends QueryBuilder
{
    protected string $table = 'SSFAMILL with (nolock)';
    protected string $primaryKey = 'CODE_SFA';
    protected string $libelle = 'DESIGNAT';

    /**
     * @param array<mixed> $listeData
     * @return array<mixed>
     */
    public function getListeTrad($listeData = [])
    {
        if (!$listeData) {
            return [];
        }

        $arrayReq = [
            ':langue' => $_SESSION['Session_Langue'],
        ];

        $req = "select 
                    SSFAMILL.CODE_SFA, ISNULL(TRAD_SFA.DESIGNAT, SSFAMILL.DESIGNAT) DESIGNAT 
                from SSFAMILL with (nolock)
                left join TRAD_SFA with (nolock) on TRAD_SFA.CODE_SFA = SSFAMILL.CODE_SFA and TRAD_SFA.COD_LNG = :langue
                where 1=1";

        $req .= " AND ".$this->makeWhereIn('SSFAMILL.CODE_SFA', $listeData, $arrayReq);

        $requete = $this->pdo->prepare($req);
        $requete->execute($arrayReq);
        $return = $requete->fetchAll($this->pdo::FETCH_ASSOC);
        
        if ($return) {
            return $return;
        } else {
            return [];
        }
    }
}
