<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zioinfo.cms.auth.mapper.UserMapper">

  <resultMap id="userMap" type="com.zioinfo.cms.auth.CmsUser">
    <id property="id" column="id"/>
    <result property="username" column="username"/>
    <result property="passwordHash" column="password_hash"/>
    <result property="displayName" column="display_name"/>
    <result property="role" column="role"/>
    <result property="active" column="is_active"/>
    <result property="createdAt" column="created_at"/>
  </resultMap>

  <select id="findByUsername" resultMap="userMap">
    SELECT id, username, password_hash, display_name, role, is_active, created_at
    FROM cms_user
    WHERE username = #{username}
  </select>

  <insert id="insert" parameterType="com.zioinfo.cms.auth.CmsUser"
          useGeneratedKeys="true" keyProperty="id">
    INSERT INTO cms_user (username, password_hash, display_name, role, is_active)
    VALUES (#{username}, #{passwordHash}, #{displayName}, #{role}, #{active})
  </insert>

</mapper>
