<?php

declare(strict_types=1);

/** GET /api/v1/administration/migrations/status */
final class MyronGetMigrationStatusAction implements MyronAction
{
    public function __construct(private readonly MyronMigrationOperationsService $service) {}

    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri: '/api/v1/administration/migrations/status',
            method: 'GET',
            domain: 'administration',
            resource: 'application-migrations',
            verb: 'status',
            inputSchema: ['type' => 'object', 'properties' => []],
            outputSchema: ['type' => 'object', 'properties' => []],
            requiredScope: MyronApiScopes::ADMINISTRATION_READ,
            summary: 'Report registered, applied, and pending application and trusted Module migrations.',
            audienceClass: 4,
            snapshotInclude: false,
            exposeToMcp: true,
            requiredCapability: 'updates.security',
        );
    }

    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        try {
            return MyronActionResult::ok($this->service->status());
        } catch (Throwable) {
            return MyronActionResult::error('migration_status_unavailable', 'Migration status is temporarily unavailable.');
        }
    }
}
