-- V108__sample_data.sql (MySQL)
-- Sample data for WTM system based on WBS.xlsx and Activity.xlsx

-- ============================================================
-- 1. SAMPLE USERS (10 users with different roles)
-- ============================================================
INSERT IGNORE INTO users (employee_id, email, username, full_name, hashed_password, department, discipline, position_title, location, employment_type, is_active)
VALUES
    ('EMP001', 'john.kim@company.com',      'john.kim',      'John Kim',       '$2a$10$dummyhash000000000000000000000000000000000000000001', 'Project Management', 'PJM', 'Project Manager',          'ONSHORE', 'INTERNAL', 1),
    ('EMP002', 'sarah.lee@company.com',      'sarah.lee',     'Sarah Lee',      '$2a$10$dummyhash000000000000000000000000000000000000000002', 'Project Controls',   'PCM', 'Project Control Manager',  'ONSHORE', 'INTERNAL', 1),
    ('EMP003', 'mike.park@company.com',      'mike.park',     'Mike Park',      '$2a$10$dummyhash000000000000000000000000000000000000000003', 'Project Controls',   'PTK', 'Project Timekeeper',       'ONSHORE', 'INTERNAL', 1),
    ('EMP004', 'david.choi@company.com',     'david.choi',    'David Choi',     '$2a$10$dummyhash000000000000000000000000000000000000000004', 'Engineering',        'PIP', 'Discipline Lead - Piping', 'ONSHORE', 'INTERNAL', 1),
    ('EMP005', 'emma.jung@company.com',      'emma.jung',     'Emma Jung',      '$2a$10$dummyhash000000000000000000000000000000000000000005', 'Engineering',        'PRO', 'Discipline Lead - Process','ONSHORE', 'INTERNAL', 1),
    ('EMP006', 'james.han@company.com',      'james.han',     'James Han',      '$2a$10$dummyhash000000000000000000000000000000000000000006', 'Engineering',        'STR', 'Discipline Lead - Structural','ONSHORE', 'INTERNAL', 1),
    ('EMP007', 'lisa.yoon@company.com',      'lisa.yoon',     'Lisa Yoon',      '$2a$10$dummyhash000000000000000000000000000000000000000007', 'Engineering',        'ELC', 'Discipline Lead - Electrical','ONSHORE', 'INTERNAL', 1),
    ('EMP008', 'ryan.seo@company.com',       'ryan.seo',      'Ryan Seo',       '$2a$10$dummyhash000000000000000000000000000000000000000008', 'Engineering',        'PRO', 'Senior Process Engineer',  'ONSHORE', 'INTERNAL', 1),
    ('EMP009', 'anna.kwon@company.com',      'anna.kwon',     'Anna Kwon',      '$2a$10$dummyhash000000000000000000000000000000000000000009', 'Engineering',        'PIP', 'Piping Engineer',          'ONSHORE', 'INTERNAL', 1),
    ('EMP010', 'admin@company.com',          'admin',         'System Admin',   '$2a$10$dummyhash000000000000000000000000000000000000000010', 'IT',                 NULL,  'System Administrator',     'ONSHORE', 'INTERNAL', 1);

-- ============================================================
-- 2. SAMPLE PROJECT (1 EPC project)
-- ============================================================
INSERT IGNORE INTO projects (project_code, name, description, project_type, status, start_date, end_date, pm_user_id)
VALUES (
    'EPU-2026-001',
    'FPSO Topside Module',
    'FPSO Topside Module Engineering, Procurement, Construction and Installation Project',
    'EPC',
    'ACTIVE',
    '2026-01-06',
    '2028-12-31',
    (SELECT id FROM users WHERE employee_id = 'EMP001')
);

-- ============================================================
-- 3. USER ROLES (assign roles to users per project)
-- ============================================================
-- SA role for admin (global, no project)
INSERT IGNORE INTO user_roles (user_id, role_id, project_id, granted_by)
SELECT u.id, r.id, NULL, (SELECT id FROM users WHERE employee_id = 'EMP001')
FROM users u, roles r WHERE u.employee_id = 'EMP010' AND r.code = 'SA';

-- PM role
INSERT IGNORE INTO user_roles (user_id, role_id, project_id, granted_by)
SELECT u.id, r.id, p.id, (SELECT id FROM users WHERE employee_id = 'EMP010')
FROM users u, roles r, projects p WHERE u.employee_id = 'EMP001' AND r.code = 'PM' AND p.project_code = 'EPU-2026-001';

-- PCM role
INSERT IGNORE INTO user_roles (user_id, role_id, project_id, granted_by)
SELECT u.id, r.id, p.id, (SELECT id FROM users WHERE employee_id = 'EMP001')
FROM users u, roles r, projects p WHERE u.employee_id = 'EMP002' AND r.code = 'PCM' AND p.project_code = 'EPU-2026-001';

-- PTK role
INSERT IGNORE INTO user_roles (user_id, role_id, project_id, granted_by)
SELECT u.id, r.id, p.id, (SELECT id FROM users WHERE employee_id = 'EMP001')
FROM users u, roles r, projects p WHERE u.employee_id = 'EMP003' AND r.code = 'PTK' AND p.project_code = 'EPU-2026-001';

-- DL roles (4 discipline leads)
INSERT IGNORE INTO user_roles (user_id, role_id, project_id, granted_by)
SELECT u.id, r.id, p.id, (SELECT id FROM users WHERE employee_id = 'EMP001')
FROM users u, roles r, projects p WHERE u.employee_id = 'EMP004' AND r.code = 'DL' AND p.project_code = 'EPU-2026-001';

INSERT IGNORE INTO user_roles (user_id, role_id, project_id, granted_by)
SELECT u.id, r.id, p.id, (SELECT id FROM users WHERE employee_id = 'EMP001')
FROM users u, roles r, projects p WHERE u.employee_id = 'EMP005' AND r.code = 'DL' AND p.project_code = 'EPU-2026-001';

INSERT IGNORE INTO user_roles (user_id, role_id, project_id, granted_by)
SELECT u.id, r.id, p.id, (SELECT id FROM users WHERE employee_id = 'EMP001')
FROM users u, roles r, projects p WHERE u.employee_id = 'EMP006' AND r.code = 'DL' AND p.project_code = 'EPU-2026-001';

INSERT IGNORE INTO user_roles (user_id, role_id, project_id, granted_by)
SELECT u.id, r.id, p.id, (SELECT id FROM users WHERE employee_id = 'EMP001')
FROM users u, roles r, projects p WHERE u.employee_id = 'EMP007' AND r.code = 'DL' AND p.project_code = 'EPU-2026-001';

-- USER roles (general engineers)
INSERT IGNORE INTO user_roles (user_id, role_id, project_id, granted_by)
SELECT u.id, r.id, p.id, (SELECT id FROM users WHERE employee_id = 'EMP001')
FROM users u, roles r, projects p WHERE u.employee_id = 'EMP008' AND r.code = 'USER' AND p.project_code = 'EPU-2026-001';

INSERT IGNORE INTO user_roles (user_id, role_id, project_id, granted_by)
SELECT u.id, r.id, p.id, (SELECT id FROM users WHERE employee_id = 'EMP001')
FROM users u, roles r, projects p WHERE u.employee_id = 'EMP009' AND r.code = 'USER' AND p.project_code = 'EPU-2026-001';

-- ============================================================
-- 4. PROJECT ASSIGNMENTS (assign all users to the project)
-- ============================================================
INSERT IGNORE INTO project_assignments (project_id, user_id, role, assigned_by)
SELECT p.id, u.id, 'PM', (SELECT id FROM users WHERE employee_id = 'EMP010')
FROM projects p, users u WHERE p.project_code = 'EPU-2026-001' AND u.employee_id = 'EMP001';

INSERT IGNORE INTO project_assignments (project_id, user_id, role, assigned_by)
SELECT p.id, u.id, 'PCM', (SELECT id FROM users WHERE employee_id = 'EMP001')
FROM projects p, users u WHERE p.project_code = 'EPU-2026-001' AND u.employee_id = 'EMP002';

INSERT IGNORE INTO project_assignments (project_id, user_id, role, assigned_by)
SELECT p.id, u.id, 'PTK', (SELECT id FROM users WHERE employee_id = 'EMP001')
FROM projects p, users u WHERE p.project_code = 'EPU-2026-001' AND u.employee_id = 'EMP003';

INSERT IGNORE INTO project_assignments (project_id, user_id, role, assigned_by)
SELECT p.id, u.id, 'DL_PIP', (SELECT id FROM users WHERE employee_id = 'EMP001')
FROM projects p, users u WHERE p.project_code = 'EPU-2026-001' AND u.employee_id = 'EMP004';

INSERT IGNORE INTO project_assignments (project_id, user_id, role, assigned_by)
SELECT p.id, u.id, 'DL_PRO', (SELECT id FROM users WHERE employee_id = 'EMP001')
FROM projects p, users u WHERE p.project_code = 'EPU-2026-001' AND u.employee_id = 'EMP005';

INSERT IGNORE INTO project_assignments (project_id, user_id, role, assigned_by)
SELECT p.id, u.id, 'DL_STR', (SELECT id FROM users WHERE employee_id = 'EMP001')
FROM projects p, users u WHERE p.project_code = 'EPU-2026-001' AND u.employee_id = 'EMP006';

INSERT IGNORE INTO project_assignments (project_id, user_id, role, assigned_by)
SELECT p.id, u.id, 'DL_ELC', (SELECT id FROM users WHERE employee_id = 'EMP001')
FROM projects p, users u WHERE p.project_code = 'EPU-2026-001' AND u.employee_id = 'EMP007';

INSERT IGNORE INTO project_assignments (project_id, user_id, role, assigned_by)
SELECT p.id, u.id, 'ENGINEER', (SELECT id FROM users WHERE employee_id = 'EMP005')
FROM projects p, users u WHERE p.project_code = 'EPU-2026-001' AND u.employee_id = 'EMP008';

