-- Slice 8b-4a · Seed SERVICE_REQUISITION_APPROVAL chain (PC → PM → FM → Exec)
INSERT INTO fin_chain_defs (chain_key, title, description, status, created_by, created_on)
SELECT 'SERVICE_REQUISITION_APPROVAL', 'Service Requisition approval', 'PC drafts, PM/FM/Exec approve before cash issue', 'ACTIVE', 0, NOW()
WHERE NOT EXISTS (SELECT 1 FROM fin_chain_defs WHERE chain_key = 'SERVICE_REQUISITION_APPROVAL');

SET @srChainId := (SELECT c0d FROM fin_chain_defs WHERE chain_key = 'SERVICE_REQUISITION_APPROVAL');

INSERT INTO fin_chain_steps (chain_id, step_no, step_key, step_label, role_required, is_terminal, sort_order, created_on)
SELECT @srChainId, s.no, s.k, s.lbl, s.rr, s.term, s.so, NOW()
FROM (
    SELECT 1 no, 'PC_REVIEW'    k, 'PC review (originator)'         lbl, 'PROJECTS COORDINATOR' rr, 0 term, 10 so UNION ALL
    SELECT 2,   'PM_VERIFY',        'PM verifies operational need',    'PROJECT MANAGER',          0,      20         UNION ALL
    SELECT 3,   'FM_VERIFY',        'FM verifies affordability',       'FINANCE MANAGER',          0,      30         UNION ALL
    SELECT 4,   'EXEC_APPROVE',     'Executive authorises cash issue', 'EXECUTIVE',                1,      40
) s
WHERE NOT EXISTS (
    SELECT 1 FROM fin_chain_steps WHERE chain_id = @srChainId AND step_key = s.k
);
