<?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.zioinfo.signage.mapper.StoreGroupMapper">

  <resultMap id="groupMap" type="com.zioinfo.signage.domain.StoreGroupVo">
    <id property="id"          column="id"/>
    <result property="tenantCode"  column="tenant_code"/>
    <result property="groupCode"   column="group_code"/>
    <result property="groupName"   column="group_name"/>
    <result property="description" column="description"/>
    <result property="active"      column="is_active"/>
    <result property="createdAt"   column="created_at"/>
  </resultMap>

  <select id="findAll" resultMap="groupMap">
    SELECT id, tenant_code, group_code, group_name, description, is_active, created_at
    FROM signage_store_group
    <where>
      <if test="tenantCode != null and tenantCode != ''">AND tenant_code = #{tenantCode}</if>
    </where>
    ORDER BY group_code
  </select>

  <select id="findById" resultMap="groupMap">
    SELECT id, tenant_code, group_code, group_name, description, is_active, created_at
    FROM signage_store_group WHERE id = #{id}
  </select>

  <insert id="insert" useGeneratedKeys="true" keyProperty="id">
    INSERT INTO signage_store_group (tenant_code, group_code, group_name, description, is_active)
    VALUES (#{tenantCode}, #{groupCode}, #{groupName}, #{description}, #{active})
  </insert>

  <update id="update">
    UPDATE signage_store_group SET
      group_name  = #{groupName},
      description = #{description},
      is_active   = #{active}
    WHERE id = #{id}
  </update>

  <delete id="delete">DELETE FROM signage_store_group WHERE id = #{id}</delete>

</mapper>
