<?php

namespace Modules\Commande\Rules;

use Entity\Model\CaEntet;
use Helpers\Outil\Roles;
use Psr\Http\Message\ServerRequestInterface;

class ModificationLigneCommande
{
    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
    {
        $idCommande = $this->request->getAttribute('idCommande');

        if (!$idCommande) {
            return true;
        }

        Roles::droitsUtilisateur($this->pdo, 'HA_CA_MVI');

        $caEntet = new CaEntet($this->pdo);
        $infoCde = $caEntet->find($idCommande);

        if (Roles::droitsUtilisateur($this->pdo, 'HA_CA_CMV') ||(Roles::droitsUtilisateur($this->pdo, 'HA_CA_MVI') && $infoCde['ACH'] == $_SESSION["Session_Login"])) {
            return true;
        }
        return false;
    }


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

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

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

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

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

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

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

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

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

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