<?php

namespace Modules\Catalogue\Validator;

use Helpers\Trad\ITrad;
use Helpers\Validator\Validator;
use Modules\Catalogue\Controller\ParametrageFormatController;

class ValidationValidator extends Validator
{
    /**
     * Summary of validateTranscodage
     * @param mixed $post
     * @return array<mixed>
     */
    public function validateValidation($post)
    {
        $listeLigne = [];
        foreach ($post as $k => $v) {
            if (str_starts_with($k, 'LIGNE')) {
                $idLigne = str_replace('LIGNE', '', $k);
                $listeLigne[] = $this->validateLigne($post, $idLigne);
            }
        }

        return $listeLigne;
    }

    /**
     * @param array<mixed> $post
     * @param string $idLigne
     * @return array<mixed>
     */
    private function validateLigne($post, string $idLigne)
    {
        $this->isInteger($this->trad->t('Ligne'), $post['LIGNE'.$idLigne], 1, 9);
        $this->isStringAvecEspace($this->trad->t('Zone 1').' '.$post['LIGNE'.$idLigne], $post['ZONE1'.$idLigne], 0, 30);
        $this->isStringAvecEspace($this->trad->t('Zone 2').' '.$post['LIGNE'.$idLigne], $post['ZONE2'.$idLigne], 0, 30);

        return [
            'LIGNE'     => $post['LIGNE'.$idLigne],
            'OPERATEUR' => 'E',
            'REGCOMPAR' => $post['REGCOMPAR'.$idLigne],
            'ZONE1'     => $post['ZONE1'.$idLigne],
            'ZONE2'     => $post['REGCOMPAR'.$idLigne] == 'E' ? $post['ZONE2'.$idLigne]:'',
        ];
    }
}
