<?php

namespace Entity\Model;

use Helpers\QueryBuilder\QueryBuilder;

class ReqSeries extends QueryBuilder
{
    protected string $table = 'REQ_SERIES with (nolock)';
    protected array $primKey = ['REQ_ETAT', 'SERIE_ID'];

    
    /**
     * @param array<mixed> $entity
     * @return void
     */
    protected function setAutoincrementExpr(array &$entity) :void
    {
        if (empty($entity['SERIE_ID'])) {
            $entity['SERIE_ID'] = [
                'expr' =>
                    "SELECT COALESCE( MAX(SERIE_ID) + 1, 1)
                    FROM REQ_SERIES
                    WHERE REQ_ETAT = :etat_0",
                'param' => [
                    ':etat_0' => $entity['REQ_ETAT'],
                ],
            ];
        }
        
        if (empty($entity['NUM_AXE'])) {
            $entity['NUM_AXE'] = [
                'expr' =>
                    "SELECT COALESCE( MAX(NUM_AXE) + 1, 0)
                    FROM REQ_SERIES
                    WHERE REQ_ETAT = :etat_1",
                'param' => [
                    ':etat_1' => $entity['REQ_ETAT'],
                ],
            ];
        }
    }
}
