<?php

namespace Entity\Model;

use Helpers\QueryBuilder\QueryBuilder;

class FlisFiltListe extends QueryBuilder
{
    protected string $table = 'FLIS_FILT_LISTE with (nolock)';
    protected array $primKey = ['FLIS_CODE_FILTRE', 'FLIS_ID'];
    protected string $libelle = 'FLIS_LIBELLE';

    protected function setAutoincrementExpr(array &$entity): void
    {
        if (! empty($entity['FLIS_ID'])) {
            return;
        }
        $entity['FLIS_ID'] = [
            'expr' =>
                "SELECT COALESCE( MAX(FLIS_ID) + 1, 1)
                FROM FLIS_FILT_LISTE
                WHERE FLIS_CODE_FILTRE = :parent",
            'param' => [
                ':parent' => $entity['FLIS_CODE_FILTRE'],
            ],
        ];
    }
}
