<?php

namespace Entity\Model;

use Helpers\QueryBuilder\QueryBuilder;

class ReqFrom extends QueryBuilder
{
    protected string $table = 'REQ_FROM with (nolock)';
    protected array $primKey = ['REQ_ETAT', 'REQ_ID', 'TABLE_ID'];

    /**
     * @param array<mixed> $entity
     * @return void
     */
    protected function setAutoincrementExpr(array &$entity) :void
    {
        if (empty($entity['TABLE_ID'])) {
            $entity['TABLE_ID'] = [
                'expr' =>
                    "SELECT COALESCE( MAX(TABLE_ID) + 1, 1)
                    FROM REQ_FROM
                    WHERE REQ_ETAT = :etat AND REQ_ID = :req",
                'param' => [
                    ':etat' => $entity['REQ_ETAT'],
                    ':req' => $entity['REQ_ID'],
                ],
            ];
        }
    }
}
