<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.caliverse.admin.domain.dao.admin.WhiteListMapper">
    <resultMap id="WhiteListResultMap" type="com.caliverse.admin.domain.entity.WhiteList">
        <id property="id" column="id"/>
        <result property="rowNum" column="row_num"/>
        <result property="guid" column="guid"/>
        <result property="nickname" column="nickname"/>
        <result property="status" column="status"/>
        <result property="createBy" column="create_by"/>
    </resultMap>
    <!--사용 이력 리스트 조회-->
    <select id="getWhiteList" parameterType="map" resultMap="WhiteListResultMap">
        SELECT
                (@row_number:=@row_number + 1) AS row_num
                , a.id
                , a.guid
                , a.nickname
                , a.status
                , (SELECT email FROM admin WHERE id = a.create_by ) AS create_by
            FROM white_list a
               , (SELECT @row_number:=0) AS t
        WHERE 1 = 1
          AND a.deleted = 0
        ORDER BY a.create_dt desc
    </select>
    <select id="getCountByGuid" parameterType="java.lang.String" resultType="java.lang.Integer">
        SELECT
            Count(*)
        FROM white_list
        WHERE guid = #{guid}
          AND status = 'PERMITTED'
          AND deleted = 0
    </select>
    <select id="getGuidById" parameterType="java.lang.Long" resultType="map">
        SELECT
            guid, nickname
        FROM white_list
        WHERE id = #{id}
    </select>

    <insert id="postWhiteList" parameterType="com.caliverse.admin.domain.request.WhiteListRequest">
        INSERT INTO white_list (guid,nickname, status, create_by)
                  VALUES (#{guid},#{nickname}, #{status},#{createBy})
    </insert>

    <update id="updateStatus" parameterType="java.lang.Long">
        UPDATE white_list SET status = 'PERMITTED' , update_dt = NOW()
            WHERE id = #{id}
    </update>

    <update id="deleteWhiteList" parameterType="java.lang.Long">
        UPDATE white_list SET deleted = 1
            WHERE id = #{id}
    </update>



</mapper>
