<?php
// require_once __DIR__ . '/../utils/jwt.php'; // Iski zaroorat nahi hai ab

function authenticate() {
    /*
    $headers = getallheaders();
    $authHeader = isset($headers['Authorization']) ? $headers['Authorization'] : 
                 (isset($headers['authorization']) ? $headers['authorization'] : null);

    if (!$authHeader) {
        http_response_code(401);
        echo json_encode(['success' => false, 'message' => 'No authorization header found']);
        exit();
    }

    if (!preg_match('/Bearer\s(\S+)/', $authHeader, $matches)) {
        http_response_code(401);
        echo json_encode(['success' => false, 'message' => 'Invalid authorization header format']);
        exit();
    }

    $jwt = $matches[1];
    $decoded = JWT::decode($jwt);

    if (!$decoded) {
        http_response_code(401);
        echo json_encode(['success' => false, 'message' => 'Invalid or expired token']);
        exit();
    }

    return $decoded;
    */
    
    // Auth bypass: Testing ke liye hum dummy data return kar sakte hain
    return ['user_id' => 1, 'role' => 'admin'];
}

function requireAdmin() {
    /*
    $user = authenticate();
    
    if ($user['role'] !== 'admin') {
        http_response_code(403);
        echo json_encode(['success' => false, 'message' => 'Admin access required']);
        exit();
    }

    return $user;
    */
    return ['user_id' => 1, 'role' => 'admin'];
}

function optionalAuth() {
    /*
    $headers = getallheaders();
    $authHeader = isset($headers['Authorization']) ? $headers['Authorization'] : 
                 (isset($headers['authorization']) ? $headers['authorization'] : null);

    if (!$authHeader) {
        return null;
    }

    if (!preg_match('/Bearer\s(\S+)/', $authHeader, $matches)) {
        return null;
    }

    $jwt = $matches[1];
    $decoded = JWT::decode($jwt);

    return $decoded ?: null;
    */
    return null;
}
?>