<?php
// Include database configuration
include('config/database.php');

// Assessor credentials
$assessor_username = 'assessor';
$assessor_password = 'assessor123'; // This will be hashed
$assessor_name = 'John Doe';
$assessor_email = 'assessor@ihub.com';

// Hash the password
$hashed_password = password_hash($assessor_password, PASSWORD_DEFAULT);

// Check if assessor already exists
$check_sql = "SELECT * FROM assessors WHERE username = ?";
$check_stmt = $conn->prepare($check_sql);
$check_stmt->bind_param("s", $assessor_username);
$check_stmt->execute();
$result = $check_stmt->get_result();

if ($result->num_rows > 0) {
    echo "Assessor user already exists!<br>";
    echo "Username: " . $assessor_username . "<br>";
    echo "Password: " . $assessor_password . "<br>";
} else {
    // Insert assessor user
    $sql = "INSERT INTO assessors (username, password, name) VALUES (?, ?, ?)";
    
    if ($stmt = $conn->prepare($sql)) {
        $stmt->bind_param("sss", $assessor_username, $hashed_password, $assessor_name);
        
        if ($stmt->execute()) {
            echo "<h2>✅ Assessor User Created Successfully!</h2>";
            echo "<div style='background: #f8f9fa; padding: 20px; border-radius: 8px; margin: 20px 0;'>";
            echo "<h3>Login Credentials:</h3>";
            echo "<p><strong>Username:</strong> " . $assessor_username . "</p>";
            echo "<p><strong>Password:</strong> " . $assessor_password . "</p>";
            echo "<p><strong>Name:</strong> " . $assessor_name . "</p>";

            echo "</div>";
            echo "<p><a href='login.php' style='color: #2c2b7c; text-decoration: none;'>← Go to Login Page</a></p>";
        } else {
            echo "Error creating assessor user: " . $stmt->error;
        }
        $stmt->close();
    } else {
        echo "Error preparing statement: " . $conn->error;
    }
}

$check_stmt->close();
$conn->close();
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Create Assessor User</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            max-width: 600px;
            margin: 50px auto;
            padding: 20px;
            background: #f5f5f5;
        }
        h2 {
            color: #333;
            text-align: center;
        }
        .credentials {
            background: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            margin: 20px 0;
        }
        .warning {
            background: #fff3cd;
            border: 1px solid #ffeaa7;
            color: #856404;
            padding: 15px;
            border-radius: 5px;
            margin: 20px 0;
        }
    </style>
</head>
<body>
    <div class="warning">
        <strong>⚠️ Security Notice:</strong> Please delete this file (create_assessor.php) after creating the assessor user for security purposes.
    </div>
</body>
</html>
