-- Migration: Create Super Admin and System Tenant
-- Description: Inserts the default System Tenant and Super Admin user.
-- Use fixed UUIDs for reproducibility in dev environments.

-- 1. Insert System Tenant
INSERT INTO core_companies (id, name, document, contact, status, created_at, updated_at)
VALUES (
    '00000000-0000-0000-0000-000000000001', -- Fixed System Tenant ID
    'System Tenant (SuperAdmin Context)',
    'SYSTEM',
    'admin@system.local',
    'ACTIVE',
    CURRENT_TIMESTAMP,
    CURRENT_TIMESTAMP
) ON CONFLICT (id) DO NOTHING;

-- 2. Insert Super Admin User
-- Password: "password123" (BCrypt hash)
INSERT INTO core_users (id, tenant_id, name, email, password_hash, status, created_at, updated_at)
VALUES (
    '00000000-0000-0000-0000-000000000002', -- Fixed SuperAdmin User ID
    '00000000-0000-0000-0000-000000000001', -- Link to System Tenant
    'Super Administrator',
    'admin@todai.jobs',
    '$2a$10$UWrE9xN39lVagJHlXZsxwOVI3NRSEd1VJ6UzMblW6LOxNmsOZtj9K', -- "password123"
    'ACTIVE',
    CURRENT_TIMESTAMP,
    CURRENT_TIMESTAMP
) ON CONFLICT (id) DO NOTHING;

-- 3. Assign Super Admin Role
INSERT INTO core_user_roles (user_id, role)
VALUES (
    '00000000-0000-0000-0000-000000000002',
    'SUPER_ADMIN'
) ON CONFLICT (user_id, role) DO NOTHING;
