<?php

namespace Modules\Additional\Specifique\Client71\Modules\Administration\Repository;

use Helpers\Ariane\Ariane;
use Helpers\QueryBuilder\AbsRepository;
use Skeleton\Controller\Controller;

class ChantierRepository extends AbsRepository
{
    /**
     * @param array<mixed> $post
     * @param string $codeSte
     * @param string $codeDir
     * @return array<mixed>
     */
    public function getSIByDir($post, string $codeSte = '', string  $codeDir = '')
    {
        $req = "select CODE_SI, LIBELLE, CODE_STE, CODE_DIR from SECTIMPU 	with (nolock)	
                where 
                CODE_STE = :codeSte
                and CODE_DIR <> :codeDir
                and CODE_SI Not in ( select LIBELLE CODESI 
                                    from  PARAMDICO with (nolock) 
                                    where PARAMDICO.TYPEDICO='LEONG_DIRSI' and PARAMDICO.ID1= :codeSte2 and PARAMDICO.ID2= :codeDir2
                                )";

        $arrayReq = [
            ':codeSte'  => $codeSte,
            ':codeDir'  => $codeDir,
            ':codeSte2'  => $codeSte,
            ':codeDir2'  => $codeDir,
        ];

        $paginatorGestion = new \Helpers\Pagination\PaginatorGestion();
        $paginatorGestion->injecterSqlCount(
            $req,
            $post,
            $arrayReq,
            $this->pdo,
            false
        );

        $whereArray = \Helpers\Filter\FilterTable::splitFilter($post, 0, 0, 1, 0);

        if (!empty($whereArray)) {
            $req .= $whereArray[0].$whereArray['tri'];
            
            if (!empty($whereArray[1])) {
                $arrayReq = array_merge($arrayReq, $whereArray[1]);
            }
        }

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

    /**
     * @param string $codeSte
     * @param string $codeDir
     * @return array<mixed>
     */
    public function getSiByDirLink(string $codeSte = '', string  $codeDir = '')
    {
        $req = "select PARAMDICO.LIBELLE CODE_SI,SECTIMPU.LIBELLE LIBELLE  
                from  PARAMDICO with (nolock)
                left join SECTIMPU with (nolock) on SECTIMPU.CODE_SI = PARAMDICO.LIBELLE AND PARAMDICO.ID1 = SECTIMPU.CODE_STE
                where PARAMDICO.TYPEDICO='LEONG_DIRSI'
                and PARAMDICO.ID1=:codeSte
                and PARAMDICO.ID2=:codeDir";

        $arrayReq = [
            ':codeSte'  => $codeSte,
            ':codeDir'  => $codeDir,
        ];

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