<?php

namespace Entity\Model;

use Helpers\QueryBuilder\QueryBuilder;

class ReqEnt extends QueryBuilder
{
    protected string $table = 'REQ_ENT with (nolock)';
    protected array $primKey = ['REQ_ETAT', 'REQ_ID'];
    protected string $libelle = 'REQ_NOM';

    /**
     * @param array<mixed> $entity
     * @return void
     */
    protected function setAutoincrementExpr(array &$entity) :void
    {
        if (empty($entity['REQ_ID'])) {
            // $entity['REQ_ID'] = [
            //     'expr' =>
            //         "SELECT COALESCE( MAX(REQ_ID) + 1, 1)
            //         FROM REQ_ENT
            //         WHERE REQ_ETAT = :etat",
            //     'param' => [':etat' => $entity['REQ_ETAT']],
            // ];
            // Note : REQ_ID is deprecated and should always be at 1
            // (Same goes for other tables joining on it althought some code still use it)
            $entity['REQ_ID'] = 1;
        }
    }
}
