-- First, let's delete the existing admin user with incorrect hash
DELETE FROM users WHERE username = 'admin';

-- Create the admin user with proper password hashes
INSERT INTO users (first_name, last_name, username, password, api_username, api_password, is_active)
VALUES (
    'Admin',
    'User',
    'admin',
    '$argon2id$v=19$m=65536,t=4,p=1$MlVtLmZGRi5ZWk5JYXNaWA$z3puq0C5VqB4dXDQxIO5r2NKYeoRQ2zhZoQQHUB+G8k',  -- Password: Admin@123!
    'admin_api',
    '$argon2id$v=19$m=65536,t=4,p=1$YVNaWC5ZWk5JLmZGRi5t$8f9qG3jX2q5vB1kX9Z2m4Y6nR7pL0wK9jD8vN2H+M1k',  -- Password: ApiAdmin@123!
    1
);

-- Create the admin permission if it doesn't exist
INSERT INTO permissions (permission_name, permission_description)
SELECT 'admin', 'Full administrative access'
WHERE NOT EXISTS (
    SELECT 1 FROM permissions WHERE permission_name = 'admin'
);

-- Assign admin permission to the admin user
INSERT INTO user_permissions (user_id, permission_id)
SELECT u.id, p.id
FROM users u, permissions p
WHERE u.username = 'admin'
AND p.permission_name = 'admin'; 