<?php

namespace Entity\Model;

use Helpers\QueryBuilder\QueryBuilder;

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

    /**
     * /!\ Note if CODE_STE not present, fallback on CODE_STE empty
     * @param string $entityType 'AO'|'BR'|'CA'|'DA'|'EX'|'FA'
     * @return array{CLE:string,CODE_STE:string,MODE_NUM:string,NO_DEP:string,PROCH_NUM:string,REUT_TROU:string,NB_IMPRES:string}|null
     */
    public function findEntity(string $entityType, ?string $societe = null) :?array
    {
        /** @phpstan-ignore-next-line */
        return $this->find(
            [
                'CLE' => $entityType,
                'CODE_STE' => [$societe ?? '', ''],
            ],
            [],
            ['tri_CODE_STE' => 'DESC']
        );
    }

    /**
     * @param string $entityType 'AO'|'BR'|'CA'|'DA'|'EX'|'FA'
     */
    public function getNodeNum(string $entityType, ?string $societe = null) :?string
    {
        return $this->findEntity($entityType, $societe)['MODE_NUM'] ?? null;
    }
}
