-- =====================================================================
-- 0014 — Gap DB ditemukan QC Integrator (8 Jul 2026), P1 blocker:
--
-- PM-PLAN-SANGGRALOKA-ONE.md §2 mendefinisikan 10 role baru CREW/SELL
-- (gm, hr_admin, hr_staff, fc, supervisor, employee, sales_manager, sales,
-- ewm, design) yang dipakai penuh oleh src/Auth/Role.php + src/Auth/Acl.php
-- (allowedHrefs/menuBlueprint) dan SEMUA halaman Hr*/Mkt* ($allowedRoles).
-- Namun kolom `user_property_access.role` ENUM TIDAK PERNAH diperluas
-- (masih hanya 6 role FIX lama) dan TIDAK ADA satupun baris seed dengan
-- role baru — artinya sebelum migrasi ini, TIDAK ADA cara login sebagai
-- gm/hr_admin/hr_staff/fc/supervisor/employee/sales_manager/sales/ewm/design;
-- seluruh modul CREW & SELL tidak bisa diuji end-to-end lewat browser.
--
-- Bagian A: perluas ENUM (murni skema, sesuai §2 — tanpa mengubah role lama).
-- Bagian B: 10 user seed DEV-ONLY (satu per role baru, pola sama dgn
--   0002_seed_master.sql) khusus untuk QC/UAT login. BUKAN data karyawan
--   nyata — jangan dipakai sbg dasar assignment role staf sungguhan
--   (itu keputusan HR/GM, di luar wewenang QC). Password semua: 'password'
--   (hash sama dgn 0002/0006). JANGAN dijalankan di produksi.
--
-- Jalankan setelah 0013.
-- =====================================================================

-- ---- A. Perluas ENUM role (tambah 10 role baru, role lama tetap) ----------
ALTER TABLE user_property_access
    MODIFY role ENUM(
        'super_admin','property_admin','dept_head','technician','reporter','viewer',
        'gm','hr_admin','hr_staff','fc','supervisor','employee',
        'sales_manager','sales','ewm','design'
    ) NOT NULL;

-- ---- B. 10 user QC/UAT, satu per role baru (property_id = 1) --------------
-- Password placeholder: bcrypt('password') — hash sama dgn 0002_seed_master.sql.
INSERT INTO users (id, username, password_hash, full_name, phone, active) VALUES
(900, 'qc.gm',            '$2y$10$f9LlXj.sDFB2CiQjtjHdX.7gDXj9PdqJldXbcNaeuZcIrsfDDoAd2', '[QC] Demo GM',                  '0811000900', 1),
(901, 'qc.hr_admin',       '$2y$10$f9LlXj.sDFB2CiQjtjHdX.7gDXj9PdqJldXbcNaeuZcIrsfDDoAd2', '[QC] Demo HC Manager',          '0811000901', 1),
(902, 'qc.hr_staff',       '$2y$10$f9LlXj.sDFB2CiQjtjHdX.7gDXj9PdqJldXbcNaeuZcIrsfDDoAd2', '[QC] Demo Staf HR',             '0811000902', 1),
(903, 'qc.fc',             '$2y$10$f9LlXj.sDFB2CiQjtjHdX.7gDXj9PdqJldXbcNaeuZcIrsfDDoAd2', '[QC] Demo Financial Controller','0811000903', 1),
(904, 'qc.supervisor',     '$2y$10$f9LlXj.sDFB2CiQjtjHdX.7gDXj9PdqJldXbcNaeuZcIrsfDDoAd2', '[QC] Demo Supervisor',          '0811000904', 1),
(905, 'qc.employee',       '$2y$10$f9LlXj.sDFB2CiQjtjHdX.7gDXj9PdqJldXbcNaeuZcIrsfDDoAd2', '[QC] Demo Karyawan',            '0811000905', 1),
(906, 'qc.sales_manager',  '$2y$10$f9LlXj.sDFB2CiQjtjHdX.7gDXj9PdqJldXbcNaeuZcIrsfDDoAd2', '[QC] Demo Sales Manager',       '0811000906', 1),
(907, 'qc.sales',          '$2y$10$f9LlXj.sDFB2CiQjtjHdX.7gDXj9PdqJldXbcNaeuZcIrsfDDoAd2', '[QC] Demo Sales',               '0811000907', 1),
(908, 'qc.ewm',            '$2y$10$f9LlXj.sDFB2CiQjtjHdX.7gDXj9PdqJldXbcNaeuZcIrsfDDoAd2', '[QC] Demo Event & Wedding Mgr', '0811000908', 1),
(909, 'qc.design',         '$2y$10$f9LlXj.sDFB2CiQjtjHdX.7gDXj9PdqJldXbcNaeuZcIrsfDDoAd2', '[QC] Demo Graphic Design',      '0811000909', 1);

INSERT INTO user_property_access (user_id, property_id, role, department) VALUES
(900, 1, 'gm',            NULL),
(901, 1, 'hr_admin',      'hr'),
(902, 1, 'hr_staff',      'hr'),
(903, 1, 'fc',            'finance'),
(904, 1, 'supervisor',    'housekeeping'),
(905, 1, 'employee',      'housekeeping'),
(906, 1, 'sales_manager', 'sales'),
(907, 1, 'sales',         'sales'),
(908, 1, 'ewm',           'sales'),
(909, 1, 'design',        'sales');

-- =====================================================================
-- END 0014_crew_sell_role_enum_seed.sql
-- Catatan: assignment role staf Sanggraloka Ubud SUNGGUHAN ke role baru ini
-- (mis. siapa hr_admin/sales_manager sebenarnya di antara user 501-592 hasil
-- 0006_seed_real_users.sql) adalah keputusan HR/GM — di luar wewenang QC,
-- BELUM dilakukan migrasi ini. Lihat docs/QC-SANGGRALOKA-ONE.md P1.
-- =====================================================================
