-- =========================================================
-- Gold Wallet — Seed Data (Arabic + Institutional)
-- =========================================================

-- CUSTOMERS
insert into public.customers (id, customer_code, name, tier, status, kyc_status, primary_contact_name, email, phone, risk_score, two_factor_enabled, linked_devices, last_login_at, last_login_ip, registered_at)
values
  ('11111111-1111-1111-1111-111111111101','GW-8821','Aurelius Capital Mgmt','institutional','active','verified','Marcus Aurelius','m.aurelius@aureliuscap.com','+1 212 555 0198',12,true,3,now() - interval '2 hours', '192.168.1.1', now() - interval '14 months'),
  ('11111111-1111-1111-1111-111111111102','GW-8822','Cressida Wealth','institutional','active','pending','Leila Cressida','ops@cressida.com','+44 20 7946 0958',28,true,2,now() - interval '6 hours', '10.0.0.14', now() - interval '9 months'),
  ('11111111-1111-1111-1111-111111111103','GW-8823','Global Sovereigns Ltd','institutional','active','verified','Kareem Sultan','finance@globalsov.com','+971 4 555 0100',18,true,4,now() - interval '1 day', '172.16.0.5', now() - interval '18 months'),
  ('11111111-1111-1111-1111-111111111104','GW-8824','John Doe','retail','suspended','under_review','John Doe','john.doe@email.com','+1 415 555 0123',72,false,1,now() - interval '4 days', '203.0.113.50', now() - interval '3 months'),
  ('11111111-1111-1111-1111-111111111105','GW-8825','Vanguard Metals','institutional','active','verified','Sonia Patel','desk@vanguardmetals.com','+1 332 555 0177',22,true,3,now() - interval '3 hours', '192.168.5.10', now() - interval '22 months'),
  ('11111111-1111-1111-1111-111111111106','GW-8826','Silverline Partners','premium','active','verified','Amjad Nasser','ops@silverline.co','+962 6 555 0199',30,true,2,now() - interval '8 hours', '10.8.0.33', now() - interval '11 months'),
  ('11111111-1111-1111-1111-111111111107','GW-8827','Apex Reserves','institutional','active','verified','Hiroshi Tanaka','treasury@apexreserves.jp','+81 3 5555 0133',15,true,2,now() - interval '12 hours', '192.168.40.4', now() - interval '20 months'),
  ('11111111-1111-1111-1111-111111111108','GW-8828','Crescent Bullion','premium','active','verified','Fatima Al-Hilal','trading@crescentbullion.ae','+971 2 555 0144',25,true,3,now() - interval '1 day', '10.10.0.7', now() - interval '16 months'),
  ('11111111-1111-1111-1111-111111111109','GW-8829','Osprey Global Macro','institutional','active','verified','Daniel Osprey','pm@ospreygm.com','+1 617 555 0188',20,true,3,now() - interval '4 hours', '192.168.9.2', now() - interval '13 months'),
  ('11111111-1111-1111-1111-111111111110','GW-8830','Apex Institutional','institutional','active','pending','Sarah Jenkins','sarah.j@apexinst.com','+44 20 7946 0900',35,true,2,now() - interval '30 hours', '172.16.2.8', now() - interval '7 months'),
  ('11111111-1111-1111-1111-111111111111','GW-8831','Sarah Jenkins','retail','active','pending','Sarah Jenkins','sarah.jenkins@email.com','+1 206 555 0166',42,false,1,now() - interval '2 days', '203.0.113.77', now() - interval '2 months'),
  ('11111111-1111-1111-1111-111111111112','GW-8832','Michael Chen','retail','active','under_review','Michael Chen','m.chen@email.com','+1 650 555 0122',85,false,1,now() - interval '5 hours', '203.0.113.88', now() - interval '1 month')
on conflict (customer_code) do nothing;

