<?php

use MintyPHP\Http\SessionStoreInterface;
use MintyPHP\Module\Helpdesk\HelpdeskAuthorizationPolicy;
use MintyPHP\Module\Helpdesk\Service\DomainListService;
use MintyPHP\Support\Guard;

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

$session = app(SessionStoreInterface::class)->all();
$tenantId = (int) ($session['current_tenant']['id'] ?? 0);

$filters = gridParseFiltersFromSchemaFile(__DIR__ . '/domains/filter-schema.php');
$filters['limit'] = (int) ($filters['limit'] ?? 10);
$filters['offset'] = (int) ($filters['offset'] ?? 0);

$result = app(DomainListService::class)->query($tenantId, $filters);

gridJsonDataResult($result['rows'], $result['total']);
