<?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.channel.mapper.ChannelMapper">

  <resultMap id="channelMap" type="com.zioinfo.cms.channel.CmsChannel">
    <id property="id" column="id"/>
    <result property="name" column="name"/>
    <result property="channelType" column="channel_type"/>
    <result property="endpoint" column="endpoint"/>
    <result property="active" column="is_active"/>
    <result property="createdAt" column="created_at"/>
  </resultMap>

  <select id="findAll" resultMap="channelMap">SELECT * FROM cms_channel ORDER BY id ASC</select>
  <select id="findById" resultMap="channelMap">SELECT * FROM cms_channel WHERE id = #{id}</select>

  <insert id="insert" parameterType="com.zioinfo.cms.channel.CmsChannel" useGeneratedKeys="true" keyProperty="id">
    INSERT INTO cms_channel (name, channel_type, endpoint, is_active)
    VALUES (#{name}, #{channelType}, #{endpoint}, #{active})
  </insert>

  <update id="update" parameterType="com.zioinfo.cms.channel.CmsChannel">
    UPDATE cms_channel SET name = #{name}, channel_type = #{channelType}, endpoint = #{endpoint}, is_active = #{active}
    WHERE id = #{id}
  </update>

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

</mapper>
