-- ============================================================================
-- V70 — 물류 허브 도크 + 반입/반출 예약 슬롯 (e-2026-live, 향후 2주)
-- 담당: kintex-testdata-dev · 작성: 2026-07-23
-- ----------------------------------------------------------------------------
-- 근본 원인(소유자 시연 지시 항목 4 — 빈 화면):
--   LogisticsMapper.findDocks 는 dock ← hall_assignment(ha.event_id=eventId) 로 홀 도크를 찾는다.
--   기존 도크(dock-h7-*)는 홀 H7 전용인데, e-2026-live 는 홀 H1(ha-live-h1)에 배정 →
--   e-2026-live 물류 허브 그리드에 도크가 0개 = 예약 슬롯 화면이 완전히 빈다.
-- 조치: 홀 H1 도크 6개 신설 + e-2026-live 반입/반출 예약을 향후 2주에 분산(가능/마감 혼재).
-- ----------------------------------------------------------------------------
-- 근거(실 조회 경로):
--   • LogisticsMapper.findDocks(eventId): dock JOIN hall_assignment ha ON ha.hall_id=dock.hall_id
--       WHERE ha.event_id=#{eventId}. → H1 도크가 있어야 e-2026-live 그리드 렌더.
--   • findReservations(eventId,direction,date): dock_reservation 방향·일자 필터(그리드 점유).
--   • findDefaultDate(eventId,direction): min(reserve_date) → 조회 기본 일자(가장 이른 예약일).
-- 원칙: 순수 INSERT ON CONFLICT DO NOTHING. 도크는 UNIQUE(hall_id,dock_no) 멱등.
--   예약 일자는 CURRENT_DATE 상대(재배포 시점 기준 항상 향후 2주). start_hour 8..19, span 2~3.
--   company_name 은 더미(공간/물류 업체명). tone: booked | priority(중량물 5t↑ 우선).
-- ============================================================================


-- 1) 홀 H1 도크 6개 ------------------------------------------------------------
INSERT INTO dock (id, hall_id, dock_no, label, heavy_priority) VALUES
  ('dock-h1-1','H1',1,'도크 1', true),
  ('dock-h1-2','H1',2,'도크 2', false),
  ('dock-h1-3','H1',3,'도크 3', false),
  ('dock-h1-4','H1',4,'도크 4', false),
  ('dock-h1-5','H1',5,'도크 5', false),
  ('dock-h1-6','H1',6,'도크 6', true)
ON CONFLICT (hall_id, dock_no) DO NOTHING;


-- 2) 반입(in) 예약 — 향후 2주 분산. 대표일 CURRENT_DATE+1 은 도크·시간대 다수 점유(가능/마감 혼재).
INSERT INTO dock_reservation
  (id, event_id, dock_id, direction, reserve_date, start_hour, span, company_name, vehicle_no, vehicle_weight, item, forklift, tone) VALUES
  -- 대표일(D+1) — 도크 1~5 부분 점유, 도크 6 및 후반 시간대는 비어 있음(가능 슬롯)
  ('dr-live-in-01','e-2026-live','dock-h1-1','in', CURRENT_DATE + 1,  8, 2, '(주)오토닉스로보',   '11가 1101', '5t',   '아일랜드 부스 자재', true,  'booked'),
  ('dr-live-in-02','e-2026-live','dock-h1-1','in', CURRENT_DATE + 1, 11, 2, NULL,                 NULL,        '5t',   '중량물 우선(5t↑)',   false, 'priority'),
  ('dr-live-in-03','e-2026-live','dock-h1-2','in', CURRENT_DATE + 1,  9, 3, '한성정밀기계',       '22나 2202', '2.5t', '기계 장비',          true,  'booked'),
  ('dr-live-in-04','e-2026-live','dock-h1-3','in', CURRENT_DATE + 1, 10, 2, '대성전자',           '33다 3303', '1t',   '전시 소품',          false, 'booked'),
  ('dr-live-in-05','e-2026-live','dock-h1-4','in', CURRENT_DATE + 1, 13, 2, '스마트팩토리솔루션', '44라 4404', '3.5t', '조립식 부스',        false, 'booked'),
  ('dr-live-in-06','e-2026-live','dock-h1-5','in', CURRENT_DATE + 1, 14, 3, '퓨처모빌리티',       '55마 5505', '5t',   '차량 전시물',        true,  'booked'),
  -- D+3
  ('dr-live-in-07','e-2026-live','dock-h1-1','in', CURRENT_DATE + 3,  9, 2, '비전AI시스템',       '66바 6606', '1t',   '디스플레이 장비',    false, 'booked'),
  ('dr-live-in-08','e-2026-live','dock-h1-2','in', CURRENT_DATE + 3, 12, 2, '한국물류로보틱스',   '77사 7707', '5t',   'AMR 로봇',           true,  'booked'),
  ('dr-live-in-09','e-2026-live','dock-h1-6','in', CURRENT_DATE + 3, 15, 2, NULL,                 NULL,        '11t 이상', '중량물 우선(11t↑)', true, 'priority'),
  -- D+5
  ('dr-live-in-10','e-2026-live','dock-h1-3','in', CURRENT_DATE + 5, 10, 3, '나노소재랩',         '88아 8808', '2.5t', '소재 샘플·집기',     false, 'booked'),
  ('dr-live-in-11','e-2026-live','dock-h1-4','in', CURRENT_DATE + 5, 14, 2, '그린에너지테크',     '99자 9909', '3.5t', '태양광 모듈',        true,  'booked'),
  -- D+7
  ('dr-live-in-12','e-2026-live','dock-h1-1','in', CURRENT_DATE + 7,  8, 2, '3D프린팅솔루션',     '10차 1010', '1t',   '3D 프린터',          false, 'booked'),
  ('dr-live-in-13','e-2026-live','dock-h1-5','in', CURRENT_DATE + 7, 11, 2, '차세대배터리',       '12카 1212', '5t',   'ESS 배터리팩',       true,  'booked')