INSERT IGNORE INTO project_assignments (project_id, user_id, role, assigned_by)
SELECT p.id, u.id, 'ENGINEER', (SELECT id FROM users WHERE employee_id = 'EMP004')
FROM projects p, users u WHERE p.project_code = 'EPU-2026-001' AND u.employee_id = 'EMP009';

-- ============================================================
-- 5. WBS VERSION + NODES (from WBS.xlsx Canonical WBS)
-- ============================================================
INSERT IGNORE INTO wbs_versions (project_id, version_number, effective_date, source_type, description, status, uploaded_by)
SELECT p.id, 1, '2026-01-06', 'MANUAL', 'Initial WBS from Canonical WBS template', 'ACTIVE', (SELECT id FROM users WHERE employee_id = 'EMP001')
FROM projects p WHERE p.project_code = 'EPU-2026-001';

-- LV1: Project
SET @wbs_ver_id = (SELECT wv.id FROM wbs_versions wv JOIN projects p ON wv.project_id = p.id WHERE p.project_code = 'EPU-2026-001' AND wv.version_number = 1);

INSERT IGNORE INTO wbs_nodes (wbs_version_id, parent_id, wbs_code, level, name, discipline, planned_hours, sort_order, is_leaf)
VALUES (@wbs_ver_id, NULL, 'F0001', 1, 'FPSO Topside Module Project', NULL, 500000.00, 1, 0);

SET @lv1_id = (SELECT id FROM wbs_nodes WHERE wbs_version_id = @wbs_ver_id AND wbs_code = 'F0001');

-- LV2: Phases (from WBS.xlsx Column L - Activity Area)
INSERT IGNORE INTO wbs_nodes (wbs_version_id, parent_id, wbs_code, level, name, discipline, planned_hours, sort_order, is_leaf) VALUES
    (@wbs_ver_id, @lv1_id, 'F0001.GNAL', 2, 'General',                           NULL, 5000.00,   1, 0),
    (@wbs_ver_id, @lv1_id, 'F0001.MGMT', 2, 'Management Activities',             NULL, 50000.00,  2, 0),
    (@wbs_ver_id, @lv1_id, 'F0001.ENGR', 2, 'Engineering',                       NULL, 300000.00, 3, 0),
    (@wbs_ver_id, @lv1_id, 'F0001.PROC', 2, 'Procurement',                       NULL, 30000.00,  4, 0),
    (@wbs_ver_id, @lv1_id, 'F0001.CONS', 2, 'Construction',                      NULL, 80000.00,  5, 0),
    (@wbs_ver_id, @lv1_id, 'F0001.PRCM', 2, 'Pre-commissioning',                NULL, 10000.00,  6, 0),
    (@wbs_ver_id, @lv1_id, 'F0001.COMM', 2, 'Commissioning & Start-up',         NULL, 15000.00,  7, 0),
    (@wbs_ver_id, @lv1_id, 'F0001.TRNS', 2, 'Transport & Logistics',            NULL, 5000.00,   8, 0),
    (@wbs_ver_id, @lv1_id, 'F0001.INST', 2, 'Installation Works',               NULL, 3000.00,   9, 0),
    (@wbs_ver_id, @lv1_id, 'F0001.OCOM', 2, 'Offshore Commissioning',           NULL, 2000.00,  10, 0);

-- LV3: Areas under ENGR (from WBS.xlsx Column O - Area)
SET @engr_id = (SELECT id FROM wbs_nodes WHERE wbs_version_id = @wbs_ver_id AND wbs_code = 'F0001.ENGR');
SET @mgmt_id = (SELECT id FROM wbs_nodes WHERE wbs_version_id = @wbs_ver_id AND wbs_code = 'F0001.MGMT');
SET @proc_id = (SELECT id FROM wbs_nodes WHERE wbs_version_id = @wbs_ver_id AND wbs_code = 'F0001.PROC');
SET @cons_id = (SELECT id FROM wbs_nodes WHERE wbs_version_id = @wbs_ver_id AND wbs_code = 'F0001.CONS');
SET @gnal_id = (SELECT id FROM wbs_nodes WHERE wbs_version_id = @wbs_ver_id AND wbs_code = 'F0001.GNAL');

INSERT IGNORE INTO wbs_nodes (wbs_version_id, parent_id, wbs_code, level, name, discipline, planned_hours, sort_order, is_leaf) VALUES
    (@wbs_ver_id, @engr_id, 'F0001.ENGR.GN', 3, 'General',         NULL, 10000.00, 1, 0),
    (@wbs_ver_id, @engr_id, 'F0001.ENGR.TP', 3, 'Topside',         NULL, 200000.00, 2, 0),
    (@wbs_ver_id, @engr_id, 'F0001.ENGR.HL', 3, 'Hull & Marine',   NULL, 60000.00, 3, 0),
    (@wbs_ver_id, @engr_id, 'F0001.ENGR.MO', 3, 'Mooring',         NULL, 20000.00, 4, 0),
    (@wbs_ver_id, @engr_id, 'F0001.ENGR.OF', 3, 'Offshore',        NULL, 10000.00, 5, 0),
    (@wbs_ver_id, @mgmt_id, 'F0001.MGMT.GN', 3, 'General',         NULL, 50000.00, 1, 0),
    (@wbs_ver_id, @proc_id, 'F0001.PROC.TP', 3, 'Topside',         NULL, 20000.00, 1, 0),
    (@wbs_ver_id, @proc_id, 'F0001.PROC.HL', 3, 'Hull & Marine',   NULL, 10000.00, 2, 0),
    (@wbs_ver_id, @cons_id, 'F0001.CONS.TP', 3, 'Topside',         NULL, 50000.00, 1, 0),
    (@wbs_ver_id, @cons_id, 'F0001.CONS.HL', 3, 'Hull & Marine',   NULL, 30000.00, 2, 0);

-- LV4: Disciplines under ENGR.TP (from WBS.xlsx Column T - Discipline codes)
SET @engr_tp_id = (SELECT id FROM wbs_nodes WHERE wbs_version_id = @wbs_ver_id AND wbs_code = 'F0001.ENGR.TP');
SET @engr_hl_id = (SELECT id FROM wbs_nodes WHERE wbs_version_id = @wbs_ver_id AND wbs_code = 'F0001.ENGR.HL');
SET @mgmt_gn_id = (SELECT id FROM wbs_nodes WHERE wbs_version_id = @wbs_ver_id AND wbs_code = 'F0001.MGMT.GN');

INSERT IGNORE INTO wbs_nodes (wbs_version_id, parent_id, wbs_code, level, name, discipline, planned_hours, sort_order, is_leaf) VALUES
    -- Management disciplines
    (@wbs_ver_id, @mgmt_gn_id, 'F0001.MGMT.GN.PJM', 4, 'Project Management',                 'PJM', 15000.00, 1, 0),
    (@wbs_ver_id, @mgmt_gn_id, 'F0001.MGMT.GN.QAS', 4, 'Quality Assurance',                   'QAS', 5000.00,  2, 0),
    (@wbs_ver_id, @mgmt_gn_id, 'F0001.MGMT.GN.HSE', 4, 'Health & Safety',                     'HSE', 5000.00,  3, 0),
    (@wbs_ver_id, @mgmt_gn_id, 'F0001.MGMT.GN.RSK', 4, 'Risk Management',                     'RSK', 3000.00,  4, 0),
    (@wbs_ver_id, @mgmt_gn_id, 'F0001.MGMT.GN.SLP', 4, 'Safety & Loss Prevention',            'SLP', 3000.00,  5, 0),
    (@wbs_ver_id, @mgmt_gn_id, 'F0001.MGMT.GN.EGM', 4, 'Engineering General Management',      'EGM', 4000.00,  6, 0),
    (@wbs_ver_id, @mgmt_gn_id, 'F0001.MGMT.GN.EPM', 4, 'Engineering Project Management',      'EPM', 5000.00,  7, 0),
    (@wbs_ver_id, @mgmt_gn_id, 'F0001.MGMT.GN.ESM', 4, 'Engineering Subcontract Management',  'ESM', 3000.00,  8, 0),
    (@wbs_ver_id, @mgmt_gn_id, 'F0001.MGMT.GN.INF', 4, 'Information Management',              'INF', 3000.00,  9, 0),
    (@wbs_ver_id, @mgmt_gn_id, 'F0001.MGMT.GN.SCM', 4, 'Supply Chain Management',             'SCM', 4000.00, 10, 0),
    (@wbs_ver_id, @mgmt_gn_id, 'F0001.MGMT.GN.PPM', 4, 'Project Procurement Management',      'PPM', 3000.00, 11, 0),
    -- Engineering disciplines under Topside
    (@wbs_ver_id, @engr_tp_id, 'F0001.ENGR.TP.PRO', 4, 'Process',                             'PRO', 35000.00, 1, 0),
    (@wbs_ver_id, @engr_tp_id, 'F0001.ENGR.TP.PIP', 4, 'Piping',                              'PIP', 40000.00, 2, 0),
    (@wbs_ver_id, @engr_tp_id, 'F0001.ENGR.TP.STR', 4, 'Structure',                           'STR', 30000.00, 3, 0),
    (@wbs_ver_id, @engr_tp_id, 'F0001.ENGR.TP.ELC', 4, 'Electrical',                          'ELC', 20000.00, 4, 0),
    (@wbs_ver_id, @engr_tp_id, 'F0001.ENGR.TP.INS', 4, 'Instrument',                          'INS', 18000.00, 5, 0),
    (@wbs_ver_id, @engr_tp_id, 'F0001.ENGR.TP.MEC', 4, 'Mechanical',                          'MEC', 15000.00, 6, 0),
    (@wbs_ver_id, @engr_tp_id, 'F0001.ENGR.TP.CIV', 4, 'Civil',                               'CIV', 8000.00,  7, 0),
    (@wbs_ver_id, @engr_tp_id, 'F0001.ENGR.TP.SFF', 4, 'Safety & Fire Fighting',              'SFF', 10000.00, 8, 0),
    (@wbs_ver_id, @engr_tp_id, 'F0001.ENGR.TP.HVC', 4, 'HVAC',                                'HVC', 5000.00,  9, 0),
    (@wbs_ver_id, @engr_tp_id, 'F0001.ENGR.TP.ICS', 4, 'ICSS Engineering',                    'ICS', 8000.00, 10, 0),
    (@wbs_ver_id, @engr_tp_id, 'F0001.ENGR.TP.TEL', 4, 'Telecommunication',                   'TEL', 5000.00, 11, 0),
    (@wbs_ver_id, @engr_tp_id, 'F0001.ENGR.TP.MOD', 4, '3D Modeling',                         'MOD', 6000.00, 12, 0),
    (@wbs_ver_id, @engr_tp_id, 'F0001.ENGR.TP.WGT', 4, 'Weight Control',                      'WGT', 3000.00, 13, 0),
    (@wbs_ver_id, @engr_tp_id, 'F0001.ENGR.TP.MCP', 4, 'Material & Corrosion Protection',     'MCP', 4000.00, 14, 0),
    -- Engineering disciplines under Hull
    (@wbs_ver_id, @engr_hl_id, 'F0001.ENGR.HL.NAV', 4, 'Naval Architecture',                  'NAV', 15000.00, 1, 0),
    (@wbs_ver_id, @engr_hl_id, 'F0001.ENGR.HL.STR', 4, 'Structure',                           'STR', 20000.00, 2, 0),
    (@wbs_ver_id, @engr_hl_id, 'F0001.ENGR.HL.OUF', 4, 'Outfitting',                          'OUF', 8000.00,  3, 0),
    (@wbs_ver_id, @engr_hl_id, 'F0001.ENGR.HL.HYD', 4, 'Hydrodynamics',                       'HYD', 5000.00,  4, 0),
    (@wbs_ver_id, @engr_hl_id, 'F0001.ENGR.HL.MOR', 4, 'Mooring & Riser Pull-in',             'MOR', 5000.00,  5, 0);