-- CASH WALLETS
insert into public.cash_wallets (wallet_code, customer_id, currency, available_balance, held_balance) values
  ('CW-8821','11111111-1111-1111-1111-111111111101','USD',1250400.00,50000.00),
  ('CW-8822','11111111-1111-1111-1111-111111111102','USD',45000.00,150000.00),
  ('CW-8823','11111111-1111-1111-1111-111111111103','USD',850000.00,0.00),
  ('CW-8824','11111111-1111-1111-1111-111111111104','USD',0.00,5000.00),
  ('CW-8825','11111111-1111-1111-1111-111111111105','USD',2100500.00,12000.00),
  ('CW-8826','11111111-1111-1111-1111-111111111106','USD',380000.00,4500.00),
  ('CW-8827','11111111-1111-1111-1111-111111111107','USD',720000.00,20000.00),
  ('CW-8828','11111111-1111-1111-1111-111111111108','USD',298000.00,1000.00),
  ('CW-8829','11111111-1111-1111-1111-111111111109','USD',1125000.00,8000.00),
  ('CW-8830','11111111-1111-1111-1111-111111111110','USD',560000.00,0.00)
on conflict (wallet_code) do nothing;

-- GOLD WALLETS
insert into public.gold_wallets (wallet_code, customer_id, available_grams, held_grams, purity) values
  ('GLD-8821','11111111-1111-1111-1111-111111111101',140000.0000,3110.3500,'99.99'),
  ('GLD-8822','11111111-1111-1111-1111-111111111102',4665.0000,300.0000,'99.99'),
  ('GLD-8823','11111111-1111-1111-1111-111111111103',26450.0000,0.0000,'99.99'),
  ('GLD-8824','11111111-1111-1111-1111-111111111104',0.0000,0.0000,'99.99'),
  ('GLD-8825','11111111-1111-1111-1111-111111111105',88200.0000,1244.1250,'99.99'),
  ('GLD-8826','11111111-1111-1111-1111-111111111106',12500.0000,155.5200,'99.99'),
  ('GLD-8827','11111111-1111-1111-1111-111111111107',52400.0000,622.0600,'99.99'),
  ('GLD-8828','11111111-1111-1111-1111-111111111108',9340.0000,0.0000,'99.99'),
  ('GLD-8829','11111111-1111-1111-1111-111111111109',38000.0000,310.0000,'99.99'),
  ('GLD-8830','11111111-1111-1111-1111-111111111110',19400.0000,0.0000,'99.99')
on conflict (wallet_code) do nothing;

-- WALLET MOVEMENTS
insert into public.wallet_movements (wallet_code, asset, direction, amount, balance_after, status, reference, note) values
  ('CW-8822','cash','in',150000.00,195000.00,'pending_hold','DEP-89920','تحويل بنكي وارد - قيد التحقق AML'),
  ('CW-8822','cash','out',10000.00,45000.00,'settled','ACH-5544','سحب ACH'),
  ('CW-8822','cash','in',55000.00,55000.00,'settled','DEP-89910','إيداع'),
  ('CW-8821','cash','in',25000.00,1300000.00,'settled','DEP-89912','إيداع مؤسسي'),
  ('CW-8821','cash','out',50000.00,1250400.00,'settled','HOLD-882','تحرير حجز'),
  ('GLD-8821','gold','in',25000.0000,140000.0000,'settled','DEP-GLD-4411','إيداع ذهب مؤسسي'),
  ('GLD-8821','gold','out',50000.0000,115000.0000,'settled','HOLD-882','تحرير حجز');