ON CONFLICT (id) DO NOTHING;


-- 3) 반출(out) 예약 — 행사 종료 후 철거(향후 2주 후반). 가능/마감 혼재.
INSERT INTO dock_reservation
  (id, event_id, dock_id, direction, reserve_date, start_hour, span, company_name, vehicle_no, vehicle_weight, item, forklift, tone) VALUES
  -- 대표일(D+10)
  ('dr-live-out-01','e-2026-live','dock-h1-1','out', CURRENT_DATE + 10, 14, 3, '(주)오토닉스로보', '11가 1101', '5t',   '철거 자재',          true,  'booked'),
  ('dr-live-out-02','e-2026-live','dock-h1-2','out', CURRENT_DATE + 10, 15, 2, '한국물류로보틱스', '77사 7707', '5t',   'AMR 회수',           true,  'booked'),
  ('dr-live-out-03','e-2026-live','dock-h1-3','out', CURRENT_DATE + 10, 16, 2, NULL,               NULL,        '11t 이상', '중량물 우선(11t↑)', true, 'priority'),
  ('dr-live-out-04','e-2026-live','dock-h1-4','out', CURRENT_DATE + 10, 13, 2, '퓨처모빌리티',     '55마 5505', '5t',   '차량 전시물 반출',   true,  'booked'),
  -- D+11
  ('dr-live-out-05','e-2026-live','dock-h1-1','out', CURRENT_DATE + 11, 10, 2, '한성정밀기계',     '22나 2202', '2.5t', '기계 장비 회수',     true,  'booked'),
  ('dr-live-out-06','e-2026-live','dock-h1-5','out', CURRENT_DATE + 11, 17, 3, '차세대배터리',     '12카 1212', '5t',   'ESS 반출',           true,  'booked'),
  -- D+12
  ('dr-live-out-07','e-2026-live','dock-h1-2','out', CURRENT_DATE + 12, 11, 2, '3D프린팅솔루션',   '10차 1010', '1t',   '3D 프린터 회수',     false, 'booked')
ON CONFLICT (id) DO NOTHING;


-- ============================================================================
-- 검증(수동):
--   -- H1 도크: SELECT count(*) FROM dock d JOIN hall_assignment ha ON ha.hall_id=d.hall_id
--   --   WHERE ha.event_id='e-2026-live'; -- 6
--   -- 반입 기본일 예약: SELECT dock_id,start_hour,span FROM dock_reservation
--   --   WHERE event_id='e-2026-live' AND direction='in' AND reserve_date=CURRENT_DATE+1;
--   -- 기본 조회일: SELECT to_char(min(reserve_date),'YYYY-MM-DD') FROM dock_reservation
--   --   WHERE event_id='e-2026-live' AND direction='in'; -- CURRENT_DATE+1
-- ============================================================================
