<?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.TenantMapper">

  <resultMap id="tenantMap" type="com.zioinfo.signage.domain.TenantVo">
    <id property="id"          column="id"/>
    <result property="tenantCode"  column="tenant_code"/>
    <result property="tenantName"  column="tenant_name"/>
    <result property="description" column="description"/>
    <result property="active"      column="is_active"/>
    <result property="createdAt"   column="created_at"/>
  </resultMap>

  <select id="findAll" resultMap="tenantMap">
    SELECT id, tenant_code, tenant_name, description, is_active, created_at
    FROM signage_tenant ORDER BY tenant_code
  </select>

  <select id="findById" resultMap="tenantMap">
    SELECT id, tenant_code, tenant_name, description, is_active, created_at
    FROM signage_tenant WHERE id = #{id}
  </select>

  <select id="findByCode" resultMap="tenantMap">
    SELECT id, tenant_code, tenant_name, description, is_active, created_at
    FROM signage_tenant WHERE tenant_code = #{tenantCode}
  </select>

  <insert id="insert" useGeneratedKeys="true" keyProperty="id">
    INSERT INTO signage_tenant (tenant_code, tenant_name, description, is_active)
    VALUES (#{tenantCode}, #{tenantName}, #{description}, #{active})
  </insert>

  <update id="update">
    UPDATE signage_tenant SET
      tenant_name  = #{tenantName},
      description  = #{description},
      is_active    = #{active}
    WHERE id = #{id}
  </update>

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

</mapper>
