<?php

namespace Modules\ProjetAchat\Repository;

class Planning
{
    private $pdo;

    public function __construct(\PDO $pdo)
    {
        $this->pdo          = $pdo;
    }
    
    /**
     * @return array<mixed>
    */
    // phpcs:ignore
    public function planning_GetMaxVersion(int $idDoa): ?array
    {
        $req = 'select max(ID_VERSION) as max_id from DOA_HISTO_PLANNING_ENT with (nolock) where ID_DOA= :idDoa';

        $arrayReq = [
            ':idDoa' => $idDoa,
        ];
        
        $requete = $this->pdo->prepare($req);
        $requete->execute($arrayReq);
        
        return $requete->fetch();
    }
    
    // phpcs:ignore
    public function planning_Histo_InsertEntete(int $idDoa, int $idVersion, string $commentaire = ''): void
    {
        $req = "insert into DOA_HISTO_PLANNING_ENT(ID_DOA, ID_VERSION, DATE_HISTO, HEURE_HISTO, COMMENTAIRE) values ( :idDoa, :idVersion,  '".date('Ymd')."', '".date('His')."', :commentaire)";
    
        $arrayReq = [
            ':idDoa' => $idDoa,
            ':idVersion' => $idVersion,
            ':commentaire' => $commentaire
        ];
        
        $requete = $this->pdo->prepare($req);
        $requete->execute($arrayReq);
    }
    
    // phpcs:ignore
    public function planning_Histo_InsertLignes(string $typeObjet, int $idObjet, int $idVersion): void
    {
        $req = "insert into DOA_HISTO_PLANNING (ID_DOA, ID_TACHE, ID_VERSION, DATE_DEB, DATE_FIN)
				select ID_OBJET, ID_TACHE, :idVersion as ID_VERSION, DATE_DEB, DATE_FIN from DOA_TACHES with(nolock) where TYPE_OBJET = :typeObjet and ID_OBJET=:idObjet";
        
        $arrayReq = [
            ':typeObjet' => $typeObjet,
            ':idObjet' => $idObjet,
            ':idVersion' => $idVersion
        ];
        
        $requete = $this->pdo->prepare($req);
        $requete->execute($arrayReq);
    }
}
