<?php

namespace Modules\Additional\Specifique\Client89\Modules\Panier\Service;

use Entity\Model\Centre;
use Helpers\ChampsSupplementaire\ChampSupp;
use Helpers\Outil\Sql;

class InitSpecifique
{
    public static function getCentreLivraison(\PDO $pdo, string $societe, string $centreLivSession):string
    {
        $specifique = Sql::dilispec($pdo, 'PARAMNGE', 'NCS_SECTIMPU_CODE_CTR_LIVR');

        if ($specifique) {
            $code_enr = ChampSupp::autoCompletCodeEnrImputations($pdo, 'SECTIMPU', $_SESSION['Session_SectionImputation'], $societe);

            $valueCS = ChampSupp::getValueCS('SECTIMPU', $code_enr, $specifique, $pdo);

            $centreFound = (new Centre($pdo))->find($valueCS);
            if ($centreFound) {
                return $valueCS;
            }
        }

        return $centreLivSession;
    }
}
