-- 봉투 단가 테스트 데이터 (/bag/bag-prices — 적용 시작·종료 다양)
-- 가격 기준: 대구시 공식 판매가 2024.7.1 (https://www.daegu.go.kr/env/index.do?menu_id=00001325)
-- 전제: bag_price 테이블 존재, code_master O종 봉투코드와 맞춤(화면에서 선택 가능한 코드)
-- 대상 지자체: 활성 지자체 중 최소 lg_idx + lg_code 110204(남구), UNION 중복 제거
-- 재실행: 동일 (지자체, 봉투코드, 적용시작일) 이 이미 있으면 삽입 안 함

SET NAMES utf8mb4;

INSERT INTO `bag_price` (`bp_lg_idx`, `bp_bag_code`, `bp_bag_name`, `bp_order_price`, `bp_wholesale`, `bp_consumer`, `bp_start_date`, `bp_end_date`, `bp_state`, `bp_regdate`)
WITH `target_lg` AS (
  (SELECT `lg_idx` FROM `local_government` WHERE `lg_state` = 1 ORDER BY `lg_idx` ASC LIMIT 1)
  UNION
  (SELECT `lg_idx` FROM `local_government` WHERE `lg_code` = '110204' LIMIT 1)
)
SELECT
  t.`lg_idx`,
  v.`c`,
  v.`n`,
  v.`o`,
  v.`w`,
  v.`co`,
  v.`s`,
  v.`e`,
  v.`st`,
  NOW()
FROM `target_lg` t
CROSS JOIN (
  SELECT '10112' AS c, '일반용 3L' AS n, 24.00 AS o, 112.00 AS w, 120.00 AS co, DATE '2023-01-01' AS s, DATE '2023-12-31' AS e, 0 AS st
  UNION ALL SELECT '10112', '일반용 3L', 24.00, 112.00, 120.00, '2024-07-01', '2024-12-31', 0
  UNION ALL SELECT '10122', '일반용 5L', 36.00, 167.00, 180.00, '2024-01-01', '2024-08-31', 0
  UNION ALL SELECT '10122', '일반용 5L', 36.00, 167.00, 180.00, '2025-09-01', NULL, 1
  UNION ALL SELECT '10132', '일반용 10L', 68.00, 316.00, 340.00, '2025-11-01', '2025-12-31', 1
  UNION ALL SELECT '10132', '일반용 10L', 68.00, 316.00, 340.00, '2026-01-15', NULL, 1
  UNION ALL SELECT '10152', '일반용 20L', 120.00, 560.00, 600.00, '2022-05-01', '2024-06-30', 0
  UNION ALL SELECT '10152', '일반용 20L', 134.00, 623.00, 670.00, '2026-04-01', NULL, 1
  UNION ALL SELECT '60102', '음식물 2L', 22.00, 102.00, 110.00, '2025-01-01', NULL, 1
  UNION ALL SELECT '60132', '음식물 10L', 116.00, 539.00, 580.00, '2025-06-01', '2025-12-31', 0
  UNION ALL SELECT '60132', '음식물 10L', 116.00, 539.00, 580.00, '2026-03-01', NULL, 1
  UNION ALL SELECT '20172', '공공용 50L', 332.00, 1544.00, 1660.00, '2020-01-01', '2020-12-31', 0
  UNION ALL SELECT '40152', '공동주택용 20L', 128.00, 596.00, 640.00, '2025-12-01', '2026-02-28', 1
  UNION ALL SELECT '10172', '일반용 50L', 332.00, 1544.00, 1660.00, '2026-06-01', NULL, 1
  UNION ALL SELECT '10192', '일반용 75L', 494.00, 2297.00, 2470.00, '2026-12-01', NULL, 1
) v
WHERE NOT EXISTS (
  SELECT 1 FROM `bag_price` b
  WHERE b.`bp_lg_idx` = t.`lg_idx` AND b.`bp_bag_code` = v.`c` AND b.`bp_start_date` = v.`s`
);

-- bp_state: 0=미사용(과거 단가 등), 1=사용
-- bp_end_date NULL = 현재 적용 중(또는 종료일 미정)