-- ORDERS
insert into public.orders (order_code, customer_id, side, quantity, quoted_price, base_price, spread, total_amount, platform_fee, network_fee, status, settlement_status, payment_method, incident_reason) values
  ('ORD-992A','11111111-1111-1111-1111-111111111101','buy',500.00,1982.00,1980.00,2.00,991000.00,200.00,50.00,'incident','pending','Wire','انتهاء صلاحية السعر قبل التسوية'),
  ('ORD-993B','11111111-1111-1111-1111-111111111102','sell',10.00,1982.00,1980.00,2.00,19820.00,200.00,50.00,'completed','settled','Wire',null),
  ('ORD-994C','11111111-1111-1111-1111-111111111105','buy',250.00,1981.50,1980.00,1.50,495375.00,200.00,50.00,'completed','settled','Wire',null),
  ('ORD-995D','11111111-1111-1111-1111-111111111107','buy',100.00,1979.80,1978.00,1.80,197980.00,100.00,30.00,'pending','pending','ACH',null),
  ('ORD-996E','11111111-1111-1111-1111-111111111108','sell',50.00,1980.50,1979.00,1.50,99025.00,100.00,30.00,'completed','settled','Wire',null),
  ('ORD-997F','11111111-1111-1111-1111-111111111104','buy',2.00,1985.00,1980.00,5.00,3970.00,20.00,5.00,'failed','failed','Card','فشل التحقق من البطاقة'),
  ('ORD-998G','11111111-1111-1111-1111-111111111106','buy',75.00,1982.40,1980.00,2.40,148680.00,150.00,25.00,'completed','settled','Wire',null),
  ('ORD-999H','11111111-1111-1111-1111-111111111109','sell',300.00,1981.00,1980.00,1.00,594300.00,200.00,50.00,'cancelled','cancelled','Wire','إلغاء بناءً على طلب العميل'),
  ('ORD-1001','11111111-1111-1111-1111-111111111110','buy',80.00,1983.50,1980.00,3.50,158680.00,150.00,25.00,'pending','pending','ACH',null),
  ('ORD-1002','11111111-1111-1111-1111-111111111103','sell',1200.00,1980.75,1980.00,0.75,2376900.00,300.00,80.00,'completed','settled','Wire',null)
on conflict (order_code) do nothing;

-- QUOTES
insert into public.quotes (quote_code, customer_id, side, price, expires_at, status, linked_order_code) values
  ('QT-8821','11111111-1111-1111-1111-111111111101','buy',1982.00, now() + interval '14 seconds','used','ORD-992A'),
  ('QT-8820','11111111-1111-1111-1111-111111111105','sell',1978.50, now() - interval '5 minutes','expired',null),
  ('QT-8819','11111111-1111-1111-1111-111111111107','buy',1981.75, now() - interval '10 minutes','cancelled',null)
on conflict (quote_code) do nothing;

-- TRANSFERS
insert into public.transfers (transfer_code, sender_id, recipient_id, asset, quantity, status, risk_level, compliance_flag, balance_check_passed, aml_check_passed, initiated_at) values
  ('TRF-1029A','11111111-1111-1111-1111-111111111101','11111111-1111-1111-1111-111111111105','gold',50.0000,'flagged','high','نمط تحويلات متتالية بسرعة عالية',true,false, now() - interval '30 minutes'),
  ('TRF-1028B','11111111-1111-1111-1111-111111111108','11111111-1111-1111-1111-111111111107','gold',25.0000,'successful','low',null,true,true, now() - interval '2 hours'),
  ('TRF-1027C','11111111-1111-1111-1111-111111111106','11111111-1111-1111-1111-111111111101','cash',15000.00,'successful','low',null,true,true, now() - interval '3 hours'),
  ('TRF-1026D','11111111-1111-1111-1111-111111111103','11111111-1111-1111-1111-111111111109','gold',500.0000,'pending','medium',null,true,true, now() - interval '10 minutes'),
  ('TRF-1025E','11111111-1111-1111-1111-111111111109','11111111-1111-1111-1111-111111111103','cash',55000.00,'failed','medium','فشل مطابقة رقم الحساب',false,true, now() - interval '5 hours')
on conflict (transfer_code) do nothing;

-- REDEMPTIONS
insert into public.redemption_requests (code, customer_id, product_name, weight_grams, units, purity, status, courier, tracking_number, destination_address, vault_location, requested_at, shipped_at, delivered_at) values
  ('RED-4402','11111111-1111-1111-1111-111111111101','PAMP Suisse 1kg Bar',5000.0000,5,'99.99','reserved','Brinks','BR-992011','Aurelius London Office, UK','Zurich-01', now() - interval '2 days', null, null),
  ('RED-4401','11111111-1111-1111-1111-111111111105','Valcambi 100g Bar',2000.0000,20,'99.99','delivered','Brinks','BR-992001','Vanguard NY HQ','London-04', now() - interval '5 days', now() - interval '3 days', now() - interval '1 day'),
  ('RED-4399','11111111-1111-1111-1111-111111111108','1oz Britannia Coin',15550.0000,500,'99.99','blocked',null,null,'Crescent Dubai','Singapore-02', now() - interval '3 days', null, null),
  ('RED-4400','11111111-1111-1111-1111-111111111106','PAMP Suisse 100g Bar',1000.0000,10,'99.99','shipped','Malca-Amit','MA-771144','Silverline Amman Vault','London-04', now() - interval '4 days', now() - interval '1 day', null),
  ('RED-4398','11111111-1111-1111-1111-111111111107','Valcambi 1oz Bar',311.0350,10,'99.99','delivered','Brinks','BR-992000','Apex Tokyo Vault','Singapore-02', now() - interval '7 days', now() - interval '5 days', now() - interval '3 days'),
  ('RED-4397','11111111-1111-1111-1111-111111111103','Metalor 1kg Bar',10000.0000,10,'99.99','pending',null,null,'Global Sovereigns Dubai','Zurich-01', now() - interval '1 day', null, null)
