<?php
namespace Modules\Commande\Controller;

use Skeleton\Controller\Controller;

use Entity\Model\DaEntet;
use Helpers\Outil\Sql;
use Helpers\Validator\Validator;
use GuzzleHttp\Psr7\Response;
use Helpers\Trad\Trad;
use Modules\Commande\Repository\CreationCommande;
use Modules\Commande\Service\CreationCommandeService;

class ValidatorLigneCdeController extends Controller
{
    /**
     * @return Response
     */
    public function validatorSaisieAction()
    {
        $post  = $this->request->getParsedBody();
        $nomChamp   = $post['nomChamp'] ?? '';
        $value      = $post['value'];
        $societe    = $post['societe'] ?? '';
        $validator = $this->createValidator();
        
        if ($post['controle'] == 'DA') {
            $validator->CAControleDA($value, $nomChamp, $societe);
        } elseif ($post['controle'] == 'ARTICLE') {
            $validator->CAControleArticle($value, $post['CODE_FOU'], $nomChamp);
        } elseif ($post['controle'] == 'QTE') {
            $validator->CAControleQTE($value, $nomChamp, ($value['UNITE']??''));
        } elseif ($post['controle'] == 'PU') {
            $validator->CAControlePU($value, $nomChamp);
        } elseif ($post['controle'] == 'DATELIV') {
            $validator->CAControleDateLivraison($value, $nomChamp);
        }
        

        if ($validator->isValid()) {
            return new Response(200, [
                
            ], $validator->getError());
        } elseif ($validator->isNonBloquant()) {
            return new Response(200, [
                
            ], $validator->getErrorNonBloquant(true));
        } else {
            return new Response(200, [
                
            ], $validator->getError());
        }
    }
}
