-- 봉투 단가 테스트 데이터 (/bag/bag-prices — 적용 시작·종료 다양)
-- 전제: 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, 22.00 AS o, 58.00 AS w, 78.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, 59.00, 79.00, '2024-07-01', '2024-12-31', 0
  UNION ALL SELECT '10122', '일반용 5L', 33.00, 98.00, 128.00, '2024-01-01', '2024-08-31', 0
  UNION ALL SELECT '10122', '일반용 5L', 36.00, 102.00, 132.00, '2025-09-01', NULL, 1
  UNION ALL SELECT '10132', '일반용 10L', 55.00, 180.00, 240.00, '2025-11-01', '2025-12-31', 1
  UNION ALL SELECT '10132', '일반용 10L', 62.00, 192.00, 252.00, '2026-01-15', NULL, 1
  UNION ALL SELECT '10152', '일반용 20L', 88.00, 340.00, 450.00, '2022-05-01', '2022-12-31', 0
  UNION ALL SELECT '10152', '일반용 20L', 102.00, 375.00, 495.00, '2026-04-01', NULL, 1
  UNION ALL SELECT '60102', '음식물 2L', 17.00, 48.00, 58.00, '2025-01-01', NULL, 1
  UNION ALL SELECT '60132', '음식물 10L', 68.00, 205.00, 275.00, '2025-06-01', '2025-12-31', 0
  UNION ALL SELECT '60132', '음식물 10L', 72.00, 212.00, 282.00, '2026-03-01', NULL, 1
  UNION ALL SELECT '20172', '공공용 50L', 175.00, 680.00, 0.00, '2020-01-01', '2020-12-31', 0
  UNION ALL SELECT '40152', '공동주택용 20L', 85.00, 330.00, 440.00, '2025-12-01', '2026-02-28', 1
  UNION ALL SELECT '10172', '일반용 50L', 205.00, 850.00, 1120.00, '2026-06-01', NULL, 1
  UNION ALL SELECT '10192', '일반용 75L', 295.00, 1260.00, 1660.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 = 현재 적용 중(또는 종료일 미정)