on conflict (code) do nothing;

-- VAULT INVENTORY
insert into public.vault_inventory (sku, product_name, vault_location, purity, available_units, reserved_units, pending_units, status, last_audit_at) values
  ('GLD-1KG-PMP','PAMP Suisse 1kg Bar','Zurich-01','99.99',1240,450,0,'adequate', now() - interval '2 days'),
  ('GLD-1OZ-KRG','Krugerrand 1oz Coin','London-04','91.67',45,1200,500,'low', now() - interval '3 days'),
  ('GLD-GRN-LBM','LBMA Granulated Gold','Singapore-02','99.99',8500,1200,2000,'adequate', now() - interval '1 day'),
  ('GLD-100G-VLC','Valcambi 100g Bar','London-04','99.99',320,80,40,'adequate', now() - interval '4 days'),
  ('GLD-1OZ-BRT','1oz Britannia Coin','London-04','99.99',8,350,100,'critical', now() - interval '6 hours'),
  ('GLD-1KG-MTL','Metalor 1kg Bar','Zurich-01','99.99',95,20,10,'adequate', now() - interval '2 days'),
  ('GLD-50G-PMP','PAMP Suisse 50g Bar','Zurich-01','99.99',680,120,50,'adequate', now() - interval '5 days'),
  ('GLD-1OZ-EGL','American Eagle 1oz','Singapore-02','91.67',15,200,80,'critical', now() - interval '12 hours')
on conflict (sku) do nothing;

insert into public.vault_activity (vault_location, activity_type, description, carrier, authorized_by) values
  ('Singapore-02','arrival','استلام 500kg سبائك LBMA','Brinks',null),
  ('London-04','allocation','حجز 1,200 أونصة لدفعة الاسترداد RD-992',null,'System Auto-alloc'),
  ('London-04','transfer','نقل 50x1kg من Zurich-01 إلى London-04','Malca-Amit','J. Doe'),
  ('Zurich-01','audit','فحص وزن دوري - فارق 0.12g تم تسجيله',null,'Audit Bot'),
  ('Singapore-02','allocation','حجز 300 أونصة لطلب استرداد RED-4399',null,'System');

-- PRICING SOURCES
insert into public.pricing_sources (name, latency_ms, status, is_primary, priority) values
  ('LBMA Primary Feed',12,'operational',true,1),
  ('BullionDesk',45,'operational',false,2),
  ('Exchange-B',18,'operational',false,3),
  ('Reuters Backup',90,'degraded',false,4)
on conflict (name) do nothing;

-- PRICE TICKS
insert into public.price_ticks (spot_price, buy_price, sell_price, spread_bps, source, captured_at) values
  (1980.50,1984.46,1976.54,20,'LBMA Primary Feed', now()),
  (1979.80,1983.76,1975.84,20,'LBMA Primary Feed', now() - interval '1 minute'),
  (1978.20,1982.16,1974.24,20,'LBMA Primary Feed', now() - interval '2 minutes'),
  (1977.90,1981.86,1973.94,20,'LBMA Primary Feed', now() - interval '3 minutes'),
  (1978.50,1982.46,1974.54,20,'LBMA Primary Feed', now() - interval '4 minutes'),
  (1979.10,1983.06,1975.14,20,'LBMA Primary Feed', now() - interval '5 minutes'),
  (1981.00,1984.96,1977.04,20,'LBMA Primary Feed', now() - interval '6 minutes'),
  (1982.40,1986.36,1978.44,20,'LBMA Primary Feed', now() - interval '7 minutes'),
  (1980.90,1984.86,1976.94,20,'LBMA Primary Feed', now() - interval '8 minutes'),
  (1979.60,1983.56,1975.64,20,'LBMA Primary Feed', now() - interval '9 minutes');

