<?php

declare(strict_types=1);

require_once "../db.php";
require_once "./customer_auth_common.php";

error_reporting(E_ERROR | E_PARSE);
ini_set("display_errors", "0");

if (($_SERVER["REQUEST_METHOD"] ?? "") !== "GET") {
    customerAuthJsonResponse(405, [
        "success" => false,
        "message" => "Method not allowed",
    ]);
}

$token = customerAuthExtractBearerToken();
$session = customerAuthGetSessionUser($conn, $token);

if (!$session) {
    customerAuthJsonResponse(401, [
        "success" => false,
        "message" => "Session is invalid or expired.",
    ]);
}

customerAuthJsonResponse(200, [
    "success" => true,
    "user" => [
        "id" => $session["user_id"],
        "name" => $session["name"],
        "email" => $session["email"],
        "role" => $session["role"],
    ],
    "expiresAt" => $session["expires_at"],
]);

