<?php

namespace Modules\Catalogue\Validator;

use Entity\Model\CataEnt;
use Helpers\Log\LogSysteme;
use Helpers\Parametres\Constante;
use Helpers\Trad\ITrad;
use Helpers\Validator\Validator;

class ControleArticleValidator extends Validator
{
    public function __construct(\PDO $pdo, ITrad $trad)
    {
        $this->pdo = $pdo;
        $this->trad = $trad;
    }

    /**
     * @param string $field
     * @param string $value
     * @param array<mixed> $post
     */
    public function validatorField(string $field, string &$value, $post = []):void
    {
        switch ($field) {
            case 'text_CODEFOUR':
                $this->zoom('Fourniss', $value, $this->trad->t('Fournisseur'), $this->pdo, true);
                break;
            case 'REFARTFOU':
                $this->isStringAvecEspace($this->trad->t('Article fournisseur'), $value, 1, 30);
                break;
            case 'DESIGNLG':
                $this->isStringAvecEspace($this->trad->t('Article fournisseur'), $value, 0, 3000);
                break;
            case 'text_FABRICANT':
                $this->zoom('Fabricant', $value, $this->trad->t('Fabricant'), $this->pdo, true);
                break;
            case 'text_SOUSFAMI':
                $this->zoom('sousFamille', $value, $this->trad->t('Sous-famille'), $this->pdo, true);
                break;
            case 'DESIGNCRT':
                $this->isStringAvecEspace($this->trad->t('Article fournisseur'), $value, 0, 60);
                break;
            case 'REFARTFAB':
                $this->isStringAvecEspace($this->trad->t('Article fabriquant'), $value, 0, 30);
                break;
            case 'text_UNITE':
                $this->zoom('Unite', $value, $this->trad->t('Unite'), $this->pdo, true);
                break;
            case 'text_GAMFABRIC':
                $this->zoom('Gamme', $value, $this->trad->t('Gamme fabricant'), $this->pdo, true, ['filter_egal_CODEFABR' => $post['FABRICANT']]);
                break;
            case 'text_CODOUANE':
                $this->zoom('TVA', $value, $this->trad->t('TVA'), $this->pdo, true);
                break;
            case 'PRIXBASE':
                $this->isFloat($this->trad->t('Prix de base'), $value, Constante::formatPU);
                break;
            case 'PRIXNET':
                $this->isFloat($this->trad->t('Prix net'), $value, Constante::formatPU);
                break;
            case 'text_DEVISE_CAT':
                $this->zoom('Devise', $value, $this->trad->t('Devise'), $this->pdo, true);
                break;
            case 'REMISE':
                $this->isFloat($this->trad->t('Remise'), $value);
                break;
            case 'text_TAUX_TVA':
                $this->zoom('TVA', $value, $this->trad->t('TVA'), $this->pdo, true);
                break;
            case 'CONDITNT':
                $this->isFloat($this->trad->t('Quantité de conditionnement'), $value);
                break;
            case 'TXTCOND':
                $this->isStringAvecEspace($this->trad->t('Libelle de conditionnement'), $value, 0, 30);
                break;
            case 'text_CODEACDR':
                $this->zoom('Acccadre', $value, $this->trad->t('Accord-cadre'), $this->pdo, true);
                break;
            case 'UNSPSC':
                //??
                break;
            case 'text_IDRAYON':
                $this->zoom('Rayon', $value, $this->trad->t('Rayon'), $this->pdo, true);
                break;
            case 'CODEARTI':
                $this->zoom('Articles', $value, $this->trad->t('Article HaPlus'), $this->pdo, true);
                break;
            case 'DELAIREA':
                $this->isInteger($this->trad->t('Délai'), $value);
                break;
            case 'CARACTER':
                break;
            case 'LONGUEUR':
                $this->isFloat($this->trad->t('Longueur'), $value);
                break;
            case 'LARGEUR':
                $this->isFloat($this->trad->t('Largeur'), $value);
                break;
            case 'HAUTEUR':
                $this->isFloat($this->trad->t('Hauteur'), $value);
                break;
            case 'VOLUME':
                $this->isFloat($this->trad->t('Volume'), $value);
                break;
            case 'POIDSBRUT':
                $this->isFloat($this->trad->t('Poids brut'), $value);
                break;
            case 'POIDSNET':
                $this->isFloat($this->trad->t('Poids net'), $value);
                break;
            case 'TYPIMAGE':
                break;
            case 'IMAGE':
                $this->isStringAvecEspace($this->trad->t('chemin'), $value, 0, 255);
                break;
            case 'VALIDITEDU':
                $this->isDate($value, '', '', false, $this->trad->t('Validité du'));
                break;
            case 'VALIDITEAU':
                $this->isDate($value, '', '', false, $this->trad->t('Validité au'));
                break;
            default:
                if ($_SESSION['environnement'] == 'developpement') {
                    $this->setError('Champs '.$field.' inconnu.');
                } else {
                    LogSysteme::prefixErrorLog("Panier : Champs $field inconnu.");
                }
                break;
        }
    }
}