-- PRICING CONFIG
insert into public.pricing_config (id, base_spread_pct, volatility_markup_pct, quote_ttl_seconds, auto_pricing_enabled) values
  (1,0.20,0.05,30,true)
on conflict (id) do update set updated_at = now();

-- FEE RULES
insert into public.fee_rules (name, applies_to, fixed_amount, pct_amount, status, priority) values
  ('رسوم التجزئة القياسية','Retail Tier 1-3',2.50,0.0015,'active',10),
  ('مؤسسي عالي الحجم','Institutional',15.00,0.0005,'active',20),
  ('تجاوز VIP (حوت)','Whale Tier',0.00,0.0002,'inactive',30),
  ('تحويلات داخلية','Internal Transfer',0.50,0.0001,'active',5),
  ('استرداد مادي','Physical Redemption',25.00,0.0010,'active',15);

-- TIER LIMITS
insert into public.tier_limits (tier, max_daily_buy, max_transfer, withdrawal_ceiling) values
  ('retail',5000.00,10000.00,2500.00),
  ('premium',50000.00,100000.00,25000.00),
  ('institutional',5000000.00,null,1000000.00)
on conflict (tier) do nothing;

-- COMMISSION RULES
insert into public.commission_rules (name, rate_pct, min_tier, status) values
  ('عمولة التجزئة',0.15,'retail','active'),
  ('عمولة المتميز',0.10,'premium','active'),
  ('عمولة مؤسسية',0.05,'institutional','active');

-- LEDGER ENTRIES
insert into public.ledger_entries (entry_code, account_ref, debit, credit, currency, transaction_ref, description) values
  ('LED-77X','ACC-USD-MAIN',991000.00,0,'USD','ORD-992A','تسوية أمر شراء ORD-992A'),
  ('LED-76X','ACC-USD-MAIN',0,495375.00,'USD','ORD-994C','تسوية بيع ORD-994C'),
  ('LED-75X','ACC-GLD-VAULT',5000.00,0,'OZ','RED-4402','حجز استرداد مادي'),
  ('LED-74X','ACC-USD-FEES',0,550.00,'USD','FEE-ACCR','تراكم رسوم منصة'),
  ('LED-73X','ACC-USD-MAIN',55000.00,0,'USD','DEP-89920','إيداع بنكي وارد'),
  ('LED-72X','ACC-USD-SETTLE',0,150000.00,'USD','TRX-0988B','تسوية عميل مؤسسي'),
  ('LED-71X','ACC-GLD-VAULT',0,2000.00,'OZ','RED-4401','تسليم استرداد Valcambi');

-- RECONCILIATION EXCEPTIONS
insert into public.reconciliation_exceptions (exception_code, source, transaction_ref, internal_value, external_value, difference, severity, status, age_hours, suggested_cause, assigned_to) values
  ('REC-8821','Bank A','TRX-1029A',1250.00,1248.50,-1.50,'high','under_review',32,'فارق توقيت في احتساب العمولة. رسوم مصرفية متوقعة $1.50 خصمت قبل التسوية.','Mark T.'),
  ('REC-8820','Vault B','TRX-0988B',50000.00,49950.00,-50.00,'critical','under_review',49,'نقص وزن مسجل في Zurich-01','Sarah C.'),
  ('REC-8819','Bank A','TRX-0977C',15000.00,15000.00,0.00,'low','resolved',72,'مطابقة تلقائية', null),
  ('REC-8818','Vault A','TRX-0966D',120000.00,119850.00,-150.00,'medium','escalated',48,'فحص حجز مفقود','Finance Ops'),
  ('REC-8817','Bank B','TRX-0955E',3200.00,3198.00,-2.00,'low','under_review',12,'خصم رسوم SWIFT','Mark T.');

