-- Seed data for roles and initial admin

-- Roles
INSERT INTO roles (id, name)
VALUES
    (gen_random_uuid(), 'admin'),
    (gen_random_uuid(), 'support')
ON CONFLICT (name) DO NOTHING;

-- Initial admin user (placeholder password hash)
-- Replace password_hash with your identity provider hash.
INSERT INTO users (id, email, password_hash, email_verified_at, status)
VALUES (
    gen_random_uuid(),
    'admin@example.com',
    '<PASSWORD_HASH>',
    now(),
    'active'
)
ON CONFLICT (email) DO NOTHING;

-- Assign admin role to the admin user
INSERT INTO user_roles (user_id, role_id)
SELECT u.id, r.id
FROM users u
JOIN roles r ON r.name = 'admin'
WHERE u.email = 'admin@example.com'
ON CONFLICT DO NOTHING;
