<?php
declare(strict_types=1);

require_once __DIR__ . '/_bootstrap.php';

golder_require_method('GET');
$master = golder_master_pdo();
$user = golder_portal_api_require_login($master);
$userId = (int)($user['id'] ?? 0);

$type = strtolower(trim((string)($_GET['type'] ?? 'payment')));
$requestId = trim((string)($_GET['id'] ?? ''));
if ($requestId === '') {
    golder_json_error(400, 'INVALID_REQUEST', 'id is required.');
}

if ($type === 'demo') {
    $row = golder_demo_request_detail_for_portal($master, $userId, $requestId);
    if (!$row) {
        golder_json_error(404, 'NOT_FOUND', 'Demo request not found.');
    }
    golder_json_response([
        'status' => 'ok',
        'type' => 'demo',
        'item' => $row,
    ]);
}

if ($type === 'support') {
    $row = golder_support_thread_detail_for_portal($master, $userId, $requestId);
    if (!$row) {
        golder_json_error(404, 'NOT_FOUND', 'Support thread not found.');
    }
    golder_json_response([
        'status' => 'ok',
        'type' => 'support',
        'item' => $row,
    ]);
}

$row = golder_payment_request_detail_for_portal($master, $userId, $requestId);
if (!$row) {
    golder_json_error(404, 'NOT_FOUND', 'Payment request not found.');
}
golder_json_response([
    'status' => 'ok',
    'type' => 'payment',
    'item' => $row,
]);


