-- =====================================================================
-- ZUSahabat Operation Portal — initial data
-- Run after schema.sql. Replace bank account numbers with the real ones.
-- =====================================================================
BEGIN;

-- Named users from the requirement
INSERT INTO users (name, email, role, access_level) VALUES
  ('Syafiqah',  'fatin.syafiqah@asgb.com.my', 'full_access', 'FULL ACCESS'),
  ('Asyraff',   'asyraaf@asgb.com.my',        'full_access', 'FULL ACCESS'),
  ('Siti',      'siti@asgb.com.my',           'management',  'MANAGEMENT – FULL ACCESS'),
  ('Ng Zhiyan', 'ngzhiyan@asgb.com.my',       'management',  'MANAGEMENT – FULL ACCESS');
-- Other Operation Team and Finance users are added in the portal (Users & Roles), one per company email.

-- Mandatory document checklist (unlocked after location approval)
INSERT INTO document_types (code, name, mandatory, sort_order) VALUES
  ('application_form',   'Application Form', true, 1),
  ('ssm',                'SSM', true, 2),
  ('typhoid',            'Typhoid Certificate', true, 3),
  ('food_handling',      'Food Handling Certificate', true, 4),
  ('repayment_record',   '12-Month Repayment Record', true, 5),
  ('aim_form',           'Signed AIM Application/Supporting Form', true, 6),
  ('fasspay_form',       'Fasspay Form', true, 7),
  ('heydoc',             'Heydoc Documents', true, 8),
  ('allianz',            'Allianz Insurance Documents', true, 9),
  ('agreement',          'Agreement / Letter of Offer', true, 10),
  ('payment_proof',      'Payment Proof', true, 11),
  ('other',              'Other Required Documents', false, 12);

-- Bank accounts (placeholders — replace with real accounts)
INSERT INTO bank_accounts (label, bank, account_no, purpose) VALUES
  ('Settlement',      'Maybank', 'XXXX-XXXX-0091', 'settlement'),
  ('Restock Fund',    'Maybank', 'XXXX-XXXX-0109', 'restock'),
  ('AIM Repayment',   'CIMB',    'XXXX-XXXX-4720', 'repayment');

-- Allocation rule 40:20 (configurable; meaning to be confirmed — see docs/05-open-questions.md)
INSERT INTO allocation_rules (effective_from, remarks) VALUES ('2026-01-01', 'Initial 40:20 structure');
INSERT INTO allocation_rule_buckets (rule_id, bucket_key, bucket_name, percentage, bank_account_id)
SELECT r.id, b.k, b.n, b.p, a.id
FROM allocation_rules r
JOIN (VALUES ('restock','Restock Fund',40.00,'Restock Fund'), ('repayment','Repayment Fund',20.00,'AIM Repayment')) AS b(k,n,p,acct) ON true
JOIN bank_accounts a ON a.label = b.acct
WHERE r.effective_from = '2026-01-01';

-- Starter stock items (prices are examples)
INSERT INTO stock_items (name, unit, unit_price) VALUES
  ('Coffee beans (1kg)', 'pack', 65.00),
  ('Fresh milk (1L)', 'carton', 7.50),
  ('Cups 16oz (50 pcs)', 'sleeve', 18.00),
  ('Caramel syrup (750ml)', 'bottle', 32.00);

COMMIT;
