-- Migration Script: Create Dummy SRM Users for All Coastal Districts
-- 
-- This SQL script creates dummy SRM (Sea Resource Manager) users for each coastal district
-- in Tamil Nadu and Union Territories (Puducherry, Karaikal).
-- 
-- Default password for all dummy SRM users: "123123"
-- Password hash is generated using PHP password_hash() function
-- 
-- Usage: Run this SQL script directly in your database or use the PHP version:
-- php api/migrations/create_dummy_srm_users.php

-- Note: Make sure SRM role exists and category column exists before running this script
-- Run these migrations first if needed:
-- - api/migrations/add_srm_role.sql
-- - api/migrations/add_category_column.sql

-- Default password hash for "123123" (generated with PHP password_hash)
-- Password: 123123
SET @default_password_hash = '$2y$10$MUZ.IYRntOe4wY89l9m/VeL8rs5MTngxXrstb/M6J7E5APlKpaU7i';

-- Insert dummy SRM users for each coastal district
-- Format: SRM-SRM-MGR-{serial}-{district_code}

INSERT INTO users (user_id, name, father_name, phone, email, password_hash, role, coastal_district, district, category, is_active, created_at, updated_at)
VALUES
-- Tiruvallur
('SRM-SRM-MGR-1-TV', 'SRM Manager - Tiruvallur', 'District Manager', '9999000001', 'srm.tiruvallur@kadal.amuthu', @default_password_hash, 'srm', 'Tiruvallur', 'Tiruvallur', 'agent_manager', 1, NOW(), NOW()),

-- Chennai
('SRM-SRM-MGR-1-CH', 'SRM Manager - Chennai', 'District Manager', '9999000002', 'srm.chennai@kadal.amuthu', @default_password_hash, 'srm', 'Chennai', 'Chennai', 'agent_manager', 1, NOW(), NOW()),

-- Chengalpattu
('SRM-SRM-MGR-1-CP', 'SRM Manager - Chengalpattu', 'District Manager', '9999000003', 'srm.chengalpattu@kadal.amuthu', @default_password_hash, 'srm', 'Chengalpattu', 'Chengalpattu', 'agent_manager', 1, NOW(), NOW()),

-- Viluppuram
('SRM-SRM-MGR-1-VL', 'SRM Manager - Viluppuram', 'District Manager', '9999000004', 'srm.viluppuram@kadal.amuthu', @default_password_hash, 'srm', 'Viluppuram', 'Viluppuram', 'agent_manager', 1, NOW(), NOW()),

-- Cuddalore
('SRM-SRM-MGR-1-CD', 'SRM Manager - Cuddalore', 'District Manager', '9999000005', 'srm.cuddalore@kadal.amuthu', @default_password_hash, 'srm', 'Cuddalore', 'Cuddalore', 'agent_manager', 1, NOW(), NOW()),

-- Mayiladuthurai
('SRM-SRM-MGR-1-MD', 'SRM Manager - Mayiladuthurai', 'District Manager', '9999000006', 'srm.mayiladuthurai@kadal.amuthu', @default_password_hash, 'srm', 'Mayiladuthurai', 'Mayiladuthurai', 'agent_manager', 1, NOW(), NOW()),

-- Nagapattinam
('SRM-SRM-MGR-1-NG', 'SRM Manager - Nagapattinam', 'District Manager', '9999000007', 'srm.nagapattinam@kadal.amuthu', @default_password_hash, 'srm', 'Nagapattinam', 'Nagapattinam', 'agent_manager', 1, NOW(), NOW()),

-- Tiruvarur
('SRM-SRM-MGR-1-TR', 'SRM Manager - Tiruvarur', 'District Manager', '9999000008', 'srm.tiruvarur@kadal.amuthu', @default_password_hash, 'srm', 'Tiruvarur', 'Tiruvarur', 'agent_manager', 1, NOW(), NOW()),

-- Thanjavur
('SRM-SRM-MGR-1-TJ', 'SRM Manager - Thanjavur', 'District Manager', '9999000009', 'srm.thanjavur@kadal.amuthu', @default_password_hash, 'srm', 'Thanjavur', 'Thanjavur', 'agent_manager', 1, NOW(), NOW()),

-- Pudukkottai
('SRM-SRM-MGR-1-PK', 'SRM Manager - Pudukkottai', 'District Manager', '9999000010', 'srm.pudukkottai@kadal.amuthu', @default_password_hash, 'srm', 'Pudukkottai', 'Pudukkottai', 'agent_manager', 1, NOW(), NOW()),

-- Ramanathapuram
('SRM-SRM-MGR-1-RM', 'SRM Manager - Ramanathapuram', 'District Manager', '9999000011', 'srm.ramanathapuram@kadal.amuthu', @default_password_hash, 'srm', 'Ramanathapuram', 'Ramanathapuram', 'agent_manager', 1, NOW(), NOW()),

-- Thoothukudi
('SRM-SRM-MGR-1-TK', 'SRM Manager - Thoothukudi', 'District Manager', '9999000012', 'srm.thoothukudi@kadal.amuthu', @default_password_hash, 'srm', 'Thoothukudi', 'Thoothukudi', 'agent_manager', 1, NOW(), NOW()),

-- Tirunelveli
('SRM-SRM-MGR-1-TN', 'SRM Manager - Tirunelveli', 'District Manager', '9999000013', 'srm.tirunelveli@kadal.amuthu', @default_password_hash, 'srm', 'Tirunelveli', 'Tirunelveli', 'agent_manager', 1, NOW(), NOW()),

-- Kanyakumari
('SRM-SRM-MGR-1-KK', 'SRM Manager - Kanyakumari', 'District Manager', '9999000014', 'srm.kanyakumari@kadal.amuthu', @default_password_hash, 'srm', 'Kanyakumari', 'Kanyakumari', 'agent_manager', 1, NOW(), NOW()),

-- Puducherry
('SRM-SRM-MGR-1-PY', 'SRM Manager - Puducherry', 'District Manager', '9999000015', 'srm.puducherry@kadal.amuthu', @default_password_hash, 'srm', 'Puducherry', 'Puducherry', 'agent_manager', 1, NOW(), NOW()),

-- Karaikal
('SRM-SRM-MGR-1-KR', 'SRM Manager - Karaikal', 'District Manager', '9999000016', 'srm.karaikal@kadal.amuthu', @default_password_hash, 'srm', 'Karaikal', 'Karaikal', 'agent_manager', 1, NOW(), NOW())

ON DUPLICATE KEY UPDATE
    updated_at = NOW();

-- Verify the inserted records
SELECT 
    user_id,
    name,
    coastal_district,
    district,
    category,
    phone,
    email,
    is_active,
    created_at
FROM users
WHERE role = 'srm'
  AND category = 'agent_manager'
ORDER BY coastal_district;
