<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ga.core.mapper.commission.StatuteConfigMapper">

    <resultMap id="VOMap"   type="com.ga.core.vo.commission.StatuteConfigVO"/>
    <resultMap id="RespMap" type="com.ga.core.vo.commission.StatuteConfigResp"/>

    <select id="selectById" resultMap="RespMap">
        SELECT config_id, entity_type, expiration_months, is_active
          FROM statute_config
         WHERE config_id = #{configId}
    </select>

    <!-- entity_type UNIQUE — 단건 반환 -->
    <select id="selectByEntityType" resultMap="RespMap">
        SELECT config_id, entity_type, expiration_months, is_active
          FROM statute_config
         WHERE entity_type = #{entityType}
    </select>

    <select id="selectList" resultMap="RespMap">
        SELECT config_id, entity_type, expiration_months, is_active
          FROM statute_config
         ORDER BY config_id ASC
    </select>

    <insert id="insert" useGeneratedKeys="true" keyProperty="configId">
        INSERT INTO statute_config
            (entity_type, expiration_months, is_active, created_by, created_at)
        VALUES
            (#{entityType}, #{expirationMonths}, COALESCE(#{isActive}, 'Y'),
             #{createdBy}, NOW())
    </insert>

    <update id="update">
        UPDATE statute_config
           SET expiration_months = #{expirationMonths},
               is_active         = #{isActive},
               updated_at        = NOW()
         WHERE config_id = #{configId}
    </update>

</mapper>
