<?php

namespace Modules\Connexion\Repository;

use Helpers\QueryBuilder\AbsRepository;

class ControleConnexionRepo extends AbsRepository
{
    /**
     * @return array<mixed>
     */
    public function nbUser(string $application = '')
    {
        $req = "SELECT 
                    COUNT(*) total
                FROM HASTUTIL WITH(NOLOCK) 
                WHERE DTE_OUV<=:date1 AND (DTE_FERM='00000000' OR DTE_FERM>=:date2)";

        if ($application == 'PROC') {
            $req .= " and ACCOXAPR=0x54";
        } elseif ($application == 'MOB') {
            $req .= " and ACCMOB=0x54";
        }

        $arrayReq = [
            ':date1' => date('Ymd'),
            ':date2' => date('Ymd'),
        ];

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

    /**
     * Summary of getInfoUser
     * @param string $login
     * @return array<mixed>
     */
    public function getInfoUser(?string $login = null)
    {
        $req = "select * from HASTUTIL where upper(CODE) = upper(:login) AND DTE_OUV <= '".date('Ymd')."' and (DTE_FERM > '".date('Ymd')."' or DTE_FERM = '00000000') ";

        $arrayReq = [
            ':login' => $login
        ];

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