<?php

namespace Modules\Additional\Specifique\Client71\Modules\Liste\Service;

use Helpers\Outil\Sql;

class SpecifiqueSI
{
    /**
     * @param \PDO $pdo
     * @param array<mixed> $array
     * @return string
     */
    public static function clauseSI(\PDO $pdo, $array) : string
    {

        $isSISecto  = Sql::paravrac($pdo, 'PARAMSTE', 'SISECTOR') == 'O' ? true : false;

        $req =  " and (
                    SECTIMPU.CODE_DIR = '{$array['CenterEmetteur']}' 
                    or exists (
                        select 
                            null
                        from SECTIMPU with(nolock)
                        where (
                            SECTIMPU.CODE_SI in ( 
                                SELECT 
                                PARAMDICO.LIBELLE 
                                from PARAMDICO with (nolock) 
                                WHERE  PARAMDICO.TYPEDICO = 'LEONG_DIRSI'
                                AND    PARAMDICO.ID1= '" . ($isSISecto ? ($array['codeSte']) : '') . "' 
                                AND PARAMDICO.ID2= '{$array['CenterEmetteur']}' 
                            )
                        )
                    )
                )
        ";

        return $req;
    }
}
