<?php

namespace Entity\Model;

use Helpers\Outil\Sql;
use Helpers\QueryBuilder\QueryBuilder;
use Helpers\Trad\ITrad;
use Modules\Stock\Helper\StringHelper;
use PDO;

class SbsLign extends QueryBuilder
{
    protected string $table = 'SBS_LIGN with (nolock)';
    protected string $primaryKey = '';

    public function __construct(PDO $pdo)
    {
        parent::__construct($pdo);
        $this->primKey = ['NO_BS', 'NO_LIG'];
    }

    /**
     * @param array<string,mixed> $ligneBonSortie
     * @return void
     */
    public function processAndMerge(array $ligneBonSortie): void
    {
        $ligneBonSortie['REAPPRO_FAIT'] = Sql::toBool($ligneBonSortie['REAPPRO_FAIT']);
        StringHelper::toFloat($ligneBonSortie, ['QTE_SORTI', 'PRIX_SORT']);
        $this->merge($ligneBonSortie);
    }

    /**
     * @param ITrad $trad
     * @return array<mixed>
     */
    public function getArchitecture(ITrad $trad)
    {
        return [
            'NO_BS'     => ['nomChamp' => $trad->t('Numéro de BS')],
            'NO_LIG'    => ['nomChamp' => $trad->t('Numéro de ligne BS')],
            'NO_DS'     => ['nomChamp' => $trad->t('Numéro de DS')],
            'NO_LIG_DS' => ['nomChamp' => $trad->t('Numéro de ligne BS')],
            'ART'       => ['nomChamp' => $trad->t('Code article')],
            'QTE_SORTI' => ['nomChamp' => $trad->t('Quantité de sortie')],
            'PRIX_SORT' => ['nomChamp' => $trad->t('Prix de sortie')],
            'SECTIMPU'  => ['nomChamp' => $trad->t('Section d\'imputation')],
            'CODE_COMP' => ['nomChamp' => $trad->t('Code complémentaire')],
            'SSCPTEANA' => ['nomChamp' => $trad->t('Sous-compte d\'analyse')],
        ];
    }
}