-- LV5: Deliverables under Process (from WBS.xlsx Column W)
SET @engr_tp_pro_id = (SELECT id FROM wbs_nodes WHERE wbs_version_id = @wbs_ver_id AND wbs_code = 'F0001.ENGR.TP.PRO');
SET @engr_tp_pip_id = (SELECT id FROM wbs_nodes WHERE wbs_version_id = @wbs_ver_id AND wbs_code = 'F0001.ENGR.TP.PIP');
SET @engr_tp_str_id = (SELECT id FROM wbs_nodes WHERE wbs_version_id = @wbs_ver_id AND wbs_code = 'F0001.ENGR.TP.STR');
SET @engr_tp_sff_id = (SELECT id FROM wbs_nodes WHERE wbs_version_id = @wbs_ver_id AND wbs_code = 'F0001.ENGR.TP.SFF');
SET @engr_tp_mec_id = (SELECT id FROM wbs_nodes WHERE wbs_version_id = @wbs_ver_id AND wbs_code = 'F0001.ENGR.TP.MEC');
SET @engr_tp_elc_id = (SELECT id FROM wbs_nodes WHERE wbs_version_id = @wbs_ver_id AND wbs_code = 'F0001.ENGR.TP.ELC');
SET @engr_tp_ins_id = (SELECT id FROM wbs_nodes WHERE wbs_version_id = @wbs_ver_id AND wbs_code = 'F0001.ENGR.TP.INS');

INSERT IGNORE INTO wbs_nodes (wbs_version_id, parent_id, wbs_code, level, name, discipline, planned_hours, sort_order, is_leaf) VALUES
    -- Process deliverables
    (@wbs_ver_id, @engr_tp_pro_id, 'F0001.ENGR.TP.PRO.PRO008', 5, 'Heat and Material Balance',                    'PRO', 3000.00, 1, 1),
    (@wbs_ver_id, @engr_tp_pro_id, 'F0001.ENGR.TP.PRO.PRO003', 5, 'Process Flow Diagrams (PFDs)',                 'PRO', 4000.00, 2, 1),
    (@wbs_ver_id, @engr_tp_pro_id, 'F0001.ENGR.TP.PRO.PRO005', 5, 'Piping & Instrumentation Diagrams (P&IDs)',    'PRO', 8000.00, 3, 1),
    (@wbs_ver_id, @engr_tp_pro_id, 'F0001.ENGR.TP.PRO.PRO012', 5, 'Process and Control Philosophy',               'PRO', 2000.00, 4, 1),
    (@wbs_ver_id, @engr_tp_pro_id, 'F0001.ENGR.TP.PRO.PRO009', 5, 'Utilities and Load Balance',                   'PRO', 2500.00, 5, 1),
    (@wbs_ver_id, @engr_tp_pro_id, 'F0001.ENGR.TP.PRO.PRO029', 5, 'Process Design and Equipment Sizing',          'PRO', 3000.00, 6, 1),
    (@wbs_ver_id, @engr_tp_pro_id, 'F0001.ENGR.TP.PRO.PRO002', 5, 'Lines List',                                   'PRO', 2000.00, 7, 1),
    (@wbs_ver_id, @engr_tp_pro_id, 'F0001.ENGR.TP.PRO.PRO006', 5, 'ESD & PSD Logic Diagram',                     'PRO', 1500.00, 8, 1),
    (@wbs_ver_id, @engr_tp_pro_id, 'F0001.ENGR.TP.PRO.PRO030', 5, 'Chemical Requirement and Storage Report',      'PRO', 1000.00, 9, 1),
    (@wbs_ver_id, @engr_tp_pro_id, 'F0001.ENGR.TP.PRO.PRO038', 5, 'Simulation Report and Models',                 'PRO', 2000.00,10, 1),
    (@wbs_ver_id, @engr_tp_pro_id, 'F0001.ENGR.TP.PRO.PRO007', 5, 'ESD & PSD Cause and Effects Matrix',          'PRO', 1500.00,11, 1),
    -- Safety deliverables
    (@wbs_ver_id, @engr_tp_sff_id, 'F0001.ENGR.TP.SFF.SAF001', 5, 'Safety Concept',                               'SFF', 1500.00, 1, 1),
    (@wbs_ver_id, @engr_tp_sff_id, 'F0001.ENGR.TP.SFF.SAF099', 5, 'Hazardous Area Classification Philosophy',     'SFF', 1000.00, 2, 1),
    (@wbs_ver_id, @engr_tp_sff_id, 'F0001.ENGR.TP.SFF.SAF802', 5, 'Human Factor Engineering',                     'SFF', 800.00,  3, 1),
    (@wbs_ver_id, @engr_tp_sff_id, 'F0001.ENGR.TP.SFF.SAF104', 5, 'Safety Equipment List',                        'SFF', 600.00,  4, 1),
    (@wbs_ver_id, @engr_tp_sff_id, 'F0001.ENGR.TP.SFF.SAF801', 5, 'Safety Studies',                               'SFF', 1200.00, 5, 1),
    (@wbs_ver_id, @engr_tp_sff_id, 'F0001.ENGR.TP.SFF.SAF025', 5, 'Fire Water and Foam Demand',                   'SFF', 800.00,  6, 1),
    (@wbs_ver_id, @engr_tp_sff_id, 'F0001.ENGR.TP.SFF.SAF062', 5, '3D Fire and Gas Detection Mapping Study',      'SFF', 1000.00, 7, 1),
    -- Mechanical deliverables
    (@wbs_ver_id, @engr_tp_mec_id, 'F0001.ENGR.TP.MEC.MEC002', 5, 'Equipment Mechanical Specification',           'MEC', 3000.00, 1, 1),
    (@wbs_ver_id, @engr_tp_mec_id, 'F0001.ENGR.TP.MEC.ENG014', 5, 'Equipment List',                               'MEC', 2000.00, 2, 1),
    -- Structural deliverables
    (@wbs_ver_id, @engr_tp_str_id, 'F0001.ENGR.TP.STR.STR001', 5, 'Structure Basis of Design',                    'STR', 2000.00, 1, 1),
    (@wbs_ver_id, @engr_tp_str_id, 'F0001.ENGR.TP.STR.STR003', 5, 'Module Main Structure Calculation Report',     'STR', 3000.00, 2, 1),
    (@wbs_ver_id, @engr_tp_str_id, 'F0001.ENGR.TP.STR.STR008', 5, 'Module Main Structure Drawings',               'STR', 5000.00, 3, 1),
    (@wbs_ver_id, @engr_tp_str_id, 'F0001.ENGR.TP.STR.STR009', 5, 'Module Secondary Structure Drawings',          'STR', 4000.00, 4, 1),
    (@wbs_ver_id, @engr_tp_str_id, 'F0001.ENGR.TP.STR.STR033', 5, 'Structural Material Take Off',                 'STR', 2000.00, 5, 1),
    -- Piping deliverables
    (@wbs_ver_id, @engr_tp_pip_id, 'F0001.ENGR.TP.PIP.PVV012', 5, 'Valves Datasheet',                             'PIP', 3000.00, 1, 1),
    (@wbs_ver_id, @engr_tp_pip_id, 'F0001.ENGR.TP.PIP.PVV005', 5, 'Critical Line List',                           'PIP', 2000.00, 2, 1),
    (@wbs_ver_id, @engr_tp_pip_id, 'F0001.ENGR.TP.PIP.ENG032', 5, 'FPSO Overall General Arrangement Plot Plan',   'PIP', 4000.00, 3, 1),
    (@wbs_ver_id, @engr_tp_pip_id, 'F0001.ENGR.TP.PIP.PVV003', 5, 'Piping Stress Calculation Notes',              'PIP', 5000.00, 4, 1),
    (@wbs_ver_id, @engr_tp_pip_id, 'F0001.ENGR.TP.PIP.PVV022', 5, 'Piping Material Classes Specification',        'PIP', 2000.00, 5, 1),
    (@wbs_ver_id, @engr_tp_pip_id, 'F0001.ENGR.TP.PIP.PVV038', 5, 'Isometric Drawings',                           'PIP', 8000.00, 6, 1),
    (@wbs_ver_id, @engr_tp_pip_id, 'F0001.ENGR.TP.PIP.PVV010', 5, 'Piping Material Take-Off',                     'PIP', 3000.00, 7, 1),
    (@wbs_ver_id, @engr_tp_pip_id, 'F0001.ENGR.TP.PIP.PVV007', 5, 'Special Item List',                            'PIP', 1500.00, 8, 1),
    (@wbs_ver_id, @engr_tp_pip_id, 'F0001.ENGR.TP.PIP.PVV008', 5, 'AIV and FIV Study',                            'PIP', 2000.00, 9, 1);

