<?php

namespace Modules\ProjetAchat\Repository;

use Helpers\QueryBuilder\AbsRepository;

class ElementConcerned extends AbsRepository
{

    public function deleteElement(int $idDoa, string $typeElem, string $idElem): void
    {
        $req = "DELETE FROM DOA_ELEM where ID_DOA = :idDoa and TYPE_ELEM = :typeElem and ID_ELEM = :idElem";
        
        $arrayReq = [
            ':idDoa' => $idDoa,
            ':typeElem' => $typeElem,
            ':idElem' => $idElem,
        ];
        
        $requete = $this->pdo->prepare($req);
        $requete->execute($arrayReq);
    }
    
    /**
     * @return array<mixed>
    */
    public function elementExistProjet(int $idObjet, string $typeElem, int $idElem): ?array
    {
        $req = "select * from DOA_ELEM with (nolock) where ID_DOA = :idObjet and TYPE_ELEM = :typeElem and ID_ELEM = :idElem";
        
        $arrayReq = [
            ':idObjet' => $idObjet,
            ':typeElem' => $typeElem,
            ':idElem' => $idElem,
        ];
        
        $requete = $this->pdo->prepare($req);
        $requete->execute($arrayReq);
        
        return $requete->fetch();
    }
    
    /**
     * @return array<mixed>
    */
    public function getListElementsConcerned(): ?array
    {
        $req = "select * from DOAR_TYPE_ELEM with (nolock) where MASQUE = 0x46";

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