-- AUDIT LOGS
insert into public.audit_logs (event_code, actor_name, actor_role, action, target_entity, module, result, ip_address, device, before_value, after_value, reason) values
  ('EVT-9932','Sarah Connor','super_admin','Manual Override','SPOT_PRICE_GLD','pricing','success','192.168.1.4','MacBook Pro',
   '{"SPOT_PRICE_GLD_MARGIN":"0.025"}'::jsonb,'{"SPOT_PRICE_GLD_MARGIN":"0.030"}'::jsonb,
   'تعديل طارئ للهامش بسبب تقلبات حادة في السعر الفوري. موافقة شفهية من رئيس التداول.'),
  ('EVT-9931','Michael Chen','compliance_officer','Account Freeze','GW-8824','customers','success','10.0.0.14','Chrome/macOS',
   '{"status":"active"}'::jsonb,'{"status":"suspended"}'::jsonb,'فحص AML عالي المخاطر'),
  ('EVT-9930','System: AuthEngine','service_account','Failed Login','admin@portal','access_control','failure','203.0.113.99','Unknown',
   null,null,'محاولة دخول فاشلة x3'),
  ('EVT-9929','Admin User','super_admin','Publish Changes','system_settings','settings','success','192.168.1.1','MacBook Pro',
   '{"base_spread_bps":20}'::jsonb,'{"base_spread_bps":25}'::jsonb,'تحديث هامش القاعدة'),
  ('EVT-9928','Sarah Jenkins','finance_admin','Role Assignment','Compliance Officer','roles','success','192.168.1.7','Chrome/macOS',
   null,'{"user":"sarah.connor"}'::jsonb,'إضافة دور جديد'),
  ('EVT-9927','Operations Admin','operations_admin','Order Cancel','ORD-999H','orders','success','192.168.1.22','Edge/Windows',
   '{"status":"pending"}'::jsonb,'{"status":"cancelled"}'::jsonb,'طلب العميل إلغاء'),
  ('EVT-9926','Mark Thompson','finance_admin','Reconcile','TRX-0977C','reconciliation','success','192.168.1.18','Firefox',
   null,null,'مطابقة يدوية'),
  ('EVT-9925','Compliance Bot','service_account','KYC Auto-Verify','GW-8830','kyc','warning','10.0.0.2','Service',
   null,'{"risk_level":"medium"}'::jsonb,'تحقق تلقائي - مراجعة مطلوبة');

-- MESSAGE TEMPLATES
insert into public.message_templates (name, channel, subject, body) values
  ('KYC_Approved_V2','email','تم تفعيل حسابك','مرحباً {{name}}, تمت الموافقة على وثائق KYC.'),
  ('Withdrawal_Alert_High','sms',null,'تنبيه: طلب سحب مرتفع القيمة {{amount}} بانتظار الموافقة.'),
  ('Margin_Call_Warning','push',null,'تحذير: اقتراب من حد الهامش.'),
  ('Monthly_Statement_08','email','كشف حسابك الشهري','كشف شهر {{month}} جاهز للتنزيل.'),
  ('Order_Failed_Notice','email','فشل تنفيذ الأمر','نعتذر، لم يتم تنفيذ أمر {{order_code}}.')
on conflict (name) do nothing;

-- MESSAGES
insert into public.messages (message_code, customer_id, channel, template_name, trigger_type, status, sent_at) values
  ('MSG-8492','11111111-1111-1111-1111-111111111104','email','KYC_Approved_V2','system_event','delivered', now() - interval '2 hours'),
  ('MSG-8491','11111111-1111-1111-1111-111111111111','sms','Withdrawal_Alert_High','transaction','pending', now() - interval '2 hours 10 minutes'),
  ('MSG-8490','11111111-1111-1111-1111-111111111103','push','Margin_Call_Warning','system_event','failed', now() - interval '2 hours 30 minutes'),
  ('MSG-8489','11111111-1111-1111-1111-111111111106','email','Monthly_Statement_08','scheduled','delivered', now() - interval '3 hours'),
  ('MSG-8488','11111111-1111-1111-1111-111111111108','sms','Order_Failed_Notice','transaction','delivered', now() - interval '5 hours'),
  ('MSG-8487','11111111-1111-1111-1111-111111111102','email','KYC_Approved_V2','system_event','pending', now() - interval '1 hour'),
  ('MSG-8486','11111111-1111-1111-1111-111111111107','push','Margin_Call_Warning','system_event','delivered', now() - interval '6 hours'),
  ('MSG-8485','11111111-1111-1111-1111-111111111109','email','Monthly_Statement_08','scheduled','delivered', now() - interval '8 hours'),
  ('MSG-8484','11111111-1111-1111-1111-111111111110','sms','Withdrawal_Alert_High','transaction','failed', now() - interval '10 hours'),
  ('MSG-8483','11111111-1111-1111-1111-111111111105','email','KYC_Approved_V2','system_event','delivered', now() - interval '12 hours');

