package com.caliverse.admin.domain.dao.admin;

import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;


public interface ReqIdMapper {
    @Select("SELECT COALESCE(MAX(req_id), 0) + 1 FROM req_id_manager WHERE req_type = #{reqType}")
    Integer getNextReqId(@Param("reqType") String reqType);

    @Insert("INSERT INTO req_id_manager (req_type, req_id, description, create_by) VALUES (#{reqType}, #{reqId}, #{desc}, #{createBy})")
    void insertReqIdHistory(@Param("reqType") String reqType, @Param("reqId") Integer reqId, @Param("desc") String desc, @Param("createBy") String createBy);

    @Select("SELECT * FROM req_id_manager WHERE req_type = #{reqType} " +
            "ORDER BY created_at DESC LIMIT #{limit}")
    List<Map<String, Object>> getReqIdHistory(@Param("reqType") String reqType,
                                              @Param("limit") int limit);
}
