<?php

namespace Modules\Suivi\Rules;

use Helpers\Outil\Roles;
use Modules\GlobalApplication\Repository\LicenceOxalys;
use Psr\Http\Message\ServerRequestInterface;

class SuiviCde
{
    protected ServerRequestInterface $request;
    protected \PDO $pdo;
        
    /**
     * __construct
     *
     * @param  ServerRequestInterface $request
     * @return void
     */
    public function __construct(ServerRequestInterface  $request, \PDO $pdo)
    {
        $this->request  = $request;
        $this->pdo      = $pdo;
    }
    
    /**
     * init
     *
     * @return bool
     */
    public function init() : bool
    {
        $typeSuivi  = $this->request->getAttribute('context');

        if ($typeSuivi == 'CdeToRate' || $typeSuivi == 'SCdeToRate') {
            return (((new LicenceOxalys($this->pdo))->noteFourActive() && roles::droitsUtilisateur($this->pdo, 'HA_NOT_VAL'))
            );
        } else {
            return (Roles::droitsUtilisateur($this->pdo, 'HA_DA_CRE') || $_SESSION['SIG_CDE'] || Roles::droitsUtilisateur($this->pdo, 'HA_CA_LIS'));
        }
    }


    /**
     * @return bool
     */
    public function liste(): bool
    {
        return true;
    }

    /**
     * @return bool
     */
    public function send(): bool
    {
        return true;
    }

    /**
     * @return bool
     */
    public function ajaxDetails(): bool
    {
        return true;
    }

    /**
     * @return bool
     */
    public function ajaxDetailsLigne(): bool
    {
        return true;
    }
}
