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

    <!-- 웹타입 목록 조회 -->
    <select id="getWebTypeList" parameterType="map" resultType="map">
        SELECT
            *
        FROM WEB_TYPE_STANDARDS
        WHERE 1=1
        <if test="active != null and active != ''">
            AND IS_ACTIVE = #{active}
        </if>
        <if test="category != null and category != ''">
            AND CATEGORY = #{category}
        </if>
        <if test="search != null and search != ''">
            AND (
                TYPE_NAME      ILIKE '%' || #{search} || '%'
             OR TYPE_NAME_ENG  ILIKE '%' || #{search} || '%'
             OR DESCRIPTION    ILIKE '%' || #{search} || '%'
            )
        </if>
        ORDER BY SORT_ORDER ASC, WEB_TYPE ASC
    </select>

    <!-- 웹타입 카테고리별 카운트 -->
    <select id="getWebTypeCategoryList" resultType="map">
        SELECT
            CATEGORY
            , COUNT(*) AS COUNT
        FROM WEB_TYPE_STANDARDS
        WHERE IS_ACTIVE = 'Y'
        GROUP BY CATEGORY
    </select>

    <!-- 버튼 액션 목록 조회 -->
    <select id="getButtonActionList" parameterType="map" resultType="map">
        SELECT
            *
        FROM BUTTON_ACTION_STANDARDS
        WHERE 1=1
        <if test="active != null and active != ''">
            AND IS_ACTIVE = #{active}
        </if>
        <if test="category != null and category != ''">
            AND CATEGORY = #{category}
        </if>
        <if test="search != null and search != ''">
            AND (
                ACTION_NAME      ILIKE '%' || #{search} || '%'
             OR ACTION_NAME_ENG  ILIKE '%' || #{search} || '%'
             OR DESCRIPTION      ILIKE '%' || #{search} || '%'
            )
        </if>
        ORDER BY SORT_ORDER ASC, ACTION_TYPE ASC
    </select>

    <!-- 버튼 액션 카테고리별 카운트 -->
    <select id="getButtonActionCategoryList" resultType="map">
        SELECT
            CATEGORY
            , COUNT(*) AS COUNT
        FROM BUTTON_ACTION_STANDARDS
        WHERE IS_ACTIVE = 'Y'
        GROUP BY CATEGORY
    </select>

</mapper>
