<?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>

</mapper>
