-- IT System Handover - System Integration SQL
-- This script adds the necessary DocTypes and Menu items into the system.

-- 1. Register DocTypes (For Permission Management)
INSERT INTO doctypes (creation, modified, modified_by, owner, enabled, name, display_name, description)
VALUES 
(NOW(), NOW(), 1, 1, 1, 'HandoverRequest', 'Handover Request (SOW)', 'Management of IT System Handover Requests / Scope of Work'),
(NOW(), NOW(), 1, 1, 1, 'HandoverCompletion', 'Handover Completion (BAST)', 'Management of IT System Handover Completion / Berita Acara Serah Terima');

-- 2. Add Menu Item under 'Application' (Parent ID 2)
-- Icon recommended: IconRepeat or IconClipboardCheck
INSERT INTO menus (creation, modified, modified_by, owner, enabled, name, title, type, icon, url, parent_id, order_no, is_parent)
VALUES 
(NOW(), NOW(), 1, 1, 1, 'handovers', 'IT System Handover', 'item', 'IconClipboardCheck', '/apps/handovers', 2, 99, 0);

-- 3. Setup Default Permissions for Administrator (Role ID 1)
-- This ensures the admin can see and test the module immediately.
INSERT INTO permissions (role_id, doctype_id, can_create, can_read, can_update, can_delete, scope)
SELECT 1, id, 1, 1, 1, 1, 'ALL'
FROM doctypes 
WHERE name IN ('HandoverRequest', 'HandoverCompletion');

-- 4. Setup Role-Menu association for Administrator (Role ID 1)
-- This makes the menu visible to administrators.
INSERT INTO role_menu (role_id, menu_id)
SELECT 1, id
FROM menus
WHERE name = 'handovers' AND url = '/apps/handovers';
