<?php
declare(strict_types=1);

require_once __DIR__ . '/../_bootstrap.php';

golder_portal_session_start();

function golder_portal_api_payload(): array
{
    $json = golder_read_json_body();
    if ($json) {
        return $json;
    }
    return $_POST;
}

function golder_portal_api_require_login(PDO $master): array
{
    $userId = golder_portal_current_user_id();
    if ($userId <= 0) {
        golder_json_error(401, 'UNAUTHORIZED', 'Portal login is required.');
    }
    $user = golder_portal_user_by_id($master, $userId);
    if (!$user || (int)($user['is_active'] ?? 0) !== 1) {
        golder_json_error(401, 'UNAUTHORIZED', 'Portal session is invalid.');
    }
    return $user;
}








