<?php
namespace Modules\Index\Repository;

class CreationCompte
{
    protected $pdo;
    
    public function __construct(\PDO $pdo)
    {
        $this->pdo = $pdo;
    }
    
    
    /**
     * getInfoForUser
     * @param String $login
     * @return Array<string>
     */
    public function getInfoForUser(String $login) : ?array
    {
        $sql = ' select HASTUTIL.*, DILISPEC.LIB01DICO as SIGNAT_DA_FAV from HASTUTIL with (nolock) ' . " left outer join DILISPEC with (nolock) on CODEDICO = HASTUTIL.CODE and DILISPEC.TYPEDICO = 'ETDESDAFAV' " . " where HASTUTIL.CODE = '" . strtoupper($login) . '\'';
        
        $requete = $this->pdo->prepare($sql);
        
        $requete->execute();
        return $requete->fetch($this->pdo::FETCH_ASSOC);
    }
    
    /**
     * listeDomaine
     * @return Array<mixed>
     */
    public function listeDomaine() : ?array
    {
        $req = "select ID1 CODE_DOMAINE from PARAMDICO with(nolock) where TYPEDICO='PARAM_DOMAINES_AD'";
        
        $requete = $this->pdo->prepare($req);
        
        $requete->execute();
        return $requete->fetchAll($this->pdo::FETCH_ASSOC);
    }
    
    /**
     * checkEmailDispo
     * @param String $email
     * @return Array<string>
     */
    public function checkEmailDispo(String $email) : ?array
    {
        $req = "select * from HASTUTIL with (nolock) where EMAIL= :mail";
        
        $arrayReq = [':mail' => $email];
        
        $requete = $this->pdo->prepare($req);
        $requete->execute($arrayReq);
        return $requete->fetch($this->pdo::FETCH_ASSOC);
    }
}