-- SUPPORT CASES
insert into public.support_cases (case_code, customer_id, category, priority, status, linked_ref, created_at, updated_at) values
  ('CASE-9281','11111111-1111-1111-1111-111111111112','transaction','high','in_progress','ORD-2931', now() - interval '2 hours', now() - interval '1 hour'),
  ('CASE-9280','11111111-1111-1111-1111-111111111111','kyc','medium','new',null, now() - interval '4 hours', now() - interval '4 hours'),
  ('CASE-9279','11111111-1111-1111-1111-111111111103','wallet','critical','pending_customer','WLT-882', now() - interval '6 hours', now() - interval '3 hours'),
  ('CASE-9278','11111111-1111-1111-1111-111111111104','redemption','medium','in_progress','RED-110', now() - interval '1 day', now() - interval '5 hours'),
  ('CASE-9275','11111111-1111-1111-1111-111111111106','transaction','low','resolved','ORD-2910', now() - interval '3 days', now() - interval '2 days'),
  ('CASE-9274','11111111-1111-1111-1111-111111111102','kyc','high','in_progress',null, now() - interval '2 days', now() - interval '1 day'),
  ('CASE-9273','11111111-1111-1111-1111-111111111105','wallet','medium','new','CW-8825', now() - interval '30 minutes', now() - interval '30 minutes');

-- RISK ALERTS
insert into public.risk_alerts (alert_code, customer_id, rule_name, severity, status, reference, details) values
  ('ALRT-9921','11111111-1111-1111-1111-111111111101','نمط تحويلات متعددة بسرعة عالية','high','under_review','TRF-1029A','{"count":3,"window":"24h","amount":"150 oz"}'::jsonb),
  ('ALRT-9920','11111111-1111-1111-1111-111111111112','طلبات شراء مرتفعة المخاطر','critical','open','ORD-997F','{"attempts":5,"hours":2}'::jsonb),
  ('ALRT-9919','11111111-1111-1111-1111-111111111104','تحذير AML: دولة عالية المخاطر','high','open',null,'{"country":"XX","score":72}'::jsonb),
  ('ALRT-9918','11111111-1111-1111-1111-111111111102','تغيير سريع في IP','medium','closed',null,'{"ips":3,"countries":2}'::jsonb),
  ('ALRT-9917','11111111-1111-1111-1111-111111111111','تكرار تسجيل دخول فاشل','medium','open',null,'{"failures":5}'::jsonb);

-- ROLES + PERMISSIONS
insert into public.roles (id, name, description, is_immutable, user_count) values
  ('22222222-2222-2222-2222-222222222201','Super Admin','وصول غير مقيّد لجميع الوحدات',true,3),
  ('22222222-2222-2222-2222-222222222202','Operations Admin','العمليات اليومية على المحافظ',false,12),
  ('22222222-2222-2222-2222-222222222203','Compliance Officer','KYC وإدارة المخاطر',false,5),
  ('22222222-2222-2222-2222-222222222204','Finance Admin','الدفتر الأستاذ والتقارير',false,8),
  ('22222222-2222-2222-2222-222222222205','Support Agent','حالات الدعم للعملاء',false,15)
on conflict (name) do nothing;