-- ============================================================
-- 6. CANONICAL WBS (mapped from WBS nodes)
-- ============================================================
SET @proj_id = (SELECT id FROM projects WHERE project_code = 'EPU-2026-001');

INSERT IGNORE INTO canonical_wbs (project_id, wbs_code, level, name, parent_code, discipline, is_active, mapped_p6_code) VALUES
    -- LV1
    (@proj_id, 'F0001',           1, 'FPSO Topside Module Project',            NULL,              NULL,  1, 'F0001'),
    -- LV2 Phases
    (@proj_id, 'F0001.GNAL',      2, 'General',                                'F0001',           NULL,  1, 'F0001.GNAL'),
    (@proj_id, 'F0001.MGMT',      2, 'Management Activities',                  'F0001',           NULL,  1, 'F0001.MGMT'),
    (@proj_id, 'F0001.ENGR',      2, 'Engineering',                            'F0001',           NULL,  1, 'F0001.ENGR'),
    (@proj_id, 'F0001.PROC',      2, 'Procurement',                            'F0001',           NULL,  1, 'F0001.PROC'),
    (@proj_id, 'F0001.CONS',      2, 'Construction',                           'F0001',           NULL,  1, 'F0001.CONS'),
    (@proj_id, 'F0001.PRCM',      2, 'Pre-commissioning',                     'F0001',           NULL,  1, 'F0001.PRCM'),
    (@proj_id, 'F0001.COMM',      2, 'Commissioning & Start-up',              'F0001',           NULL,  1, 'F0001.COMM'),
    (@proj_id, 'F0001.TRNS',      2, 'Transport & Logistics',                 'F0001',           NULL,  1, 'F0001.TRNS'),
    (@proj_id, 'F0001.INST',      2, 'Installation Works',                    'F0001',           NULL,  1, 'F0001.INST'),
    (@proj_id, 'F0001.OCOM',      2, 'Offshore Commissioning',                'F0001',           NULL,  1, 'F0001.OCOM'),
    -- LV3 Areas
    (@proj_id, 'F0001.ENGR.GN',   3, 'General',                               'F0001.ENGR',      NULL,  1, 'F0001.ENGR.GN'),
    (@proj_id, 'F0001.ENGR.TP',   3, 'Topside',                               'F0001.ENGR',      NULL,  1, 'F0001.ENGR.TP'),
    (@proj_id, 'F0001.ENGR.HL',   3, 'Hull & Marine',                         'F0001.ENGR',      NULL,  1, 'F0001.ENGR.HL'),
    (@proj_id, 'F0001.ENGR.MO',   3, 'Mooring',                               'F0001.ENGR',      NULL,  1, 'F0001.ENGR.MO'),
    (@proj_id, 'F0001.ENGR.OF',   3, 'Offshore',                              'F0001.ENGR',      NULL,  1, 'F0001.ENGR.OF'),
    (@proj_id, 'F0001.MGMT.GN',   3, 'General',                               'F0001.MGMT',      NULL,  1, 'F0001.MGMT.GN'),
    (@proj_id, 'F0001.PROC.TP',   3, 'Topside',                               'F0001.PROC',      NULL,  1, 'F0001.PROC.TP'),
    (@proj_id, 'F0001.PROC.HL',   3, 'Hull & Marine',                         'F0001.PROC',      NULL,  1, 'F0001.PROC.HL'),
    (@proj_id, 'F0001.CONS.TP',   3, 'Topside',                               'F0001.CONS',      NULL,  1, 'F0001.CONS.TP'),
    (@proj_id, 'F0001.CONS.HL',   3, 'Hull & Marine',                         'F0001.CONS',      NULL,  1, 'F0001.CONS.HL'),
    -- LV4 Disciplines (Engineering Topside)
    (@proj_id, 'F0001.ENGR.TP.PRO', 4, 'Process',                             'F0001.ENGR.TP',   'PRO', 1, 'F0001.ENGR.TP.PRO'),
    (@proj_id, 'F0001.ENGR.TP.PIP', 4, 'Piping',                              'F0001.ENGR.TP',   'PIP', 1, 'F0001.ENGR.TP.PIP'),
    (@proj_id, 'F0001.ENGR.TP.STR', 4, 'Structure',                           'F0001.ENGR.TP',   'STR', 1, 'F0001.ENGR.TP.STR'),
    (@proj_id, 'F0001.ENGR.TP.ELC', 4, 'Electrical',                          'F0001.ENGR.TP',   'ELC', 1, 'F0001.ENGR.TP.ELC'),
    (@proj_id, 'F0001.ENGR.TP.INS', 4, 'Instrument',                          'F0001.ENGR.TP',   'INS', 1, 'F0001.ENGR.TP.INS'),
    (@proj_id, 'F0001.ENGR.TP.MEC', 4, 'Mechanical',                          'F0001.ENGR.TP',   'MEC', 1, 'F0001.ENGR.TP.MEC'),
    (@proj_id, 'F0001.ENGR.TP.CIV', 4, 'Civil',                               'F0001.ENGR.TP',   'CIV', 1, 'F0001.ENGR.TP.CIV'),
    (@proj_id, 'F0001.ENGR.TP.SFF', 4, 'Safety & Fire Fighting',              'F0001.ENGR.TP',   'SFF', 1, 'F0001.ENGR.TP.SFF'),
    (@proj_id, 'F0001.ENGR.TP.HVC', 4, 'HVAC',                                'F0001.ENGR.TP',   'HVC', 1, 'F0001.ENGR.TP.HVC'),
    (@proj_id, 'F0001.ENGR.TP.ICS', 4, 'ICSS Engineering',                    'F0001.ENGR.TP',   'ICS', 1, 'F0001.ENGR.TP.ICS'),
    (@proj_id, 'F0001.ENGR.TP.TEL', 4, 'Telecommunication',                   'F0001.ENGR.TP',   'TEL', 1, 'F0001.ENGR.TP.TEL'),
    (@proj_id, 'F0001.ENGR.TP.MOD', 4, '3D Modeling',                         'F0001.ENGR.TP',   'MOD', 1, 'F0001.ENGR.TP.MOD'),
    (@proj_id, 'F0001.ENGR.TP.WGT', 4, 'Weight Control',                      'F0001.ENGR.TP',   'WGT', 1, 'F0001.ENGR.TP.WGT'),
    (@proj_id, 'F0001.ENGR.TP.MCP', 4, 'Material & Corrosion Protection',     'F0001.ENGR.TP',   'MCP', 1, 'F0001.ENGR.TP.MCP'),
    -- LV4 Disciplines (Engineering Hull)
    (@proj_id, 'F0001.ENGR.HL.NAV', 4, 'Naval Architecture',                  'F0001.ENGR.HL',   'NAV', 1, 'F0001.ENGR.HL.NAV'),
    (@proj_id, 'F0001.ENGR.HL.STR', 4, 'Structure',                           'F0001.ENGR.HL',   'STR', 1, 'F0001.ENGR.HL.STR'),
    (@proj_id, 'F0001.ENGR.HL.OUF', 4, 'Outfitting',                          'F0001.ENGR.HL',   'OUF', 1, 'F0001.ENGR.HL.OUF'),
    (@proj_id, 'F0001.ENGR.HL.HYD', 4, 'Hydrodynamics',                       'F0001.ENGR.HL',   'HYD', 1, 'F0001.ENGR.HL.HYD'),
    (@proj_id, 'F0001.ENGR.HL.MOR', 4, 'Mooring & Riser Pull-in',             'F0001.ENGR.HL',   'MOR', 1, 'F0001.ENGR.HL.MOR'),
    -- LV4 Management disciplines
    (@proj_id, 'F0001.MGMT.GN.PJM', 4, 'Project Management',                  'F0001.MGMT.GN',   'PJM', 1, 'F0001.MGMT.GN.PJM'),
    (@proj_id, 'F0001.MGMT.GN.QAS', 4, 'Quality Assurance',                   'F0001.MGMT.GN',   'QAS', 1, 'F0001.MGMT.GN.QAS'),
    (@proj_id, 'F0001.MGMT.GN.HSE', 4, 'Health & Safety',                     'F0001.MGMT.GN',   'HSE', 1, 'F0001.MGMT.GN.HSE'),
    (@proj_id, 'F0001.MGMT.GN.RSK', 4, 'Risk Management',                     'F0001.MGMT.GN',   'RSK', 1, 'F0001.MGMT.GN.RSK'),
    (@proj_id, 'F0001.MGMT.GN.EPM', 4, 'Engineering Project Management',      'F0001.MGMT.GN',   'EPM', 1, 'F0001.MGMT.GN.EPM'),
    (@proj_id, 'F0001.MGMT.GN.SCM', 4, 'Supply Chain Management',             'F0001.MGMT.GN',   'SCM', 1, 'F0001.MGMT.GN.SCM');

