-- Impor setelah schema.sql pada database RIETS yang sedang dipilih.
INSERT INTO roles(name,description) VALUES
('Super Admin','Akses penuh'),('Admin','Operasional sistem'),('HRD','SDM dan laporan'),('Manager','Dashboard dan laporan'),
('Supervisor','Monitoring tim'),('Karyawan','Aplikasi perangkat'),('IT','Infrastruktur dan perangkat');

INSERT INTO permissions(code,name,module) VALUES
('dashboard.view','Lihat dashboard','dashboard'),('master.manage','Kelola master data','master'),
('tracking.view','Lihat tracking','tracking'),('tracking.manage','Kelola tracking','tracking'),
('report.view','Lihat laporan','report'),('report.export','Export laporan','report'),
('settings.manage','Kelola pengaturan','settings'),('audit.view','Lihat audit','audit'),
('device_policy.view','Lihat kebijakan perangkat','device_policy'),
('device_policy.manage','Kelola kebijakan perangkat','device_policy');
INSERT INTO role_permissions SELECT 1,id FROM permissions;
INSERT INTO role_permissions SELECT 2,id FROM permissions WHERE code NOT IN ('audit.view');
INSERT INTO role_permissions SELECT 3,id FROM permissions WHERE code IN ('dashboard.view','master.manage','tracking.view','report.view','report.export');
INSERT INTO role_permissions SELECT 4,id FROM permissions WHERE code IN ('dashboard.view','tracking.view','report.view','report.export');
INSERT INTO role_permissions SELECT 5,id FROM permissions WHERE code IN ('dashboard.view','tracking.view','report.view');
INSERT INTO role_permissions SELECT 7,id FROM permissions WHERE code IN ('dashboard.view','master.manage','tracking.view','settings.manage','audit.view');
INSERT INTO role_permissions SELECT 7,id FROM permissions WHERE code IN ('device_policy.view','device_policy.manage');

-- Password: Admin@12345 (ubah segera setelah login)
INSERT INTO users(role_id,name,email,password_hash,is_active,password_changed_at)
VALUES(1,'Administrator RIETS','admin@riets.local','$argon2id$v=19$m=65536,t=4,p=1$U2J5T1Y3a0trWWRaVUtZNQ$VSBStDDcD6Xmt7lP+KQvNNaTk10v2eF+dA+Bh1KbXgo',1,NOW());

INSERT INTO divisions(code,name) VALUES('IT','Information Technology'),('HRD','Human Resources'),('OPS','Operasional');
INSERT INTO positions(name) VALUES('Manager'),('Supervisor'),('Staff');
INSERT INTO users(role_id,name,email,password_hash,is_active,password_changed_at)
VALUES(6,'Samsul','samsul@riets.local','$argon2id$v=19$m=65536,t=4,p=1$U2J5T1Y3a0trWWRaVUtZNQ$VSBStDDcD6Xmt7lP+KQvNNaTk10v2eF+dA+Bh1KbXgo',1,NOW());
INSERT INTO employees(user_id,division_id,position_id,nik,name,phone,email,status)
VALUES(2,3,3,'RKA-0001','Samsul','080000000000','samsul@riets.local','active');
INSERT INTO buildings(code,name,address,area_m2,latitude,longitude) VALUES('GD-A','Gedung Produksi','Kompleks RKA',2500,-6.2000000,106.8166667);
INSERT INTO floors(building_id,name,level_no,width_px,height_px,scale_px_per_meter) VALUES(1,'Lantai 1',1,1200,800,10);
INSERT INTO rooms(floor_id,code,name,x,y,width,height,is_restricted) VALUES
(1,'GDG','Gudang',50,50,300,250,0),(1,'QC','Quality Control',400,50,280,250,0),(1,'PANEL','Panel Listrik',750,50,220,200,1);
INSERT INTO qr_areas(room_id,building_id,code,name,latitude,longitude,radius_m,status,created_by)
VALUES(1,1,'RKA-GD-A-GUDANG','Area Masuk Gudang',-6.2000000,106.8166667,150,'active',1);
INSERT INTO beacons(floor_id,code,uuid,major,minor,x,y,tx_power,radius_m,status) VALUES
(1,'BCN-A01','fda50693-a4e2-4fb1-afcf-c6eb07647825',1,1,80,80,-59,15,'active'),
(1,'BCN-A02','fda50693-a4e2-4fb1-afcf-c6eb07647825',1,2,620,80,-59,15,'active'),
(1,'BCN-A03','fda50693-a4e2-4fb1-afcf-c6eb07647825',1,3,450,500,-59,15,'active');
INSERT INTO work_schedules(name,day_of_week,start_time,end_time) VALUES
('Reguler',1,'08:00:00','17:00:00'),('Reguler',2,'08:00:00','17:00:00'),('Reguler',3,'08:00:00','17:00:00'),
('Reguler',4,'08:00:00','17:00:00'),('Reguler',5,'08:00:00','17:00:00');
INSERT INTO system_settings(setting_key,setting_value,is_public) VALUES
('tracking_interval_seconds','1',1),('offline_after_seconds','30',1),('gps_max_accuracy_m','100',1),
('enforce_work_schedule','true',1),
('location_engines','{"gps":true,"ble":true,"uwb":false,"rfid":false}',1),('company_name','"RKA"',1),
('device_policy_enabled','true',0),
('device_policy_notice','"Pemantauan aplikasi hanya dari MDM/proxy/firewall resmi atau input admin, bukan penyadapan browser."',0);

INSERT INTO device_restriction_profiles
(name,description,mdm_provider,camera_allowed,social_media_allowed,youtube_allowed,require_location_enabled,settings,is_active)
VALUES
('Profil Operasional RKA','Profil perangkat kerja: lokasi wajib aktif, sosmed dan kamera mengikuti kebijakan perusahaan.',NULL,0,0,0,1,
 '{"tracking_interval_seconds":1,"allowed_sources":["mdm","proxy","firewall","admin_manual"]}',1);

INSERT INTO device_policy_rules(rule_type,rule_key,rule_label,severity,notes) VALUES
('blocked_domain','instagram.com','Instagram','warning','Blokir melalui DNS/proxy/firewall atau MDM browser policy'),
('blocked_domain','facebook.com','Facebook','warning','Blokir melalui DNS/proxy/firewall atau MDM browser policy'),
('blocked_domain','youtube.com','YouTube','warning','Blokir melalui DNS/proxy/firewall atau MDM browser policy'),
('blocked_domain','tiktok.com','TikTok','warning','Blokir melalui DNS/proxy/firewall atau MDM browser policy'),
('blocked_app','com.instagram.android','Instagram Android','warning','Butuh Android Enterprise MDM untuk enforcement'),
('blocked_app','com.facebook.katana','Facebook Android','warning','Butuh Android Enterprise MDM untuk enforcement'),
('blocked_app','com.google.android.youtube','YouTube Android','warning','Butuh Android Enterprise MDM untuk enforcement'),
('blocked_app','com.zhiliaoapp.musically','TikTok Android','warning','Butuh Android Enterprise MDM untuk enforcement'),
('camera_restriction','camera','Pembatasan kamera','critical','Butuh MDM pada perangkat perusahaan/supervised');
