<?php
/**
 * Admin Password Reset Script
 * Run this once to set the correct admin password, then DELETE this file!
 */

// Database connection
$host = 'localhost';
$dbname = 'safa_modest_house';
$user = 'root';
$pass = '';

try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $user, $pass);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    // Generate proper hash for Admin@123
    $password = 'Admin@123';
    $hash = password_hash($password, PASSWORD_DEFAULT);
    
    // Check if admin exists
    $stmt = $pdo->prepare("SELECT id FROM admins WHERE email = ?");
    $stmt->execute(['admin@safamodest.com']);
    $admin = $stmt->fetch();
    
    if ($admin) {
        // Update existing admin
        $stmt = $pdo->prepare("UPDATE admins SET password_hash = ? WHERE email = ?");
        $stmt->execute([$hash, 'admin@safamodest.com']);
        echo "<h2>✅ Admin password updated!</h2>";
    } else {
        // Create new admin
        $stmt = $pdo->prepare("INSERT INTO admins (full_name, email, password_hash, role) VALUES (?, ?, ?, ?)");
        $stmt->execute(['Super Admin', 'admin@safamodest.com', $hash, 'super_admin']);
        echo "<h2>✅ Admin account created!</h2>";
    }
    
    echo "<p><strong>Email:</strong> admin@safamodest.com</p>";
    echo "<p><strong>Password:</strong> Admin@123</p>";
    echo "<p style='color:red;'><strong>⚠️ DELETE THIS FILE NOW!</strong></p>";
    echo "<p><a href='admin/auth/login.php'>Go to Admin Login →</a></p>";
    
} catch (PDOException $e) {
    echo "<h2>❌ Database Error</h2>";
    echo "<p>" . $e->getMessage() . "</p>";
    echo "<p>Make sure the database exists and credentials are correct.</p>";
}
