<?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.bsmlab.dfx.dfxconsole.app.user.DfxUserMapper">

    <select id="selectConsoleUserByUserUuid" parameterType="com.bsmlab.dfx.dfxconsole.app.user.DfxUserDto" resultType="com.bsmlab.dfx.dfxconsole.app.user.DfxUserDto">
        SELECT USER_UUID, USER_EMAIL, USER_PASSWORD, USER_NICK, USER_REGISTER_TIME, LAST_LOGIN_TIME
        FROM TB_DFX_USER
        WHERE USER_UUID = #{userUuid}
    </select>

    <select id="selectConsoleUserByUserEmail" parameterType="com.bsmlab.dfx.dfxconsole.app.user.DfxUserDto" resultType="com.bsmlab.dfx.dfxconsole.app.user.DfxUserDto">
        SELECT USER_UUID, USER_EMAIL, USER_PASSWORD, USER_NICK, USER_REGISTER_TIME, LAST_LOGIN_TIME
        FROM TB_DFX_USER
        WHERE USER_EMAIL = #{userEmail}
    </select>

    <select id="selectConsoleUserSearchListForPage" parameterType="com.bsmlab.dfx.dfxconsole.app.user.UserSearchParameterDto" resultType="com.bsmlab.dfx.dfxconsole.app.user.DfxUserDto">
        SELECT USER_UUID, USER_EMAIL, USER_PASSWORD, USER_NICK, USER_REGISTER_TIME, LAST_LOGIN_TIME, COUNT(USER_UUID) OVER () AS TOTAL_ITEM_COUNT
        FROM TB_DFX_USER
        WHERE 1 = 1
            AND USER_EMAIL LIKE '%'||#{userEmail}||'%'
            AND USER_NICK LIKE '%'||#{userNick}||'%'
        ORDER BY USER_NICK
        LIMIT #{itemCountPerPage} * (#{page}) OFFSET #{itemCountPerPage} * (#{page} - 1)
    </select>

    <insert id="insertConsoleUser" parameterType="com.bsmlab.dfx.dfxconsole.app.user.DfxUserDto">
        INSERT INTO TB_DFX_USER (
            USER_UUID, USER_EMAIL, USER_NICK, USER_REGISTER_TIME, LAST_LOGIN_TIME
        )
        VALUES (
            #{userUuid}, #{userEmail}, #{userNick}, #{userRegisterTime}, #{lastLoginTime}
        )
    </insert>
</mapper>
