<?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">
<!--
  HallMapper — 홀 마스터·트렌치·비상구 조회(계약 확장, read-only). SRID 0 = 홀 로컬 평면(미터).
  ★backend-dev 추가(db-engineer 계약 §3 밖). 기존 테이블(hall·trench·hall_exit)만 조회, 마이그레이션 불변.
-->
<mapper namespace="com.zioinfo.kintex.module.m2.mapper.HallMapper">

    <!-- 홀 마스터 헤더. -->
    <select id="findHall" resultType="map">
        SELECT id                  AS "hallId",
               label,
               width_m             AS "widthM",
               depth_m             AS "depthM",
               height_m            AS "heightM",
               floor_load_t_per_m2 AS "floorLoadTPerM2",
               booth_capacity      AS "boothCapacity",
               has_gas             AS "hasGas",
               is_assumed_trench   AS "assumedTrench"
        FROM hall
        WHERE id = #{hallId}
          AND tenant_id = #{tenantId}
    </select>

    <!-- 홀 트렌치 좌표(가정 그리드 포함). -->
    <select id="findTrenches" resultType="map">
        SELECT id             AS "trenchId",
               ST_X(geom)     AS "x",
               ST_Y(geom)     AS "y",
               supply_power   AS "supplyPower",
               supply_water   AS "supplyWater",
               supply_air     AS "supplyAir",
               supply_network AS "supplyNetwork",
               supply_gas     AS "supplyGas",
               is_assumed     AS "assumed"
        FROM trench
        WHERE hall_id = #{hallId}
        ORDER BY id
    </select>

    <!-- 홀 비상구 좌표·이격. -->
    <select id="findExits" resultType="map">
        SELECT id          AS "exitId",
               ST_X(geom)  AS "x",
               ST_Y(geom)  AS "y",
               clearance_m AS "clearanceM"
        FROM hall_exit
        WHERE hall_id = #{hallId}
        ORDER BY id
    </select>

    <!-- 홀 마스터 전체 — 평면도 선택 트리(대분류 전시장 > 중분류 홀). OUTDOOR 제외. -->
    <select id="findAllHalls" resultType="map">
        SELECT id                AS "hallId",
               exhibition_center AS "center",
               label,
               width_m           AS "widthM",
               depth_m           AS "depthM"
        FROM hall
        WHERE id LIKE 'H%'
        ORDER BY exhibition_center, length(id), id
    </select>

    <!-- 홀 구역(소분류) 전체 — V60 hall_zone. -->
    <select id="findAllZones" resultType="map">
        SELECT id      AS "zoneId",
               hall_id AS "hallId",
               label,
               x0, y0, x1, y1
        FROM hall_zone
        ORDER BY hall_id, sort
    </select>

    <!-- 구역 단건(경계) — 구역 제한 자동배치. -->
    <select id="findZone" resultType="map">
        SELECT id      AS "zoneId",
               hall_id AS "hallId",
               label,
               x0, y0, x1, y1
        FROM hall_zone
        WHERE id = #{zoneId}
    </select>

    <!-- 홀 기둥(V62 실측) — 자동배치 회피·캔버스 표시. -->
    <select id="findPillars" resultType="map">
        SELECT id         AS "pillarId",
               ST_X(geom) AS "x",
               ST_Y(geom) AS "y",
               radius_m   AS "radiusM"
        FROM hall_pillar
        WHERE hall_id = #{hallId}
        ORDER BY id
    </select>

    <!-- 벽·계단·엘리베이터·문 장애물(V63 실측) — 자동배치 회피·캔버스 표시. -->
    <select id="findObstacles" resultType="map">
        SELECT id   AS "obstacleId",
               kind,
               x0, y0, x1, y1
        FROM hall_obstacle
        WHERE hall_id = #{hallId}
        ORDER BY id
    </select>

</mapper>
