<?php

use MintyPHP\Module\Helpdesk\HelpdeskAuthorizationPolicy;
use MintyPHP\Module\Helpdesk\Service\DebitorDetailService;
use MintyPHP\Router;
use MintyPHP\Support\Guard;

Guard::requireLogin();
Guard::requireAbilityOrForbidden(HelpdeskAuthorizationPolicy::ABILITY_ACCESS);

$request = requestInput();
if ($request->method() !== 'GET') {
    http_response_code(405);
    Router::json(['ok' => false, 'error' => 'method_not_allowed']);

    return;
}

$ticketNo = trim((string) $request->query('ticketNo', ''));

if ($ticketNo === '') {
    http_response_code(400);
    Router::json(['ok' => false, 'error' => 'missing_parameters']);

    return;
}

$service = app(DebitorDetailService::class);
$result = $service->loadTicketLog($ticketNo);

Router::json($result);
