<?php

namespace Modules\Catalogue\Validator;

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

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

        return $listeLigne;
    }

    /**
     * @param array<mixed> $post
     * @param string $idLigne
     * @return array<mixed>
     */
    private function validateLigneTranso($post, string $idLigne)
    {
        $this->isStringAvecEspace($this->trad->t('Valeur d\'entrée').' '.$post['LGTRANSCO'.$idLigne], $post['VALENTREE'.$idLigne], 1, 255);
        $this->isStringAvecEspace($this->trad->t('Valeur de remplacement').' '.$post['LGTRANSCO'.$idLigne], $post['VALREMPLA'.$idLigne], 1, 255);

        return [
            'VALENTREE' => $post['VALENTREE'.$idLigne],
            'VALREMPLA' => $post['VALREMPLA'.$idLigne],
        ];
    }
}
