<?php

namespace Entity\Model;

use Helpers\QueryBuilder\QueryBuilder;

class Paramnum extends QueryBuilder
{
    protected \PDO $pdo;
    
    protected string $table = 'PARAMNUM with (nolock)';
    
    protected string $primaryKey = '';
    
    public function __construct(\PDO $pdo)
    {
        $this->pdo = $pdo;
    }

    /**
     * /!\ Note if CODE_STE not present, fallback on CODE_STE empty
     * @param 'AO'|'BR'|'CA'|'DA'|'EX'|'FA' $entityType
     * @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 'AO'|'BR'|'CA'|'DA'|'EX'|'FA' $entityType
     */
    public function getNodeNum(string $entityType, string $societe = null) :?string
    {
        return $this->findEntity($entityType, $societe)['MODE_NUM'] ?? null;
    }
}
