-- =============================================================================
-- E2E Test Users - Seed Script
-- =============================================================================
-- Pre-seeded test users with known credentials for E2E testing.
-- These users have bcrypt-hashed passwords matching the E2E_ env vars.
--
-- Passwords:
--   e2e-worker: E2eWorkerPass123!
--   e2e-client: E2eClientPass123!
--   e2e-admin:  E2eAdminPass123!
--
-- Runs after 01-init.sql creates the sso schema and tables.

-- E2E Worker account (access_level='user', profiles=['worker'])
INSERT INTO sso.users (
    id, email, username, password_hash, access_level, profiles, primary_profile,
    is_active, email_verified, email_verified_at, created_at, updated_at
) VALUES (
    'e2e00000-0000-0000-0000-000000000001',
    'e2e-worker@atlilith.test',
    'e2e-worker',
    '$2b$12$AJJv8.Ag41p6V1c0XMogaOgSCQgC7tcVaCQePMjGD8N0y4fxBXIre',
    'user',
    '["worker"]'::jsonb,
    'worker',
    true,
    true,
    NOW(),
    NOW(),
    NOW()
) ON CONFLICT (email) DO UPDATE SET
    password_hash = EXCLUDED.password_hash,
    updated_at = NOW();

-- E2E Client account (access_level='user', profiles=['client'])
INSERT INTO sso.users (
    id, email, username, password_hash, access_level, profiles, primary_profile,
    is_active, email_verified, email_verified_at, created_at, updated_at
) VALUES (
    'e2e00000-0000-0000-0000-000000000002',
    'e2e-client@atlilith.test',
    'e2e-client',
    '$2b$12$0KDYn4hqqBwj7ZPbcfug0u/kBArssouDi2sZI/nREKtzNZVfEUESa',
    'user',
    '["client"]'::jsonb,
    'client',
    true,
    true,
    NOW(),
    NOW(),
    NOW()
) ON CONFLICT (email) DO UPDATE SET
    password_hash = EXCLUDED.password_hash,
    updated_at = NOW();

-- E2E Admin account (access_level='admin', profiles=['admin'])
INSERT INTO sso.users (
    id, email, username, password_hash, access_level, profiles, primary_profile,
    is_active, email_verified, email_verified_at, created_at, updated_at
) VALUES (
    'e2e00000-0000-0000-0000-000000000003',
    'e2e-admin@atlilith.test',
    'e2e-admin',
    '$2b$12$MXI45t5ufiVcQtnzDSSzn.dKdqUitCr1GDKYmfuFYFKGb87sn3rqG',
    'admin',
    '["admin"]'::jsonb,
    'admin',
    true,
    true,
    NOW(),
    NOW(),
    NOW()
) ON CONFLICT (email) DO UPDATE SET
    password_hash = EXCLUDED.password_hash,
    updated_at = NOW();

-- Verify seed data
DO $$
DECLARE
    user_count INTEGER;
BEGIN
    SELECT COUNT(*) INTO user_count FROM sso.users WHERE email LIKE 'e2e-%@atlilith.test';
    RAISE NOTICE 'E2E test users seeded: % users', user_count;
END $$;
