<?php

declare(strict_types=1);

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

    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri: '/api/v1/administration/license-manager/entitlement',
            method: 'GET',
            domain: 'administration',
            resource: 'license-manager',
            verb: 'get-entitlement',
            inputSchema: [
                'type' => 'object',
                'properties' => [
                    'moduleSlug' => ['type' => 'string'],
                ],
            ],
            outputSchema: [
                'type' => 'object',
                'properties' => [
                    'entitlements' => ['type' => 'array'],
                    'catalogEmpty' => ['type' => 'boolean'],
                    'serviceReachable' => ['type' => 'boolean'],
                    'stage' => ['type' => 'string'],
                ],
            ],
            requiredScope: MyronApiScopes::ADMINISTRATION_READ,
            summary: 'Read paid Module entitlement state from the local License Manager scaffold.',
            sideEffects: [],
            audienceClass: 3,
            snapshotInclude: false,
            exposeToMcp: true,
        );
    }

    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        $moduleSlug = isset($input['moduleSlug']) ? (string) $input['moduleSlug'] : null;
        return MyronActionResult::ok($this->service->getEntitlement($moduleSlug));
    }
}
