-- Quick Admin User Creation Script
-- This script creates or updates an admin user for the EFL system
-- Default credentials: admin / admin123

-- First, let's create a hashed password for 'admin123'
-- Hash: $2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi

-- Insert or update admin user
INSERT INTO users (
    username,
    email,
    password,
    first_name,
    last_name,
    role,
    status,
    is_super_admin,
    created_at,
    updated_at
) VALUES (
    'admin',
    'admin@efl.local',
    '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi',
    'System',
    'Administrator',
    'admin',
    'active',
    1,
    NOW(),
    NOW()
)
ON DUPLICATE KEY UPDATE
    password = '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi',
    status = 'active',
    is_super_admin = 1,
    updated_at = NOW();

-- Alternative: Just update password for existing admin user
-- UPDATE users 
-- SET password = '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi',
--     status = 'active'
-- WHERE username = 'admin';

-- Verify the admin user was created/updated
SELECT id, username, email, role, status, is_super_admin 
FROM users 
WHERE username = 'admin';

-- Insert other school users: HR, Storekeeper, Librarian, ICT Technician, Gatekeeper
INSERT INTO users (username, email, password, first_name, last_name, role, status, is_super_admin, created_at, updated_at)
VALUES
('hr', 'hr@efl.local', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'HR', 'User', 'hr-staff', 'active', 0, NOW(), NOW()),
('storekeeper', 'storekeeper@efl.local', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'Store', 'Keeper', 'storekeeper', 'active', 0, NOW(), NOW()),
('librarian', 'librarian@efl.local', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'Library', 'Staff', 'librarian', 'active', 0, NOW(), NOW()),
('ict', 'ict@efl.local', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'ICT', 'Technician', 'ict-technician', 'active', 0, NOW(), NOW()),
('gatekeeper', 'gatekeeper@efl.local', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'Gate', 'Keeper', 'gatekeeper', 'active', 0, NOW(), NOW())
ON DUPLICATE KEY UPDATE
    password = VALUES(password),
    role = VALUES(role),
    status = VALUES(status),
    updated_at = NOW();
