<?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.ga.core.mapper.product.InsuranceCompanyMapper">

    <resultMap id="CompanyMap" type="com.ga.core.vo.product.InsuranceCompanyVO"/>

    <sql id="cols">
        company_id, company_code, company_name, company_type, biz_no,
        contact_name, contact_phone, contact_email, is_active
    </sql>

    <select id="selectAll" resultMap="CompanyMap">
        SELECT <include refid="cols"/> FROM insurance_company ORDER BY company_id
    </select>

    <select id="selectActive" resultMap="CompanyMap">
        SELECT <include refid="cols"/> FROM insurance_company WHERE is_active='Y' ORDER BY company_id
    </select>

    <select id="selectById" resultMap="CompanyMap">
        SELECT <include refid="cols"/> FROM insurance_company WHERE company_id = #{companyId}
    </select>

    <select id="selectByCode" resultMap="CompanyMap">
        SELECT <include refid="cols"/> FROM insurance_company WHERE company_code = #{companyCode}
    </select>

    <insert id="insert" parameterType="com.ga.core.vo.product.InsuranceCompanyVO"
            useGeneratedKeys="true" keyProperty="companyId">
        INSERT INTO insurance_company (company_code, company_name, company_type, biz_no,
                                       contact_name, contact_phone, contact_email, is_active)
        VALUES (#{companyCode}, #{companyName}, #{companyType}, #{bizNo},
                #{contactName}, #{contactPhone}, #{contactEmail}, COALESCE(#{isActive},'Y'))
    </insert>

    <update id="update" parameterType="com.ga.core.vo.product.InsuranceCompanyVO">
        UPDATE insurance_company SET
            company_name = #{companyName},
            company_type = #{companyType},
            biz_no = #{bizNo},
            contact_name = #{contactName},
            contact_phone = #{contactPhone},
            contact_email = #{contactEmail},
            is_active = #{isActive}
        WHERE company_id = #{companyId}
    </update>

    <delete id="deleteById">DELETE FROM insurance_company WHERE company_id = #{companyId}</delete>

</mapper>
