<?php
namespace Modules\Fournisseur\Repository;

use Helpers\QueryBuilder\AbsRepository;

class FircheFournissRepo extends AbsRepository
{
    /**
     * @return array<string>
     */
    public function getFicheInfo(string $fournissId)
    {
        return $this->fetchAssocOne(
            "SELECT 
                FOURNISS.*,
                (
                    SELECT MAX(FOUR_EVE.DTE_EVE)
                    FROM FOUR_EVE with(nolock)
                    WHERE FOUR_EVE.CODE = FOURNISS.CODE
                        AND FOUR_EVE.COD_EVE = 'RIB'
                ) as dateLastRibUpdate
            FROM FOURNISS with(nolock)
            WHERE FOURNISS.CODE = :id",
            [':id' => $fournissId]
        );
    }

    /**
     * @param string $idFrs
     * @return array<mixed>
     */
    public function infoFrs(string $idFrs)
    {
        $req = "select 
                    FOURNISS.*, 
                    COUNTRY.LIBELLE LIB_PAYS, 
                    LANGUES.LIBELLE LIB_LANGUE,
                    REGROUP.LIBELLE LIB_REGROUP
                from FOURNISS with (nolock)
                left join COUNTRY with (nolock) ON COUNTRY.CODE_PAYS = FOURNISS.CODE_PAYS
                left join LANGUES with (nolock) on LANGUES.COD_LNG = FOURNISS.COD_LNG
                left join REGROUP with (nolock) on REGROUP.CODE_REG = FOURNISS.CODE_REGR
                where CODE = :idFrs";

        $arrayReq = [
            ':idFrs' => $idFrs,
        ];

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