-- ============================================================
-- 7. TEAL VERSION + ENTRIES (from Activity.xlsx)
-- ============================================================
INSERT IGNORE INTO teal_versions (project_id, version_number, effective_date, description, status, uploaded_by)
SELECT p.id, 1, '2026-01-06', 'Initial TEAL from Activity Dictionary', 'ACTIVE', (SELECT id FROM users WHERE employee_id = 'EMP001')
FROM projects p WHERE p.project_code = 'EPU-2026-001';

SET @teal_ver_id = (SELECT tv.id FROM teal_versions tv JOIN projects p ON tv.project_id = p.id WHERE p.project_code = 'EPU-2026-001' AND tv.version_number = 1);

-- EPCI Engineering Activities (from Activity.xlsx - EPCI sheet & Master Activity Dictionary)
INSERT IGNORE INTO teal_entries (teal_version_id, canonical_wbs_id, activity_code, activity_name, discipline, is_active) VALUES
    -- Design Development activities (from Master Activity Dictionary)
    (@teal_ver_id, (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PRO'), 'ENG-DD-LAYOUT-FI',    'Layout - First Issue',                            'PRO', 1),
    (@teal_ver_id, (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PRO'), 'ENG-DD-LAYOUT-REV',   'Layout - Revision',                               'PRO', 1),
    (@teal_ver_id, (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PRO'), 'ENG-DD-PID-FI',       'P&ID - First Issue',                              'PRO', 1),
    (@teal_ver_id, (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PRO'), 'ENG-DD-PID-REV',      'P&ID - Revision',                                 'PRO', 1),
    (@teal_ver_id, (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.ELC'), 'ENG-DD-SLD-FI',       'SLD - First Issue',                               'ELC', 1),
    (@teal_ver_id, (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.ELC'), 'ENG-DD-SLD-REV',      'SLD - Revision',                                  'ELC', 1),
    (@teal_ver_id, (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.STR'), 'ENG-DD-DETDWG-FI',   'Detail Drawing - First Issue',                    'STR', 1),
    (@teal_ver_id, (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.STR'), 'ENG-DD-DETDWG-REV',  'Detail Drawing - Revision',                       'STR', 1),
    (@teal_ver_id, (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PIP'), 'ENG-DD-ISO-FI',       'Isometric - First Issue',                         'PIP', 1),
    (@teal_ver_id, (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PIP'), 'ENG-DD-ISO-REV',      'Isometric - Revision',                            'PIP', 1),
    (@teal_ver_id, (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.MOD'), 'ENG-DD-3DMDL-FI',    '3D Model - First Issue',                          'MOD', 1),
    (@teal_ver_id, (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.MOD'), 'ENG-DD-3DMDL-REV',   '3D Model - Revision',                             'MOD', 1),
    (@teal_ver_id, NULL,                                                                                           'ENG-DD-CALC-FI',     'Calculation - First Issue',                        NULL, 1),
    (@teal_ver_id, NULL,                                                                                           'ENG-DD-CALC-REV',    'Calculation - Revision',                           NULL, 1),
    (@teal_ver_id, NULL,                                                                                           'ENG-DD-SPEC-FI',     'Specification - First Issue',                      NULL, 1),
    (@teal_ver_id, NULL,                                                                                           'ENG-DD-SPEC-REV',    'Specification - Revision',                         NULL, 1),
    (@teal_ver_id, NULL,                                                                                           'ENG-DD-DS-FI',       'Datasheet - First Issue',                          NULL, 1),
    (@teal_ver_id, NULL,                                                                                           'ENG-DD-DS-REV',      'Datasheet - Revision',                             NULL, 1),
    (@teal_ver_id, NULL,                                                                                           'ENG-DD-MR-FI',       'Material Requisition (MR) - First Issue',          NULL, 1),
    (@teal_ver_id, NULL,                                                                                           'ENG-DD-MR-REV',      'Material Requisition (MR) - Revision',             NULL, 1),
    -- Review & Coordination
    (@teal_ver_id, NULL, 'ENG-RC-VDR',      'Vendor Data Review',                          NULL, 1),
    (@teal_ver_id, NULL, 'ENG-RC-CCR',      'Client Comment Response',                     NULL, 1),
    (@teal_ver_id, NULL, 'ENG-RC-IDC',      'IDC Coordination',                            NULL, 1),
    (@teal_ver_id, NULL, 'ENG-RC-IDA',      'Inter-discipline Alignment',                  NULL, 1),
    (@teal_ver_id, NULL, 'ENG-RC-TCL',      'Technical Clarification',                     NULL, 1),
    (@teal_ver_id, NULL, 'ENG-RC-EIP',      'Engineering Input to Procurement',            NULL, 1),
    (@teal_ver_id, NULL, 'ENG-RC-WCU',      'Weight Control Update',                       NULL, 1),
    (@teal_ver_id, NULL, 'ENG-RC-GEN',      'Review & Coordination - General',             NULL, 1),
    -- Change Management
    (@teal_ver_id, NULL, 'ENG-CM-CIA',      'Change Impact Assessment',                    NULL, 1),
    (@teal_ver_id, NULL, 'ENG-CM-RDW',      'Redesign / Rework',                           NULL, 1),
    (@teal_ver_id, NULL, 'ENG-CM-ABU',      'As-built Update',                             NULL, 1),
    (@teal_ver_id, NULL, 'ENG-CM-CNP',      'Change Note Preparation',                     NULL, 1),
    -- EPCI Engineering - Basis of Design (from EPCI sheet)
    (@teal_ver_id, NULL, 'EPCI-ENG-BOD-FI',  'Basis of Design / Design Inputs - First Issue', NULL, 1),
    (@teal_ver_id, NULL, 'EPCI-ENG-BOD-REV', 'Basis of Design / Design Inputs - Revision',    NULL, 1),
    (@teal_ver_id, NULL, 'EPCI-ENG-CTR-FI',  'Calculation & Technical Reports - First Issue',  NULL, 1),
    (@teal_ver_id, NULL, 'EPCI-ENG-CTR-REV', 'Calculation & Technical Reports - Revision',     NULL, 1),
    (@teal_ver_id, NULL, 'EPCI-ENG-DWG-FI',  'Drawings - First Issue',                         NULL, 1),
    (@teal_ver_id, NULL, 'EPCI-ENG-DWG-REV', 'Drawings - Revision',                            NULL, 1),
    (@teal_ver_id, NULL, 'EPCI-ENG-LST-FI',  'Lists / Schedules / Indexes - First Issue',      NULL, 1),
    (@teal_ver_id, NULL, 'EPCI-ENG-LST-REV', 'Lists / Schedules / Indexes - Revision',         NULL, 1),
    (@teal_ver_id, NULL, 'EPCI-ENG-MRM-FI',  'Material & Requisition Management - First Issue', NULL, 1),
    (@teal_ver_id, NULL, 'EPCI-ENG-MRM-REV', 'Material & Requisition Management - Revision',    NULL, 1),
    (@teal_ver_id, NULL, 'EPCI-ENG-3DM',     '3D Modeling',                                     NULL, 1),
    (@teal_ver_id, NULL, 'EPCI-ENG-3DM-REV', '3D Modeling - Revision',                          NULL, 1),
    -- EPCI Engineering Non-deliverable
    (@teal_ver_id, NULL, 'EPCI-ENG-ND-PDS',  'Preliminary Design / Study Work',                 NULL, 1),
    (@teal_ver_id, NULL, 'EPCI-ENG-ND-MCP',  'Model / Calculation Preparation',                 NULL, 1),
    (@teal_ver_id, NULL, 'EPCI-ENG-ND-ITR',  'Internal Technical Review',                       NULL, 1),
    (@teal_ver_id, NULL, 'EPCI-ENG-ND-CDA',  'Cross-discipline Alignment',                      NULL, 1),
    (@teal_ver_id, NULL, 'EPCI-ENG-ND-TCI',  'Technical Clarification (Internal)',               NULL, 1),
    -- EPCI Engineering Support/Admin
    (@teal_ver_id, NULL, 'EPCI-ENG-SA-MTG',  'Engineering Meetings',                             NULL, 1),
    (@teal_ver_id, NULL, 'EPCI-ENG-SA-TDM',  'Tool/Data Maintenance',                            NULL, 1),
    (@teal_ver_id, NULL, 'EPCI-ENG-SA-RPT',  'Engineering Reporting',                             NULL, 1),
    (@teal_ver_id, NULL, 'EPCI-ENG-SA-DFT',  'Drafting Support',                                  NULL, 1),
    (@teal_ver_id, NULL, 'EPCI-ENG-SA-GEN',  'Engineering - General',                             NULL, 1),
    -- SCM Activities (from Master Activity Dictionary)
    (@teal_ver_id, NULL, 'SCM-SB-VPQ',  'Vendor Pre-qualification',           NULL, 1),
    (@teal_ver_id, NULL, 'SCM-SB-RFQ',  'RFQ Issuance',                       NULL, 1),
    (@teal_ver_id, NULL, 'SCM-SB-TBE',  'Technical Bid Evaluation',           NULL, 1),
    (@teal_ver_id, NULL, 'SCM-SB-CBE',  'Commercial Bid Evaluation',          NULL, 1),
    (@teal_ver_id, NULL, 'SCM-PO-DFT',  'PO Drafting',                        NULL, 1),
    (@teal_ver_id, NULL, 'SCM-PO-ISS',  'PO Issuance',                        NULL, 1),
    (@teal_ver_id, NULL, 'SCM-PO-AMD',  'PO Amendment',                       NULL, 1),
    (@teal_ver_id, NULL, 'SCM-VE-DOC',  'Vendor Document Expediting',         NULL, 1),
    (@teal_ver_id, NULL, 'SCM-VE-PSM',  'Production Schedule Monitoring',     NULL, 1),
    (@teal_ver_id, NULL, 'SCM-VE-FAT',  'FAT Coordination',                   NULL, 1),
    (@teal_ver_id, NULL, 'SCM-VE-LOG',  'Logistics Coordination',             NULL, 1),
    -- PMT Activities (from Master Activity Dictionary)
    (@teal_ver_id, NULL, 'PMT-PB-EPU',  'Execution Plan Update',              NULL, 1),
    (@teal_ver_id, NULL, 'PMT-PB-WBS',  'WBS/PBS/MBS Alignment',              NULL, 1),
    (@teal_ver_id, NULL, 'PMT-PB-BSD',  'Baseline Schedule Development',      NULL, 1),
    (@teal_ver_id, NULL, 'PMT-SC-WSU',  'Weekly Schedule Update',             NULL, 1),
    (@teal_ver_id, NULL, 'PMT-SC-PM',   'Progress Measurement',               NULL, 1),
    (@teal_ver_id, NULL, 'PMT-SC-EVA',  'EV Analysis',                        NULL, 1),
    (@teal_ver_id, NULL, 'PMT-CC-CBD',  'Cost Baseline Development',          NULL, 1),
    (@teal_ver_id, NULL, 'PMT-CC-CRP',  'Cost Reporting',                     NULL, 1),
    (@teal_ver_id, NULL, 'PMT-CC-FCU',  'Forecast Update',                    NULL, 1),
    (@teal_ver_id, NULL, 'PMT-CV-CID',  'Change Identification',              NULL, 1),
    (@teal_ver_id, NULL, 'PMT-CV-VOC',  'VOC Log Management',                 NULL, 1),
    (@teal_ver_id, NULL, 'PMT-RS-RRD',  'Risk Register Development',          NULL, 1),
    (@teal_ver_id, NULL, 'PMT-RS-RWS',  'Risk Workshop',                      NULL, 1),
    (@teal_ver_id, NULL, 'PMT-DI-DCO',  'Document Control Oversight',         NULL, 1),
    (@teal_ver_id, NULL, 'PMT-DI-TMT',  'Transmittal Management',             NULL, 1),
    (@teal_ver_id, NULL, 'PMT-RP-WRP',  'Weekly Report',                      NULL, 1),
    (@teal_ver_id, NULL, 'PMT-RP-MRP',  'Monthly Report',                     NULL, 1),
    (@teal_ver_id, NULL, 'PMT-GC-GRV',  'Gate Review Prep',                   NULL, 1),
    (@teal_ver_id, NULL, 'PMT-GC-AUD',  'Audit Preparation',                  NULL, 1),
    (@teal_ver_id, NULL, 'PMT-TC-MTG',  'PMT Meeting Coordination',           NULL, 1),
    (@teal_ver_id, NULL, 'PMT-TC-DSC',  'Discipline Coordination',            NULL, 1),
    -- Construction Activities
    (@teal_ver_id, NULL, 'CON-YS-FPR',  'Fabrication Progress Review',        NULL, 1),
    (@teal_ver_id, NULL, 'CON-YS-IPV',  'Installation Progress Validation',   NULL, 1),
    (@teal_ver_id, NULL, 'CON-SS-WKD',  'Site Walkdown',                      NULL, 1),
    (@teal_ver_id, NULL, 'CON-SS-VIW',  'Verification of Installed Work',     NULL, 1),
    (@teal_ver_id, NULL, 'CON-IN-NCR',  'NCR Tracking',                       NULL, 1),
    (@teal_ver_id, NULL, 'CON-IN-ESC',  'Issue Escalation',                   NULL, 1),
    -- QA/QC Activities
    (@teal_ver_id, NULL, 'QA-QAS-ITP',  'ITP Review',                         NULL, 1),
    (@teal_ver_id, NULL, 'QA-QAS-QDR',  'QA Document Review',                 NULL, 1),
    (@teal_ver_id, NULL, 'QA-QCS-FAT',  'FAT Witnessing',                     NULL, 1),
    (@teal_ver_id, NULL, 'QA-QCS-INW',  'Inspection Witnessing',              NULL, 1),
    -- HSSE Activities
    (@teal_ver_id, NULL, 'HSE-OVS-INS', 'HSE Inspection',                     NULL, 1),
    (@teal_ver_id, NULL, 'HSE-OVS-KPI', 'HSE KPI Review',                     NULL, 1),
    (@teal_ver_id, NULL, 'HSE-CI-INC',  'Incident Investigation',             NULL, 1),
    -- Commissioning Activities
    (@teal_ver_id, NULL, 'COM-PCO-PLN', 'Pre-comm Plan Review',               NULL, 1),
    (@teal_ver_id, NULL, 'COM-PCO-LPC', 'Loop Check Monitoring',              NULL, 1),
    -- Tender Activities (from EPCI-Support-Comm sheet)
    (@teal_ver_id, NULL, 'TND-MS-ITT',  'ITT Review & Scope Breakdown',                    NULL, 1),
    (@teal_ver_id, NULL, 'TND-MS-CLR',  'Clarification Question Preparation',              NULL, 1),
    (@teal_ver_id, NULL, 'TND-MS-TES',  'Tender Execution Strategy',                       NULL, 1),
    (@teal_ver_id, NULL, 'TND-MS-WTA',  'Win Theme & Competitor Analysis',                 NULL, 1),
    (@teal_ver_id, NULL, 'TND-MS-TPC',  'Technical Proposal Consolidation',                NULL, 1),
    (@teal_ver_id, NULL, 'TND-MS-CPC',  'Commercial Proposal Consolidation',               NULL, 1),
    (@teal_ver_id, NULL, 'TND-MS-GRP',  'Gate Review Preparation',                         NULL, 1),
    (@teal_ver_id, NULL, 'TND-MS-FPS',  'Final Proposal Submission',                       NULL, 1),
    (@teal_ver_id, NULL, 'TND-ENG-TSF', 'Technical Scope Framing',                         NULL, 1),
    (@teal_ver_id, NULL, 'TND-ENG-TDB', 'Tender Design Basis',                             NULL, 1),
    (@teal_ver_id, NULL, 'TND-ENG-PDD', 'Preliminary Design Development (Tender)',         NULL, 1),
    (@teal_ver_id, NULL, 'TND-ENG-MTO', 'Tender MTO / Load/Line List',                     NULL, 1),
    (@teal_ver_id, NULL, 'TND-PMT-PEP', 'Project Overall Execution Planning',              NULL, 1),
    (@teal_ver_id, NULL, 'TND-PMT-PSD', 'Project Schedule Development',                    NULL, 1),
    (@teal_ver_id, NULL, 'TND-PMT-MPP', 'Manpower Planning',                               NULL, 1),
    -- Pre-FEED Activities (from EPCI-Support-Comm sheet)
    (@teal_ver_id, NULL, 'PFD-ENG-COI', 'Concept Option Identification',                   NULL, 1),
    (@teal_ver_id, NULL, 'PFD-ENG-DCS', 'Design Concept Selection',                        NULL, 1),
    (@teal_ver_id, NULL, 'PFD-ENG-TSC', 'Technology Screening',                            NULL, 1),
    (@teal_ver_id, NULL, 'PFD-ENG-DBD', 'Design Basis Development (Concept Level)',        NULL, 1),
    (@teal_ver_id, NULL, 'PFD-ENG-HPC', 'High-level Process Calculation',                  NULL, 1),
    (@teal_ver_id, NULL, 'PFD-ENG-HMB', 'Approximate Heat/Material Balance',               NULL, 1),
    (@teal_ver_id, NULL, 'PFD-ENG-PSC', 'Preliminary Sizing Calculation',                  NULL, 1),
    (@teal_ver_id, NULL, 'PFD-ENG-CBD', 'Concept Layout / Block Diagram',                  NULL, 1),
    (@teal_ver_id, NULL, 'PFD-ENG-HPF', 'High-level PFD',                                  NULL, 1),
    (@teal_ver_id, NULL, 'PFD-ENG-UPI', 'Ultra-simplified P&ID (U-P&ID)',                  NULL, 1),
    (@teal_ver_id, NULL, 'PFD-ENG-FST', 'Feasibility Study',                               NULL, 1),
    (@teal_ver_id, NULL, 'PFD-ENG-CSR', 'Concept Selection Report',                        NULL, 1),
    -- FEED Activities (from EPCI-Support-Comm sheet)
    (@teal_ver_id, NULL, 'FED-ENG-DBU', 'Design Basis Update (FEED Level)',                NULL, 1),
    (@teal_ver_id, NULL, 'FED-ENG-PDD', 'Philosophy Document Development',                 NULL, 1),
    (@teal_ver_id, NULL, 'FED-ENG-PCR', 'Process Calculation (Refined)',                   NULL, 1),
    (@teal_ver_id, NULL, 'FED-ENG-HYC', 'Hydraulic Calculation',                           NULL, 1),
    (@teal_ver_id, NULL, 'FED-ENG-PSA', 'Preliminary Stress/Structural Analysis',         NULL, 1),
    (@teal_ver_id, NULL, 'FED-ENG-ELA', 'Electrical Load Analysis',                        NULL, 1),
    (@teal_ver_id, NULL, 'FED-ENG-FGA', 'FEED-level Layout (GA)',                          NULL, 1),
    (@teal_ver_id, NULL, 'FED-ENG-FPF', 'FEED PFD',                                        NULL, 1),
    (@teal_ver_id, NULL, 'FED-ENG-FPI', 'FEED P&ID',                                       NULL, 1),
    (@teal_ver_id, NULL, 'FED-ENG-SLD', 'SLD (Preliminary)',                               NULL, 1),
    (@teal_ver_id, NULL, 'FED-ENG-DSD', 'Datasheet Development',                           NULL, 1),
    (@teal_ver_id, NULL, 'FED-ENG-TSP', 'Technical Specification Draft',                   NULL, 1),
    (@teal_ver_id, NULL, 'FED-ENG-HAZ', 'HAZID/ENVID Support',                             NULL, 1),
    (@teal_ver_id, NULL, 'FED-ENG-WER', 'Weight Estimation (Refined)',                     NULL, 1),
    -- Support Core Work (from EPCI-Support-Comm sheet row 166+)
    (@teal_ver_id, NULL, 'SUP-BD-CMA',  'Client Management & Market Analysis',             NULL, 1),
    (@teal_ver_id, NULL, 'SUP-PM-CPR',  'Corporate Planning/Reporting',                    NULL, 1),
    (@teal_ver_id, NULL, 'SUP-HR-RCO',  'Recruitment & Onboarding',                        NULL, 1),
    (@teal_ver_id, NULL, 'SUP-HR-TNP',  'Training & Performance',                          NULL, 1),
    (@teal_ver_id, NULL, 'SUP-LG-CTR',  'Contract Review',                                 NULL, 1),
    (@teal_ver_id, NULL, 'SUP-TC-TDE',  'Tech Development & Evaluation',                   NULL, 1),
    (@teal_ver_id, NULL, 'SUP-GPO-STD', 'PMT Governance & Standards',                      NULL, 1),
    -- Common Work (from EPCI-Support-Comm sheet row 176+)
    (@teal_ver_id, NULL, 'CMN-ADM-GEN', 'General Admin/Document Management',               NULL, 1),
    (@teal_ver_id, NULL, 'CMN-MTG-ICO', 'Internal Coordination',                           NULL, 1),
    (@teal_ver_id, NULL, 'CMN-TRN-MCT', 'Mandatory/Compliance Training',                   NULL, 1),
    (@teal_ver_id, NULL, 'CMN-PI-WTU',  'Workflow/Template Updates',                        NULL, 1),
    (@teal_ver_id, NULL, 'CMN-STR-KBS', 'KPI/Budget/Strategy Workshop',                    NULL, 1),
    (@teal_ver_id, NULL, 'CMN-PPL-MPC', 'Mentoring/Performance Cycle',                     NULL, 1),
    (@teal_ver_id, NULL, 'CMN-EVT-TWC', 'Townhall/Workshops/CSR',                          NULL, 1);

-- ============================================================
-- 8. ADDITIONAL OVERHEAD TYPES (from Activity.xlsx Non-Project)
-- ============================================================
INSERT IGNORE INTO overhead_types (code, name, category, sort_order) VALUES
    ('SYS_PROC_DEV', 'System & Process Development',     'DEVELOPMENT', 15),
    ('ORG_OPS',      'Organizational Operation',          'ADMIN',       16),
    ('CORP_INIT',    'Corporate Initiative/Strategy',     'CORPORATE',   17),
    ('MENTORING',    'Mentoring & Coaching',              'PEOPLE',      18),
    ('TECH_DEV',     'Technology Development',            'DEVELOPMENT', 19),
    ('RECRUITMENT',  'Recruitment & Onboarding',          'HR',          20),
    ('PERF_MGMT',    'Performance Management',            'HR',          21);

-- ============================================================
-- 9. WORK RULES
-- ============================================================
INSERT IGNORE INTO work_rules (location, min_daily_hours, max_daily_hours, max_weekly_hours, is_active) VALUES
    ('ONSHORE',  8.00, 12.00, 52.00, 1),
    ('OFFSHORE', 10.00, 12.00, 60.00, 1),
    ('REMOTE',   8.00, 10.00, 48.00, 1);

-- ============================================================
-- 10. SAMPLE TIMESHEETS (2 weeks for 2 users)
-- ============================================================
-- Week 1: 2026-03-16 ~ 2026-03-22 for EMP008 (Ryan Seo, Senior Process Engineer)
INSERT IGNORE INTO timesheets (user_id, week_start_date, week_end_date, status, total_hours, submitted_at)
SELECT u.id, '2026-03-16', '2026-03-22', 'APPROVED', 44.00, '2026-03-22 17:00:00'
FROM users u WHERE u.employee_id = 'EMP008';

-- Week 1: 2026-03-16 ~ 2026-03-22 for EMP009 (Anna Kwon, Piping Engineer)
INSERT IGNORE INTO timesheets (user_id, week_start_date, week_end_date, status, total_hours, submitted_at)
SELECT u.id, '2026-03-16', '2026-03-22', 'SUBMITTED', 42.00, '2026-03-22 17:30:00'
FROM users u WHERE u.employee_id = 'EMP009';

-- Week 2: 2026-03-23 ~ 2026-03-29 for EMP008
INSERT IGNORE INTO timesheets (user_id, week_start_date, week_end_date, status, total_hours, submitted_at)
SELECT u.id, '2026-03-23', '2026-03-29', 'DRAFT', 24.00, NULL
FROM users u WHERE u.employee_id = 'EMP008';

-- Week 2: 2026-03-23 ~ 2026-03-29 for EMP009
INSERT IGNORE INTO timesheets (user_id, week_start_date, week_end_date, status, total_hours, submitted_at)
SELECT u.id, '2026-03-23', '2026-03-29', 'DRAFT', 16.00, NULL
FROM users u WHERE u.employee_id = 'EMP009';

-- Timesheet Entries for EMP008 Week 1 (Process engineer working on P&ID and PFD)
-- Monday 2026-03-16
INSERT IGNORE INTO timesheet_entries (timesheet_id, entry_type, entry_date, hours, epc_project_id, canonical_wbs_id, teal_entry_id, remark)
SELECT ts.id, 'EPC', '2026-03-16', 8.00, @proj_id,
    (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PRO'),
    (SELECT id FROM teal_entries WHERE teal_version_id = @teal_ver_id AND activity_code = 'ENG-DD-PID-FI'),
    'P&ID development for Module 1 separation system'
FROM timesheets ts JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP008' AND ts.week_start_date = '2026-03-16';

-- Tuesday 2026-03-17
INSERT IGNORE INTO timesheet_entries (timesheet_id, entry_type, entry_date, hours, epc_project_id, canonical_wbs_id, teal_entry_id, remark)
SELECT ts.id, 'EPC', '2026-03-17', 6.00, @proj_id,
    (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PRO'),
    (SELECT id FROM teal_entries WHERE teal_version_id = @teal_ver_id AND activity_code = 'ENG-DD-PID-FI'),
    'P&ID development continued'
FROM timesheets ts JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP008' AND ts.week_start_date = '2026-03-16';

INSERT IGNORE INTO timesheet_entries (timesheet_id, entry_type, entry_date, hours, np_category, remark)
SELECT ts.id, 'NP', '2026-03-17', 2.00, 'TRAINING', 'Process simulation software training'
FROM timesheets ts JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP008' AND ts.week_start_date = '2026-03-16';

-- Wednesday 2026-03-18
INSERT IGNORE INTO timesheet_entries (timesheet_id, entry_type, entry_date, hours, epc_project_id, canonical_wbs_id, teal_entry_id, remark)
SELECT ts.id, 'EPC', '2026-03-18', 8.00, @proj_id,
    (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PRO'),
    (SELECT id FROM teal_entries WHERE teal_version_id = @teal_ver_id AND activity_code = 'ENG-RC-IDC'),
    'IDC review session with Piping and Instrument'
FROM timesheets ts JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP008' AND ts.week_start_date = '2026-03-16';

-- Thursday 2026-03-19
INSERT IGNORE INTO timesheet_entries (timesheet_id, entry_type, entry_date, hours, epc_project_id, canonical_wbs_id, teal_entry_id, remark)
SELECT ts.id, 'EPC', '2026-03-19', 10.00, @proj_id,
    (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PRO'),
    (SELECT id FROM teal_entries WHERE teal_version_id = @teal_ver_id AND activity_code = 'ENG-DD-LAYOUT-FI'),
    'Layout development for compression module'
FROM timesheets ts JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP008' AND ts.week_start_date = '2026-03-16';

-- Friday 2026-03-20
INSERT IGNORE INTO timesheet_entries (timesheet_id, entry_type, entry_date, hours, epc_project_id, canonical_wbs_id, teal_entry_id, remark)
SELECT ts.id, 'EPC', '2026-03-20', 8.00, @proj_id,
    (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PRO'),
    (SELECT id FROM teal_entries WHERE teal_version_id = @teal_ver_id AND activity_code = 'ENG-RC-VDR'),
    'Vendor data review for heat exchangers'
FROM timesheets ts JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP008' AND ts.week_start_date = '2026-03-16';

-- Saturday 2026-03-21
INSERT IGNORE INTO timesheet_entries (timesheet_id, entry_type, entry_date, hours, epc_project_id, canonical_wbs_id, teal_entry_id, remark)
SELECT ts.id, 'EPC', '2026-03-21', 2.00, @proj_id,
    (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PRO'),
    (SELECT id FROM teal_entries WHERE teal_version_id = @teal_ver_id AND activity_code = 'ENG-DD-PID-REV'),
    'P&ID revision for client comments'
FROM timesheets ts JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP008' AND ts.week_start_date = '2026-03-16';

-- Timesheet Entries for EMP009 Week 1 (Piping engineer)
-- Monday 2026-03-16
INSERT IGNORE INTO timesheet_entries (timesheet_id, entry_type, entry_date, hours, epc_project_id, canonical_wbs_id, teal_entry_id, remark)
SELECT ts.id, 'EPC', '2026-03-16', 8.00, @proj_id,
    (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PIP'),
    (SELECT id FROM teal_entries WHERE teal_version_id = @teal_ver_id AND activity_code = 'ENG-DD-ISO-FI'),
    'Isometric drawing for Module 1 piping'
FROM timesheets ts JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP009' AND ts.week_start_date = '2026-03-16';

-- Tuesday 2026-03-17
INSERT IGNORE INTO timesheet_entries (timesheet_id, entry_type, entry_date, hours, epc_project_id, canonical_wbs_id, teal_entry_id, remark)
SELECT ts.id, 'EPC', '2026-03-17', 8.00, @proj_id,
    (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PIP'),
    (SELECT id FROM teal_entries WHERE teal_version_id = @teal_ver_id AND activity_code = 'ENG-DD-ISO-FI'),
    'Isometric drawing continued - critical lines'
FROM timesheets ts JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP009' AND ts.week_start_date = '2026-03-16';

-- Wednesday 2026-03-18
INSERT IGNORE INTO timesheet_entries (timesheet_id, entry_type, entry_date, hours, epc_project_id, canonical_wbs_id, teal_entry_id, remark)
SELECT ts.id, 'EPC', '2026-03-18', 6.00, @proj_id,
    (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PIP'),
    (SELECT id FROM teal_entries WHERE teal_version_id = @teal_ver_id AND activity_code = 'EPCI-ENG-ND-CDA'),
    'Cross-discipline alignment with Structural'
FROM timesheets ts JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP009' AND ts.week_start_date = '2026-03-16';

INSERT IGNORE INTO timesheet_entries (timesheet_id, entry_type, entry_date, hours, np_category, remark)
SELECT ts.id, 'NP', '2026-03-18', 2.00, 'MEETING', 'Department weekly meeting'
FROM timesheets ts JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP009' AND ts.week_start_date = '2026-03-16';

-- Thursday 2026-03-19
INSERT IGNORE INTO timesheet_entries (timesheet_id, entry_type, entry_date, hours, epc_project_id, canonical_wbs_id, teal_entry_id, remark)
SELECT ts.id, 'EPC', '2026-03-19', 10.00, @proj_id,
    (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PIP'),
    (SELECT id FROM teal_entries WHERE teal_version_id = @teal_ver_id AND activity_code = 'ENG-DD-ISO-FI'),
    'Isometric drawings - overtime for deadline'
FROM timesheets ts JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP009' AND ts.week_start_date = '2026-03-16';

-- Friday 2026-03-20
INSERT IGNORE INTO timesheet_entries (timesheet_id, entry_type, entry_date, hours, epc_project_id, canonical_wbs_id, teal_entry_id, remark)
SELECT ts.id, 'EPC', '2026-03-20', 8.00, @proj_id,
    (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PIP'),
    (SELECT id FROM teal_entries WHERE teal_version_id = @teal_ver_id AND activity_code = 'ENG-RC-VDR'),
    'Vendor data review for pipe fittings'
FROM timesheets ts JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP009' AND ts.week_start_date = '2026-03-16';

-- EMP008 Week 2 entries (partial - DRAFT)
INSERT IGNORE INTO timesheet_entries (timesheet_id, entry_type, entry_date, hours, epc_project_id, canonical_wbs_id, teal_entry_id, remark)
SELECT ts.id, 'EPC', '2026-03-23', 8.00, @proj_id,
    (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PRO'),
    (SELECT id FROM teal_entries WHERE teal_version_id = @teal_ver_id AND activity_code = 'ENG-DD-PID-REV'),
    'P&ID revision B incorporating vendor data'
FROM timesheets ts JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP008' AND ts.week_start_date = '2026-03-23';

INSERT IGNORE INTO timesheet_entries (timesheet_id, entry_type, entry_date, hours, epc_project_id, canonical_wbs_id, teal_entry_id, remark)
SELECT ts.id, 'EPC', '2026-03-24', 8.00, @proj_id,
    (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PRO'),
    (SELECT id FROM teal_entries WHERE teal_version_id = @teal_ver_id AND activity_code = 'EPCI-ENG-CTR-FI'),
    'Process calculation report for compressor sizing'
FROM timesheets ts JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP008' AND ts.week_start_date = '2026-03-23';

INSERT IGNORE INTO timesheet_entries (timesheet_id, entry_type, entry_date, hours, epc_project_id, canonical_wbs_id, teal_entry_id, remark)
SELECT ts.id, 'EPC', '2026-03-25', 8.00, @proj_id,
    (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PRO'),
    (SELECT id FROM teal_entries WHERE teal_version_id = @teal_ver_id AND activity_code = 'ENG-RC-CCR'),
    'Client comment response for PFD package'
FROM timesheets ts JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP008' AND ts.week_start_date = '2026-03-23';

-- EMP009 Week 2 entries (partial - DRAFT)
INSERT IGNORE INTO timesheet_entries (timesheet_id, entry_type, entry_date, hours, epc_project_id, canonical_wbs_id, teal_entry_id, remark)
SELECT ts.id, 'EPC', '2026-03-23', 8.00, @proj_id,
    (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PIP'),
    (SELECT id FROM teal_entries WHERE teal_version_id = @teal_ver_id AND activity_code = 'ENG-DD-ISO-REV'),
    'Isometric revision for stress analysis updates'
FROM timesheets ts JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP009' AND ts.week_start_date = '2026-03-23';

INSERT IGNORE INTO timesheet_entries (timesheet_id, entry_type, entry_date, hours, epc_project_id, canonical_wbs_id, teal_entry_id, remark)
SELECT ts.id, 'EPC', '2026-03-24', 8.00, @proj_id,
    (SELECT id FROM canonical_wbs WHERE project_id = @proj_id AND wbs_code = 'F0001.ENGR.TP.PIP'),
    (SELECT id FROM teal_entries WHERE teal_version_id = @teal_ver_id AND activity_code = 'ENG-RC-EIP'),
    'Engineering input for pipe procurement MR'
FROM timesheets ts JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP009' AND ts.week_start_date = '2026-03-23';

-- ============================================================
-- 11. SAMPLE APPROVALS (1 approved, 1 pending)
-- ============================================================
-- Approved: EMP008 Week 1
INSERT IGNORE INTO approvals (timesheet_id, requester_id, project_id, status, submitted_at, completed_at)
SELECT ts.id, u.id, @proj_id, 'APPROVED', '2026-03-22 17:00:00', '2026-03-23 10:30:00'
FROM timesheets ts JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP008' AND ts.week_start_date = '2026-03-16';

-- Approval lines for EMP008 Week 1 (DL -> PCM -> PM)
INSERT IGNORE INTO approval_lines (approval_id, approver_id, approval_order, role_code, status, acted_at)
SELECT a.id, (SELECT id FROM users WHERE employee_id = 'EMP005'), 1, 'DL', 'APPROVED', '2026-03-22 18:00:00'
FROM approvals a JOIN timesheets ts ON a.timesheet_id = ts.id JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP008' AND ts.week_start_date = '2026-03-16';

INSERT IGNORE INTO approval_lines (approval_id, approver_id, approval_order, role_code, status, acted_at)
SELECT a.id, (SELECT id FROM users WHERE employee_id = 'EMP002'), 2, 'PCM', 'APPROVED', '2026-03-23 09:00:00'
FROM approvals a JOIN timesheets ts ON a.timesheet_id = ts.id JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP008' AND ts.week_start_date = '2026-03-16';

INSERT IGNORE INTO approval_lines (approval_id, approver_id, approval_order, role_code, status, acted_at)
SELECT a.id, (SELECT id FROM users WHERE employee_id = 'EMP001'), 3, 'PM', 'APPROVED', '2026-03-23 10:30:00'
FROM approvals a JOIN timesheets ts ON a.timesheet_id = ts.id JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP008' AND ts.week_start_date = '2026-03-16';

-- Approval comment
INSERT IGNORE INTO approval_comments (approval_id, user_id, comment, action)
SELECT a.id, (SELECT id FROM users WHERE employee_id = 'EMP005'), 'Timesheet verified. OT on Thursday approved per project need.', 'APPROVE'
FROM approvals a JOIN timesheets ts ON a.timesheet_id = ts.id JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP008' AND ts.week_start_date = '2026-03-16';

-- Pending: EMP009 Week 1
INSERT IGNORE INTO approvals (timesheet_id, requester_id, project_id, status, submitted_at)
SELECT ts.id, u.id, @proj_id, 'PENDING', '2026-03-22 17:30:00'
FROM timesheets ts JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP009' AND ts.week_start_date = '2026-03-16';

-- Approval lines for EMP009 Week 1 (DL pending)
INSERT IGNORE INTO approval_lines (approval_id, approver_id, approval_order, role_code, status)
SELECT a.id, (SELECT id FROM users WHERE employee_id = 'EMP004'), 1, 'DL', 'PENDING'
FROM approvals a JOIN timesheets ts ON a.timesheet_id = ts.id JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP009' AND ts.week_start_date = '2026-03-16';

INSERT IGNORE INTO approval_lines (approval_id, approver_id, approval_order, role_code, status)
SELECT a.id, (SELECT id FROM users WHERE employee_id = 'EMP002'), 2, 'PCM', 'PENDING'
FROM approvals a JOIN timesheets ts ON a.timesheet_id = ts.id JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP009' AND ts.week_start_date = '2026-03-16';

INSERT IGNORE INTO approval_lines (approval_id, approver_id, approval_order, role_code, status)
SELECT a.id, (SELECT id FROM users WHERE employee_id = 'EMP001'), 3, 'PM', 'PENDING'
FROM approvals a JOIN timesheets ts ON a.timesheet_id = ts.id JOIN users u ON ts.user_id = u.id
WHERE u.employee_id = 'EMP009' AND ts.week_start_date = '2026-03-16';

-- ============================================================
-- 12. PROJECT TYPE CONFIG (EPC defaults)
-- ============================================================
INSERT IGNORE INTO project_type_config (project_type, config_key, config_value, description) VALUES
    ('EPC',  'approval_chain',     'DL,PCM,PM',    'Default approval chain for EPC projects'),
    ('EPC',  'max_weekly_hours',   '52',            'Maximum weekly hours for EPC projects'),
    ('EPC',  'timesheet_period',   'WEEKLY',        'Timesheet submission period'),
    ('EPC',  'overtime_threshold', '8',             'Daily hours threshold for OT calculation'),
    ('FEED', 'approval_chain',     'DL,PM',         'Default approval chain for FEED projects'),
    ('FEED', 'max_weekly_hours',   '48',            'Maximum weekly hours for FEED projects'),
    ('FEED', 'timesheet_period',   'WEEKLY',        'Timesheet submission period');
