<?php

namespace Modules\Stock\Repository;

use Exception;
use Helpers\QueryBuilder\AbsRepository;
use Modules\Stock\Trait\Repo\EnteteRepoTrait;

class FamilleRepo extends AbsRepository
{
    use EnteteRepoTrait;

    /**
     * @param array<string,mixed> $post
     * @return array<int, array<string,string>>
     * @throws Exception
     */
    public function listFamilles(array $post): array
    {
        $arrayReq = [];
        $req = "SELECT
                    F.DESIGNAT + ' (' + F.CODE_FAM + ')' AS F_DESIGNAT_CODE,
                    F.CODE_FAM AS CODE_FAM,
                    SF.CODE_SFA AS CODE_SFA,
                    SF.DESIGNAT AS SF_DESIGNAT
                FROM FAMILLE F
                LEFT JOIN SSFAMILL SF ON F.CODE_FAM = SF.CODE_FAM WHERE 1=1 ";

        $requete = $this->applyFilter($req, $arrayReq, $post);

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