-- =============================================
-- Initial Seed Data for Goa GEL Platform
-- =============================================

-- Insert Departments
INSERT INTO departments (id, code, name, wallet_address, is_active, description, contact_email, contact_phone, created_at, updated_at)
VALUES
  (
    '11111111-1111-1111-1111-111111111111',
    'FIRE_DEPT',
    'Fire & Emergency Services Department',
    '0x1111111111111111111111111111111111111111',
    true,
    'Responsible for fire safety inspections and certifications',
    'fire@goa.gov.in',
    '+91-832-2222222',
    CURRENT_TIMESTAMP,
    CURRENT_TIMESTAMP
  ),
  (
    '22222222-2222-2222-2222-222222222222',
    'TOURISM_DEPT',
    'Department of Tourism',
    '0x2222222222222222222222222222222222222222',
    true,
    'Manages tourism licenses and hospitality registrations',
    'tourism@goa.gov.in',
    '+91-832-3333333',
    CURRENT_TIMESTAMP,
    CURRENT_TIMESTAMP
  ),
  (
    '33333333-3333-3333-3333-333333333333',
    'MUNICIPALITY',
    'Municipal Corporation of Panaji',
    '0x3333333333333333333333333333333333333333',
    true,
    'Local governance and building permits',
    'municipality@goa.gov.in',
    '+91-832-4444444',
    CURRENT_TIMESTAMP,
    CURRENT_TIMESTAMP
  ),
  (
    '44444444-4444-4444-4444-444444444444',
    'HEALTH_DEPT',
    'Directorate of Health Services',
    '0x4444444444444444444444444444444444444444',
    true,
    'Health and sanitation inspections',
    'health@goa.gov.in',
    '+91-832-5555555',
    CURRENT_TIMESTAMP,
    CURRENT_TIMESTAMP
  )
ON CONFLICT (code) DO NOTHING;

-- Insert Demo Users
-- Password hashes are for: Admin@123, Fire@123, Tourism@123, Municipality@123, Citizen@123
INSERT INTO users (id, email, password_hash, name, role, department_id, phone, is_active, created_at, updated_at)
VALUES
  (
    'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
    'admin@goa.gov.in',
    '$2b$10$uTkObgkUNJSVLb0ESwSQqekO4wKJJvjC02VdEb38vxzRT9ib4ByM.',
    'System Administrator',
    'ADMIN',
    NULL,
    '+91-9876543210',
    true,
    CURRENT_TIMESTAMP,
    CURRENT_TIMESTAMP
  ),
  (
    'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
    'fire@goa.gov.in',
    '$2b$10$YB1iB3GjHfTwtaULRxSoRudg2eUft4b40V/1YI1iDK8OeAel7OXby',
    'Fire Department Officer',
    'DEPARTMENT',
    '11111111-1111-1111-1111-111111111111',
    '+91-9876543211',
    true,
    CURRENT_TIMESTAMP,
    CURRENT_TIMESTAMP
  ),
  (
    'cccccccc-cccc-cccc-cccc-cccccccccccc',
    'tourism@goa.gov.in',
    '$2b$10$MwcPrX91SxlZN09eQxEA4u6ErLOnw7DmrD2f3C7pzEY0pbKRJ.p.e',
    'Tourism Department Officer',
    'DEPARTMENT',
    '22222222-2222-2222-2222-222222222222',
    '+91-9876543212',
    true,
    CURRENT_TIMESTAMP,
    CURRENT_TIMESTAMP
  ),
  (
    'dddddddd-dddd-dddd-dddd-dddddddddddd',
    'municipality@goa.gov.in',
    '$2b$10$K4RH4xbduaGQRYMHJeXA3.7Z1eBnBTSDkOQgDLmYVWIUeYFKjp5xm',
    'Municipality Officer',
    'DEPARTMENT',
    '33333333-3333-3333-3333-333333333333',
    '+91-9876543213',
    true,
    CURRENT_TIMESTAMP,
    CURRENT_TIMESTAMP
  ),
  (
    'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee',
    'citizen@example.com',
    '$2b$10$94al.IXYDxN6yNIycR4yI.soU00DqS3BwNBXvrLr4v6bB7B94oH6G',
    'Demo Citizen',
    'CITIZEN',
    NULL,
    '+91-9876543214',
    true,
    CURRENT_TIMESTAMP,
    CURRENT_TIMESTAMP
  ),
  (
    'ffffffff-ffff-ffff-ffff-ffffffffffff',
    'citizen2@example.com',
    '$2b$10$94al.IXYDxN6yNIycR4yI.soU00DqS3BwNBXvrLr4v6bB7B94oH6G',
    'Second Citizen',
    'CITIZEN',
    NULL,
    '+91-9876543215',
    true,
    CURRENT_TIMESTAMP,
    CURRENT_TIMESTAMP
  )
ON CONFLICT (email) DO NOTHING;

