<?php

declare(strict_types=1);

/** POST /api/v1/administration/license-manager/refresh */
final class MyronRefreshModuleEntitlementsAction implements MyronAction
{
    public function __construct(private readonly MyronModuleLicenseManagerService $service) {}

    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri: '/api/v1/administration/license-manager/refresh',
            method: 'POST',
            domain: 'administration',
            resource: 'license-manager',
            verb: 'refresh-entitlements',
            inputSchema: ['type' => 'object', 'properties' => []],
            outputSchema: [
                'type' => 'object',
                'properties' => [
                    'modules' => ['type' => 'array'],
                    'catalogEmpty' => ['type' => 'boolean'],
                    'serviceReachable' => ['type' => 'boolean'],
                    'stage' => ['type' => 'string'],
                    'operatorMessage' => ['type' => 'string'],
                ],
            ],
            requiredScope: MyronApiScopes::ADMINISTRATION_WRITE,
            summary: 'Refresh paid Module entitlements through the Stage A License Manager scaffold.',
            sideEffects: [],
            audienceClass: 4,
            snapshotInclude: false,
            exposeToMcp: true,
        );
    }

    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        return MyronActionResult::ok($this->service->refreshEntitlements($caller->callerId));
    }
}
