<?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="approvalEvent">

    <resultMap id="approvalEventResult" type="com.samsung.approval.entity.ApprovalEvent">
        <id property="eventId" column="EVENT_ID"/>
        <result property="approvalRequestId" column="APPROVAL_REQUEST_ID"/>
        <result property="eventMessage" column="EVENT_MESSAGE"/>
        <result property="eventCode" column="EVENT_CODE" />
        <result property="firstRegDatetime" column="FIRST_REG_DATETIME" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="tableApprovalEvent">TN_CF_APPROVAL_EVENT</sql>

    <sql id="columnsApprovalEvent">
		EVENT_ID, APPROVAL_REQUEST_ID, EVENT_MESSAGE,
		FIRST_REG_DATETIME, EVENT_CODE
	</sql>

    <select id="selectApprovalEventList" parameterType="java.util.HashMap" resultMap="approvalEventResult">
        SELECT <include refid="columnsApprovalEvent" />
        FROM   <include refid="tableApprovalEvent" />
        WHERE  APPROVAL_REQUEST_ID = #{approvalRequestId}
        <if test="@com.samsung.SdlComparator@isNotEmpty(eventId)">
        AND    EVENT_ID = #{eventId}
        </if>
        ORDER BY FIRST_REG_DATETIME DESC
    </select>

    <insert id="insertApprovalEvent" parameterType="java.util.HashMap">
        INSERT INTO <include refid="tableApprovalEvent" />
        (<include refid="columnsApprovalEvent" />)
        VALUES
        (#{eventId}, #{approvalRequestId}, #{eventMessage},
         #{firstRegDatetime}, #{eventCode})
    </insert>

</mapper>