insert into public.role_permissions (role_id, module, can_view, can_create, can_edit, can_delete, can_execute) values
  ('22222222-2222-2222-2222-222222222201','customers_kyc',true,true,true,true,true),
  ('22222222-2222-2222-2222-222222222201','wallet_operations',true,true,true,true,true),
  ('22222222-2222-2222-2222-222222222201','system_settings',true,true,true,true,true),
  ('22222222-2222-2222-2222-222222222202','customers_kyc',true,false,true,false,false),
  ('22222222-2222-2222-2222-222222222202','wallet_operations',true,true,true,false,true),
  ('22222222-2222-2222-2222-222222222202','system_settings',false,false,false,false,false),
  ('22222222-2222-2222-2222-222222222203','customers_kyc',true,true,true,false,true),
  ('22222222-2222-2222-2222-222222222203','wallet_operations',true,false,false,false,false),
  ('22222222-2222-2222-2222-222222222203','system_settings',false,false,false,false,false),
  ('22222222-2222-2222-2222-222222222204','customers_kyc',true,false,false,false,false),
  ('22222222-2222-2222-2222-222222222204','wallet_operations',true,false,true,false,false),
  ('22222222-2222-2222-2222-222222222204','system_settings',true,false,true,false,false),
  ('22222222-2222-2222-2222-222222222205','customers_kyc',true,false,false,false,false),
  ('22222222-2222-2222-2222-222222222205','wallet_operations',true,false,false,false,false),
  ('22222222-2222-2222-2222-222222222205','system_settings',false,false,false,false,false);

-- SYSTEM SETTINGS
insert into public.system_settings (id, environment, maintenance_mode, mfa_policy, session_timeout_minutes, admin_ip_whitelist, default_quote_ttl, base_spread_bps, max_slippage_pct, engine_version, last_deployment_at, updated_by)
values (1,'Production',false,'Strict (All Users)',15, array['192.168.1.0/24','10.0.0.0/8','203.0.113.50'], 30, 25, 1.5, 'v4.2.1-stable', now() - interval '1 day','System Admin')
on conflict (id) do update set updated_at = now();

-- INTEGRATIONS HEALTH
insert into public.integrations_health (name, category, status, latency_ms, last_sync_at, note) values
  ('Core Banking API','core','operational',45, now(),null),
  ('Global Gold Feed','pricing','operational',12, now() - interval '2 seconds',null),
  ('SMS Gateway','messaging','degraded',240, now() - interval '5 minutes','معدل فشل > 5%'),
  ('Email Provider','messaging','operational',60, now() - interval '10 seconds',null),
  ('KYC Vendor','compliance','operational',180, now() - interval '1 minute',null)
on conflict (name) do nothing;

-- KYC APPLICATIONS
insert into public.kyc_applications (app_code, customer_id, status, risk_level, sla_minutes_remaining, flags, extracted_dob, declared_dob, mismatch_reason, document_proof_url, selfie_url) values
  ('APP-8921','11111111-1111-1111-1111-111111111112','under_review','high',45, array['DOB_MISMATCH'],'1985-04-12','1985-04-21','تاريخ الميلاد المستخرج لا يطابق إدخال المستخدم','/placeholder.svg?height=400&width=300','/placeholder.svg?height=400&width=300'),
  ('APP-8922','11111111-1111-1111-1111-111111111111','pending','low',135, array[]::text[], null, null, null,'/placeholder.svg?height=400&width=300','/placeholder.svg?height=400&width=300'),
  ('APP-8923','11111111-1111-1111-1111-111111111110','pending','medium',90, array[]::text[], null, null, null,'/placeholder.svg?height=400&width=300','/placeholder.svg?height=400&width=300'),
  ('APP-8924','11111111-1111-1111-1111-111111111102','under_review','medium',60, array['HIGH_VALUE_ACCOUNT'], null, null, null,'/placeholder.svg?height=400&width=300','/placeholder.svg?height=400&width=300')
on conflict (app_code) do nothing;

-- CUSTOMER NOTES
insert into public.customer_notes (customer_id, author_name, content) values
  ('11111111-1111-1111-1111-111111111101','Admin User','عميل مؤسسي مميز - تعامل بأولوية'),
  ('11111111-1111-1111-1111-111111111102','Compliance Bot','KYC في انتظار تحقق AML للإيداع المرتفع'),
  ('11111111-1111-1111-1111-111111111104','Michael Chen','حساب معلّق بسبب نشاط مشبوه');
