-- ============================================
-- Query to Get All Users with Emails and Password Hashes
-- ============================================
-- Run this in phpMyAdmin or your MySQL client
-- This will show all users with their email and password hash

SELECT 
    id,
    name,
    email,
    password AS password_hash,
    contactNumber,
    role,
    isActive,
    passwordSet,
    isEmailVerified,
    isPhoneVerified,
    createdAt
FROM users
ORDER BY 
    CASE role
        WHEN 'admin' THEN 1
        WHEN 'manager' THEN 2
        WHEN 'supplier' THEN 3
        WHEN 'workshop' THEN 4
        WHEN 'customer' THEN 5
        ELSE 6
    END,
    createdAt DESC;

-- ============================================
-- Separate Queries by Role
-- ============================================

-- ADMIN & MANAGER USERS
SELECT 
    'ADMIN/MANAGER' AS user_type,
    id,
    name,
    email,
    password AS password_hash,
    contactNumber,
    role,
    isActive,
    passwordSet,
    createdAt
FROM users
WHERE role IN ('admin', 'manager')
ORDER BY createdAt DESC;

-- SUPPLIER USERS
SELECT 
    'SUPPLIER' AS user_type,
    id,
    name,
    email,
    password AS password_hash,
    contactNumber,
    role,
    isActive,
    passwordSet,
    createdAt
FROM users
WHERE role = 'supplier'
ORDER BY createdAt DESC;

-- CUSTOMER USERS
SELECT 
    'CUSTOMER' AS user_type,
    id,
    name,
    email,
    password AS password_hash,
    contactNumber,
    role,
    isActive,
    passwordSet,
    createdAt
FROM users
WHERE role = 'customer'
ORDER BY createdAt DESC;

-- WORKSHOP USERS
SELECT 
    'WORKSHOP' AS user_type,
    id,
    name,
    email,
    password AS password_hash,
    contactNumber,
    role,
    isActive,
    passwordSet,
    createdAt
FROM users
WHERE role = 'workshop'
ORDER BY createdAt DESC;

-- ============================================
-- NOTE ABOUT PASSWORDS:
-- ============================================
-- Passwords are stored as bcrypt hashes (60 characters, starts with $2a$10$)
-- You cannot see the plain text password, only the hash.
-- 
-- Common default password hashes:
-- Password "admin123" hash: $2a$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy
-- 
-- To verify a password matches a hash, use bcrypt.compare() or an online tool.
-- To reset a password, generate a new hash at: https://bcrypt-generator.com/
-- ============================================