-- Insert Sample Applicants (linked to citizen users)
INSERT INTO applicants (id, digilocker_id, name, email, phone, is_active, created_at, updated_at)
VALUES
  (
    'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee',
    'DL-GOA-CITIZEN-001',
    'Demo Citizen',
    'citizen@example.com',
    '+91-9876543214',
    true,
    CURRENT_TIMESTAMP,
    CURRENT_TIMESTAMP
  ),
  (
    'ffffffff-ffff-ffff-ffff-ffffffffffff',
    'DL-GOA-CITIZEN-002',
    'Second Citizen',
    'citizen2@example.com',
    '+91-9876543215',
    true,
    CURRENT_TIMESTAMP,
    CURRENT_TIMESTAMP
  )
ON CONFLICT (digilocker_id) DO NOTHING;

-- Insert Sample Workflows
INSERT INTO workflows (id, workflow_type, name, description, version, definition, is_active, created_at, updated_at)
VALUES
  (
    'ffffffff-ffff-ffff-ffff-ffffffffffff',
    'RESORT_LICENSE',
    'Resort License Approval Workflow',
    'Multi-department approval workflow for resort licenses in Goa',
    1,
    '{"isActive":true,"stages":[{"stageId":"stage_1_fire","stageName":"Fire Safety Review","stageOrder":1,"executionType":"SEQUENTIAL","requiredApprovals":[{"departmentCode":"FIRE_DEPT","departmentName":"Fire & Emergency Services Department","requiredDocuments":["FIRE_SAFETY_CERTIFICATE","BUILDING_PLAN"],"isMandatory":true}],"completionCriteria":"ALL","timeoutDays":7,"onTimeout":"NOTIFY","onRejection":"FAIL_REQUEST"},{"stageId":"stage_2_parallel","stageName":"Tourism & Municipality Review","stageOrder":2,"executionType":"PARALLEL","requiredApprovals":[{"departmentCode":"TOURISM_DEPT","departmentName":"Department of Tourism","requiredDocuments":["PROPERTY_OWNERSHIP","BUILDING_PLAN"],"isMandatory":true},{"departmentCode":"MUNICIPALITY","departmentName":"Municipal Corporation of Panaji","requiredDocuments":["PROPERTY_OWNERSHIP","TAX_CLEARANCE"],"isMandatory":true}],"completionCriteria":"ALL","timeoutDays":14,"onTimeout":"ESCALATE","onRejection":"FAIL_REQUEST"},{"stageId":"stage_3_health","stageName":"Health & Sanitation Review","stageOrder":3,"executionType":"SEQUENTIAL","requiredApprovals":[{"departmentCode":"HEALTH_DEPT","departmentName":"Directorate of Health Services","requiredDocuments":["HEALTH_CERTIFICATE"],"isMandatory":true}],"completionCriteria":"ALL","timeoutDays":7,"onTimeout":"NOTIFY","onRejection":"FAIL_REQUEST"}]}',
    true,
    CURRENT_TIMESTAMP,
    CURRENT_TIMESTAMP
  ),
  (
    'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
    'FIRE_SAFETY_CERT',
    'Fire Safety Certificate Workflow',
    'Workflow for fire safety certification',
    1,
    '{"isActive":true,"stages":[{"stageId":"stage_1","stageName":"Fire Safety Review","stageOrder":1,"executionType":"SEQUENTIAL","requiredApprovals":[{"departmentCode":"FIRE_DEPT","departmentName":"Fire & Emergency Services Department","requiredDocuments":["FIRE_SAFETY_CERTIFICATE","BUILDING_PLAN"],"isMandatory":true}],"completionCriteria":"ALL","timeoutDays":7,"onTimeout":"NOTIFY","onRejection":"FAIL_REQUEST"}]}',
    true,
    CURRENT_TIMESTAMP,
    CURRENT_TIMESTAMP
  ),
  (
    'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
    'TOURISM_LICENSE',
    'Tourism License Workflow',
    'Workflow for tourism business licenses',
    1,
    '{"isActive":true,"stages":[{"stageId":"stage_1","stageName":"Tourism Department Review","stageOrder":1,"executionType":"SEQUENTIAL","requiredApprovals":[{"departmentCode":"TOURISM_DEPT","departmentName":"Department of Tourism","requiredDocuments":["PROPERTY_OWNERSHIP"],"isMandatory":true}],"completionCriteria":"ALL","timeoutDays":14,"onTimeout":"NOTIFY","onRejection":"FAIL_REQUEST"}]}',
    true,
    CURRENT_TIMESTAMP,
    CURRENT_TIMESTAMP
  ),
  (
    'cccccccc-cccc-cccc-cccc-cccccccccccc',
    'TRADE_LICENSE',
    'Trade License Workflow',
    'Workflow for trade and business licenses',
    1,
    '{"isActive":true,"stages":[{"stageId":"stage_1","stageName":"Municipality Review","stageOrder":1,"executionType":"SEQUENTIAL","requiredApprovals":[{"departmentCode":"MUNICIPALITY","departmentName":"Municipal Corporation","requiredDocuments":["PROPERTY_OWNERSHIP","TAX_CLEARANCE"],"isMandatory":true}],"completionCriteria":"ALL","timeoutDays":14,"onTimeout":"NOTIFY","onRejection":"FAIL_REQUEST"}]}',
    true,
    CURRENT_TIMESTAMP,
    CURRENT_TIMESTAMP
  )
ON CONFLICT (workflow_type) DO NOTHING;
