<?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="openApiProxy">

  <sql id="openApiProxySearchCondition">
    <if test="keyword != null and keyword != ''">
      AND (NAME ILIKE '%' || #{keyword} || '%')
    </if>
    <if test="status != null and status != ''">
      AND STATUS = #{status}
    </if>
  </sql>

  <select id="getOpenApiProxyList" parameterType="map" resultType="map">
    SELECT * FROM OPEN_API_PROXY
    WHERE 1=1
    <include refid="common.companyCodeFilter"/>
    <include refid="openApiProxySearchCondition"/>
    <include refid="common.dynamicOrderBy"/>
    <include refid="common.pagination"/>
  </select>

  <select id="getOpenApiProxyListCnt" parameterType="map" resultType="int">
    SELECT COUNT(*) FROM OPEN_API_PROXY
    WHERE 1=1
    <include refid="common.companyCodeFilter"/>
    <include refid="openApiProxySearchCondition"/>
  </select>

  <select id="getOpenApiProxyInfo" parameterType="map" resultType="map">
    SELECT * FROM OPEN_API_PROXY
    WHERE ID = #{id}
    <include refid="common.companyCodeFilter"/>
  </select>

  <insert id="insertOpenApiProxy" parameterType="map" useGeneratedKeys="true" keyProperty="id">
    INSERT INTO OPEN_API_PROXY (COMPANY_CODE, CREATED_DATE, UPDATED_DATE)
    VALUES (#{company_code}, NOW(), NOW())
  </insert>

  <update id="updateOpenApiProxy" parameterType="map">
    UPDATE OPEN_API_PROXY
    SET UPDATED_DATE = NOW()
    WHERE ID = #{id}
    <include refid="common.companyCodeFilter"/>
  </update>

  <delete id="deleteOpenApiProxy" parameterType="map">
    DELETE FROM OPEN_API_PROXY
    WHERE ID = #{id}
    <include refid="common.companyCodeFilter"/>
  </delete>

</mapper>
