-- Insurer Setup table + seed data

CREATE TABLE IF NOT EXISTS insurers (
    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    name VARCHAR(255) NOT NULL,
    short_name VARCHAR(100) NULL,
    address TEXT NULL,
    phone VARCHAR(50) NULL,
    email VARCHAR(255) NULL,
    website VARCHAR(255) NULL,
    contact_person VARCHAR(255) NULL,
    contact_phone VARCHAR(50) NULL,
    status ENUM('active','inactive') NOT NULL DEFAULT 'active',
    created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
    deleted_at TIMESTAMP NULL DEFAULT NULL,
    PRIMARY KEY (id),
    UNIQUE KEY uq_insurers_name (name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Seed Nigerian insurance companies
INSERT IGNORE INTO insurers (name, short_name, address, phone, email, website, status) VALUES
('Leadway Assurance Company Limited', 'Leadway', 'Leadway House, 121/123 Broad Street, Marina, Lagos', '0700-LEADWAY', 'info@leadway.com', 'www.leadway.com', 'active'),
('AIICO Insurance Plc', 'AIICO', 'AIICO Plaza, Plot PC 12, Churchgate Street, Victoria Island, Lagos', '01-2795000', 'customerservice@aiicoplc.com', 'www.aiicoplc.com', 'active'),
('AXA Mansard Insurance Plc', 'AXA Mansard', 'AXA Mansard House, Plot 1090, Ahmadu Bello Way, Victoria Island, Lagos', '01-4608800', 'info@axamansard.com', 'www.axamansard.com', 'active'),
('Custodian Insurance Plc', 'Custodian', 'Custodian House, 16A, Commercial Avenue, Sabo, Yaba, Lagos', '01-3422000', 'info@custodianplc.com', 'www.custodianplc.com', 'active'),
('Mutual Benefits Assurance Plc', 'Mutual Benefits', 'Mutual Benefits House, 233, Ikorodu Road, Lagos', '01-4533000', 'info@mutualng.com', 'www.mutualng.com', 'active'),
('Cornerstone Insurance Plc', 'Cornerstone', 'Cornerstone House, 216, Ikorodu Road, Ilupeju, Lagos', '01-2791000', 'info@cornerstone.com.ng', 'www.cornerstone.com.ng', 'active'),
('NEM Insurance Plc', 'NEM', 'NEM House, 6, Igbosere Street, Lagos Island, Lagos', '01-2630901', 'info@neminsuranceplc.com', 'www.neminsuranceplc.com', 'active'),
('Law Union and Rock Insurance Plc', 'Law Union', 'Law Union House, 122, Awolowo Road, Ikoyi, Lagos', '01-4618000', 'info@lawunionrock.com', 'www.lawunionrock.com', 'active'),
('Lasaco Assurance Plc', 'Lasaco', 'Lasaco House, 1, Nnamdi Azikiwe Street, Lagos', '01-2631616', 'info@lasaco.com', 'www.lasaco.com', 'active'),
('Royal Exchange Plc', 'Royal Exchange', 'Royal Exchange Building, 17, Martin Street, Lagos Island, Lagos', '01-2643432', 'info@royalexchange-plc.com', 'www.royalexchange-plc.com', 'active'),
('Standard Alliance Insurance Plc', 'Standard Alliance', 'Standard Alliance House, 1, Oyinlola Abayomi Street, Off Adeola Odeku, Victoria Island, Lagos', '01-2716000', 'info@standardalliance.com', 'www.standardalliance.com', 'active'),
('Sovereign Trust Insurance Plc', 'Sovereign Trust', 'Sovereign Trust House, 219, Ikorodu Road, Ilupeju, Lagos', '01-7792000', 'info@sovereigntrust.com', 'www.sovereigntrust.com', 'active'),
('Sunu Assurances Nigeria Plc', 'Sunu', 'Sunu House, 62, Opebi Road, Ikeja, Lagos', '01-2735600', 'info@sunuassurances.com', 'www.sunuassurances.com', 'active'),
('United Capital Insurance Limited', 'United Capital', 'United Capital House, 107, Awolowo Road, Ikoyi, Lagos', '01-2809000', 'info@unitedcapitalinsurance.com', 'www.unitedcapitalinsurance.com', 'active'),
('Consolidated Hallmark Insurance Plc', 'Consolidated Hallmark', 'Consolidated Hallmark House, 248, Ikorodu Road, Ilupeju, Lagos', '01-4485000', 'info@chinsurance.com.ng', 'www.chinsurance.com.ng', 'active'),
('Goldlink Insurance Plc', 'Goldlink', 'Goldlink House, 10, Jimoh Ojora Street, Off Adeniyi Jones, Ikeja, Lagos', '01-2910662', 'info@goldlinkplc.com', 'www.goldlinkplc.com', 'active'),
('Industrial and General Insurance Plc', 'IGI', 'IGI House, 68, Tafawa Balewa Road, Lagos', '01-8978222', 'info@iginsurance.com.ng', 'www.iginsurance.com.ng', 'active'),
('Mansard Insurance Plc', 'Mansard', 'Mansard House, Plot 1090, Ahmadu Bello Way, Victoria Island, Lagos', '01-4608800', 'info@mansardplc.com', 'www.mansardplc.com', 'active'),
('NCRIB (Nigerian Council of Registered Insurance Brokers)', 'NCRIB', 'NCRIB House, 2, Balarabe Musa Crescent, Victoria Island, Lagos', '01-2610431', 'info@ncrib.org.ng', 'www.ncib.org.ng', 'active'),
('Prestige Insurance Brokers Limited', 'Prestige', 'Prestige House, 30, Allen Avenue, Ikeja, Lagos', '01-7742148', 'info@prestige.com.ng', 'www.prestige.com.ng', 'active'),
('Tropical General Insurance (TGI)', 'TGI', 'TGI House, 1, Kodesoh Street, Off Durosimi Etti Drive, Lekki Phase 1, Lagos', '01-4541150', 'info@tgiplc.com', 'www.tgiplc.com', 'active'),
('WAPIC Insurance Plc', 'WAPIC', 'WAPIC House, Plot 2, Oyinlola Abayomi Street, Off Adeola Odeku, Victoria Island, Lagos', '01-2719600', 'customerservice@wapic.com', 'www.wapic.com', 'active'),
('Zenith Insurance Limited', 'Zenith Insurance', 'Zenith Insurance Building, 6, Idowu Taylor Street, Victoria Island, Lagos', '01-2807000', 'info@zenithinsurance.com', 'www.zenithinsurance.com', 'active'),
('Alliance and General Insurance Brokers Limited', 'Alliance & General', 'Alliance House, 10, Tokunbo Alli Street, Off Awolowo Road, Ikoyi, Lagos', '01-2673200', 'info@alliancegeneral.com', 'www.alliancegeneral.com', 'active'),
('Anchor Insurance Brokers Limited', 'Anchor', 'Anchor House, 6, Odugbesan Street, Off Opebi Road, Ikeja, Lagos', '01-9031770', 'info@anchorinsurance.com', 'www.anchorinsurance.com', 'active'),
('Aspect Insurance Brokers Limited', 'Aspect', 'Aspect House, 51, Awolowo Road, Ikoyi, Lagos', '01-2719890', 'info@aspectbrokers.com', 'www.aspectbrokers.com', 'active'),
('B.D. Jones Insurance Brokers Limited', 'B.D. Jones', 'B.D. Jones House, 73, Awolowo Road, Ikoyi, Lagos', '01-2673421', 'info@bdjones.com', 'www.bdjones.com', 'active'),
('Broadlife Insurance Brokers Limited', 'Broadlife', 'Broadlife House, 34, Ikorodu Road, Lagos', '01-4395000', 'info@broadlifeng.com', 'www.broadlifeng.com', 'active'),
('Crusader Insurance Brokers Limited', 'Crusader', 'Crusader House, 1, Oke-Ira Street, Off Bode Thomas, Surulere, Lagos', '01-5851000', 'info@crusaderbrokers.com', 'www.crusaderbrokers.com', 'active'),
('Edgewood Insurance Brokers Limited', 'Edgewood', 'Edgewood House, 15, Ogundana Drive, Off Allen Avenue, Ikeja, Lagos', '01-9038000', 'info@edgewoodbrokers.com', 'www.edgewoodbrokers.com', 'active'),
('Excel Insurance Brokers Limited', 'Excel', 'Excel House, 4, Oshuntokun Avenue, Ibadan, Oyo', '02-7510156', 'info@excelbrokers.com', 'www.excelbrokers.com', 'active'),
('FBN Insurance Brokers Limited', 'FBN Insurance', 'FBN House, 1, Bankole Street, Off Awolowo Road, Ikoyi, Lagos', '01-2715500', 'info@fbninsurance.com', 'www.fbninsurance.com', 'active'),
('GND Insurance Brokers Limited', 'GND', 'GND House, 5, Ojuolape Street, Off Opebi Road, Ikeja, Lagos', '01-2916181', 'info@gndbrokers.com', 'www.gndbrokers.com', 'active'),
('Greenlife Insurance Brokers Limited', 'Greenlife', 'Greenlife House, 2, Olatunde Ayoola Street, Ikeja, Lagos', '01-2952888', 'info@greenlifebrokers.com', 'www.greenlifebrokers.com', 'active'),
('Hogg Insurance Brokers Limited', 'Hogg', 'Hogg House, 44, Awolowo Road, Ikoyi, Lagos', '01-2693385', 'info@hogg.com.ng', 'www.hogg.com.ng', 'active'),
('IBI Insurance Brokers Limited', 'IBI', 'IBI House, 16, Opebi Road, Ikeja, Lagos', '01-4932772', 'info@ibibrokers.com', 'www.ibibrokers.com', 'active'),
('JMG Insurance Brokers Limited', 'JMG', 'JMG House, 8, Otunba Jobi Fele Way, Alausa, Ikeja, Lagos', '01-2793788', 'info@jmgbrokers.com', 'www.jmgbrokers.com', 'active'),
('Kingbird Insurance Brokers Limited', 'Kingbird', 'Kingbird House, 17A, Opebi Road, Ikeja, Lagos', '01-2911711', 'info@kingbird.com.ng', 'www.kingbird.com.ng', 'active'),
('Millenium Insurance Brokers Limited', 'Millenium', 'Millenium House, 28, Kodesoh Street, Lekki Phase 1, Lagos', '01-4541039', 'info@milleniumbrokers.com', 'www.milleniumbrokers.com', 'active'),
('NAICOM (National Insurance Commission)', 'NAICOM', 'NAICOM House, Plot 807, Kashim Ibrahim Street, Abuja', '09-2923000', 'info@naicom.gov.ng', 'www.naicom.gov.ng', 'active'),
('New Horizon Insurance Brokers Limited', 'New Horizon', 'New Horizon House, 2, Obisesan Street, Ikeja, Lagos', '01-7744000', 'info@newhorizonbrokers.com', 'www.newhorizonbrokers.com', 'active'),
('Oak Insurance Brokers Limited', 'Oak', 'Oak House, 23, Ikorodu Road, Fadeyi, Lagos', '01-4391000', 'info@oakbrokers.com', 'www.oakbrokers.com', 'active'),
('Pinnacle Insurance Brokers Limited', 'Pinnacle', 'Pinnacle House, 6, Oyetola Street, Off Opebi Road, Ikeja, Lagos', '01-2915111', 'info@pinnaclebrokers.com', 'www.pinnaclebrokers.com', 'active'),
('Quest Insurance Brokers Limited', 'Quest', 'Quest House, 10, Abebe Village Road, Iganmu, Lagos', '01-5850500', 'info@questbrokers.com', 'www.questbrokers.com', 'active'),
('Rahamaniyya Insurance Brokers Limited', 'Rahamaniyya', 'Rahamaniyya House, 14, Ladoke Akintola Boulevard, Garki 2, Abuja', '09-6722122', 'info@rahamaniyya.com', 'www.rahamaniyya.com', 'active'),
('Staco Insurance Plc', 'Staco', 'Staco House, 40, Ikorodu Road, Lagos', '01-2631481', 'info@stacoinsurance.com', 'www.stacoinsurance.com', 'active'),
('Sureguard Insurance Brokers Limited', 'Sureguard', 'Sureguard House, 21, Town Planning Way, Ilupeju, Lagos', '01-2911212', 'info@sureguardbrokers.com', 'www.sureguardbrokers.com', 'active'),
('Tower Insurance Brokers Limited', 'Tower', 'Tower House, 5, Adebayo Doherty Road, Lekki Phase 1, Lagos', '01-6328282', 'info@towerbrokers.com', 'www.towerbrokers.com', 'active'),
('Unique Insurance Brokers Limited', 'Unique', 'Unique House, 3, Ola Ayeni Street, Ikeja, Lagos', '01-2910091', 'info@uniquebrokers.com', 'www.uniquebrokers.com', 'active'),
('Trustfund Insurance Brokers Limited', 'Trustfund', 'Trustfund House, 12, Kodesoh Street, Lekki Phase 1, Lagos', '01-4541789', 'info@trustfundbrokers.com', 'www.trustfundbrokers.com', 'active'),
('Valtrust Insurance Brokers Limited', 'Valtrust', 'Valtrust House, 19, Toyin Street, Ikeja, Lagos', '01-2914770', 'info@valtrust.com.ng', 'www.valtrust.com.ng', 'active');

-- Add permissions for Insurer setup
INSERT IGNORE INTO permissions (code, description) VALUES
('insurer.view', 'View insurance companies'),
('insurer.create', 'Create insurance companies'),
('insurer.edit', 'Edit insurance companies'),
('insurer.delete', 'Delete insurance companies');

-- Grant insurer permissions to all existing roles
INSERT IGNORE INTO role_permissions (role_id, permission_id)
SELECT r.id, p.id FROM roles r CROSS JOIN permissions p
WHERE p.code IN ('insurer.view','insurer.create','insurer.edit','insurer.delete');
