-- 109_param_driver_room_dept.sql — param DRIVER_ROOM_DEPT (Kontrak Sprint 10 §WP-10C butir 2)
--
-- Sebelumnya dept "pemilik" gerbang workflow driver kamar & rate (RATE_ADR_TARGET) hardcode
-- string 'FO' langsung di Service\DriverService (WORKFLOW_DEPT / WORKFLOW_DEPT_RATE). Dipindah
-- ke param_global supaya bisa diubah via GET/PUT /api/admin/params (WP-2A) tanpa deploy ulang,
-- selaras pola param lain (TOTAL_ROOM_INV dkk, 107_param.sql).
--
-- param_global.param_value = DECIMAL(18,6) — TIDAK bisa menyimpan kode teks 'FO' langsung.
-- Nilai yang disimpan = department.id milik dept berkode 'FO' (seed 103_department.sql: id=1).
-- DriverRepository::findRoomDeptCode() JOIN balik ke department utk resolusi id -> code.
--
-- IDEMPOTENSI (pola sama dgn 108_param_tax.sql / 160_insight_rules.sql, ADR-001/ADR-010):
-- version_id = NULL (param global lintas versi) dan MariaDB TIDAK menganggap NULL sbg duplikat
-- pada UNIQUE KEY uq_param_global (version_id, param_code) — ON DUPLICATE KEY UPDATE TIDAK aman
-- di sini (akan menambah baris baru tiap re-run seed.php). Pola pengganti: INSERT ... SELECT ...
-- WHERE NOT EXISTS, guard eksplisit (version_id IS NULL AND param_code = ...) — re-run TIDAK
-- PERNAH menambah baris baru dan TIDAK PERNAH menimpa nilai yang sudah diedit admin.

INSERT INTO param_global (version_id, param_code, param_value)
SELECT NULL, 'DRIVER_ROOM_DEPT', (SELECT id FROM department WHERE code = 'FO')
 WHERE NOT EXISTS (
       SELECT 1 FROM param_global WHERE version_id IS NULL AND param_code = 'DRIVER_ROOM_DEPT');
