-- 180_roomrev_owner.sql — Konfigurasi kepemilikan section Room Revenue (ADR-014, WP-11B).
-- Permintaan user: "pada bagian room revenue, berikan akses ke akun S&M yang membuatnya."
-- Sesuai praktik & master Excel (rantai Rate Structure -> DETAIL ROOM REV -> Room (FO)):
-- proyeksi kamar disusun Sales & Marketing, Front Office memakainya.
--
-- Kepemilikan section sebagai DATA (pola SAMA seed 170_outlets.sql, form_code
-- 'COVER_OUTLETS'): App\Repository\RoomRevRepository::findOwnerConfig() membaca baris ini
-- SETIAP request (tanpa cache) — menambah/mengurangi pemilik = ubah config_json.write_depts
-- lalu re-run `php scripts/seed.php` (TANPA deploy/ubah kode) langsung berefek pada:
--   - GET/PUT /api/input-roomrev + breakdown (rows = akun section config_json.section milik
--     config_json.host_dept),
--   - gerbang RBAC tulis /api/driver/room & /api/driver/rate,
--   - kunci (read_only + locked_reason='ROOMREV') section config_json.section pada grid dept
--     host_dept bila dept aktor TIDAK ada di write_depts,
--   - item menu "Room Revenue"/"Statistik Kamar"/"Rate ADR Target".
--
-- Akses DITAMBAHKAN, bukan dipindahkan (ADR-014 butir b): FO tetap ada di write_depts di
-- bawah supaya fo_user TIDAK kehilangan akses yang sudah ada — S&M mendapat akses BARU.
--
-- department_id = id dept SM (lihat 103_department.sql: SM id=9) — form ini "milik" S&M
-- secara administratif (siapa yang mengelola konfigurasinya), TIDAK BERARTI baris budget-nya
-- pindah ke dept SM: config_json.host_dept ('FO') tetap menentukan dept mana yang datanya
-- (department_account/budget_line) sungguh dipakai — literal id sesuai konvensi seed lain
-- (103_department.sql/120_users.sql/170_outlets.sql), bukan hasil DESCRIBE/introspeksi (ADR-005).
--
-- ON DUPLICATE KEY UPDATE config_json=VALUES(...): file ini BUKAN data transaksional user
-- (ADR-010 hanya membatasi budget_line/compare) — ini konfigurasi master, wajar ditimpa ulang
-- oleh re-seed (mekanisme "ubah seed -> kepemilikan baru berlaku tanpa deploy").

INSERT INTO form_definition (department_id, form_code, form_type, title, config_json) VALUES
(
    9,
    'ROOMREV_OWNER',
    'grid',
    'Room Revenue',
    JSON_OBJECT(
        'host_dept', 'FO',
        'section', 'REVENUE',
        'write_depts', JSON_ARRAY('SM', 'FO')
    )
)
ON DUPLICATE KEY UPDATE
    department_id = VALUES(department_id),
    title = VALUES(title),
    config_json = VALUES(config_json);
