-- Core seed data: roles, permissions, providers, settings, CMS. Safe to re-run.
INSERT IGNORE INTO roles (id, slug, name) VALUES
 (1,'super_admin','Super Admin'),(2,'admin','Admin'),(3,'support','Support Staff'),(4,'user','Regular User');

INSERT IGNORE INTO permissions (slug, description) VALUES
 ('admin.access','Open the admin panel'),
 ('users.manage','View and manage users'),
 ('plans.manage','Create and edit plans, coupons, subscriptions'),
 ('wallet.approve','Approve add-funds requests and adjust balances'),
 ('transactions.view_all','View all tenants transactions'),
 ('providers.manage','Manage providers and parser configuration'),
 ('devices.manage','Manage and revoke any device'),
 ('developer.view_all','View all API / webhook logs'),
 ('cms.manage','Edit website content'),
 ('settings.manage','Edit system, email and security settings'),
 ('support.reply','Reply to support tickets'),
 ('audit.view','View audit and security logs');

-- super_admin: everything
INSERT IGNORE INTO role_permissions (role_id, permission_id) SELECT 1, id FROM permissions;
-- admin: everything except settings/cms
INSERT IGNORE INTO role_permissions (role_id, permission_id)
  SELECT 2, id FROM permissions WHERE slug NOT IN ('settings.manage','cms.manage');
-- support: tickets + read-only user view
INSERT IGNORE INTO role_permissions (role_id, permission_id)
  SELECT 3, id FROM permissions WHERE slug IN ('admin.access','support.reply','users.manage');

INSERT IGNORE INTO providers (id, slug, name, account_type, parser_class, sort_order) VALUES
 (1,'bkash','bKash Personal','personal','App\\Services\\Parsers\\ConfigurableParser',1),
 (2,'nagad','Nagad Personal','personal','App\\Services\\Parsers\\ConfigurableParser',2),
 (3,'rocket','Rocket Personal','personal','App\\Services\\Parsers\\ConfigurableParser',3),
 (4,'upay','Upay Personal','personal','App\\Services\\Parsers\\ConfigurableParser',4);

-- Rocket numbers are typically the mobile number plus a trailing digit (12 digits); allow both.
UPDATE providers SET number_pattern='^01[3-9][0-9]{8}[0-9]?$' WHERE slug='rocket';

-- Default parser patterns. These are STARTING POINTS and must be verified against real SMS
-- samples from each provider before production use; edit them in Admin > Parser Configuration.
INSERT IGNORE INTO provider_parser_configs (provider_id, config_key, config_value) VALUES
 (1,'txn_id_pattern','TrxID\\s*([A-Z0-9]{8,12})'),
 (1,'amount_pattern','(?:Tk|BDT)\\s*([0-9,]+(?:\\.[0-9]{1,2})?)'),
 (1,'sender_pattern','from\\s*(01[0-9]{9})'),
 (1,'received_keyword','received'),
 (2,'txn_id_pattern','TxnID:?\\s*([A-Z0-9]{8,12})'),
 (2,'amount_pattern','(?:Amount|Tk)[:\\s]*([0-9,]+(?:\\.[0-9]{1,2})?)'),
 (2,'sender_pattern','(?:Sender|from)[:\\s]*(01[0-9]{9})'),
 (2,'received_keyword','received'),
 (3,'txn_id_pattern','TxnId:?\\s*([A-Z0-9]{8,14})'),
 (3,'amount_pattern','(?:Tk|BDT)\\s*([0-9,]+(?:\\.[0-9]{1,2})?)'),
 (3,'sender_pattern','from\\s*(01[0-9]{9,10})'),
 (3,'received_keyword','received'),
 (4,'txn_id_pattern','(?:TrxID|TxnID):?\\s*([A-Z0-9]{8,14})'),
 (4,'amount_pattern','(?:Tk|BDT)\\s*([0-9,]+(?:\\.[0-9]{1,2})?)'),
 (4,'sender_pattern','from\\s*(01[0-9]{9})'),
 (4,'received_keyword','received');

INSERT IGNORE INTO system_settings (setting_key, setting_value) VALUES
 ('brand_name','Your Brand'),
 ('brand_tagline','Automatic payment verification for personal mobile banking'),
 ('primary_color','#13A8E8'),
 ('secondary_color','#3678F6'),
 ('logo_path',''),
 ('favicon_path',''),
 ('site_title','Your Brand - Payment Verification'),
 ('seo_description','Verify incoming mobile banking payments automatically.'),
 ('contact_email',''),
 ('contact_phone',''),
 ('contact_address',''),
 ('social_facebook',''),('social_twitter',''),('social_telegram',''),
 ('footer_text','All rights reserved.'),
 ('hero_title','Verify mobile payments automatically'),
 ('hero_description','Connect your device, receive transaction signals, and verify orders through a developer API and signed webhooks.'),
 ('registration_enabled','1'),
 ('trial_plan_id',''),
 ('order_default_expiry_minutes','30'),
 ('tx_time_window_minutes','60'),
 ('sms_retention_days','90'),
 ('smtp_host',''),('smtp_port','587'),('smtp_user',''),('smtp_from',''),
 ('maintenance_mode','0');

INSERT IGNORE INTO cms_pages (slug, title, body_html, is_published) VALUES
 ('terms','Terms of Service','<p>Edit this page from Admin &rsaquo; Website CMS.</p>',1),
 ('privacy','Privacy Policy','<p>Edit this page from Admin &rsaquo; Website CMS.</p>',1),
 ('faq','FAQ','',1),
 ('features','Features','',1),
 ('how-it-works','How It Works','',1);
