<?php

namespace Modules\Commande\Rules;

use Helpers\Outil\Roles;
use Psr\Http\Message\ServerRequestInterface;

class AccRecep
{
    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;
    }
        
    /**
     * create
     *
     * @return bool
     */
    public function create() : bool
    {
        if (Roles::droitsUtilisateur($this->pdo, 'HA_CA_SAR')) {
            return true;
        }
        return false;
    }

    /**
     * detail
     *
     * @return bool
     */
    public function detail() : bool
    {
        if (Roles::droitsUtilisateur($this->pdo, 'HA_CA_SAR')) {
            return true;
        }
        return false;
    }

    public function formUpdate() : bool
    {
        return $this->hasUpdateRight();
    }

    public function update() : bool
    {
        return $this->hasUpdateRight();
    }

    private function hasUpdateRight() :bool
    {
        $droit = [
            'HA_CA_SAR' => Roles::droitsUtilisateur($this->pdo, 'HA_CA_SAR', $_SESSION["Session_Login"]),
            'HA_CA_MAR' => Roles::droitsUtilisateur($this->pdo, 'HA_CA_MAR', $_SESSION["Session_Login"]),
        ];
        return $droit['HA_CA_SAR'] && $droit['HA_CA_MAR'];
    }


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

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