<?php

declare(strict_types=1);

/** APO-195 Card 3 — POST /api/v1/content/categories/{categoryId}/reactivate */
final class MyronReactivateCategoryAction implements MyronAction
{
    public function __construct(private readonly MyronCategoryActionService $service) {}
    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri: '/api/v1/content/categories/{categoryId}/reactivate', method: 'POST',
            domain: 'content', resource: 'category', verb: 'reactivate',
            inputSchema: ['type' => 'object', 'properties' => ['categoryId' => ['type' => 'string']], 'required' => ['categoryId']],
            outputSchema: ['type' => 'object', 'properties' => ['isActive' => ['type' => 'boolean']]],
            requiredScope: MyronApiScopes::CONTENT_WRITE,
            summary: 'Reactivate an archived category (sets is_active=1).',
            sideEffects: ['updates page_categories.is_active'], audienceClass: 4,
            adminAliases: ['reactivate-category'], snapshotInclude: false, exposeToMcp: true,
        );
    }
    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        try { return MyronActionResult::ok($this->service->reactivate((string) ($input['categoryId'] ?? ''), $caller)); }
        catch (InvalidArgumentException $e) { return MyronActionResult::error('input_invalid', $e->getMessage()); }
        catch (Throwable $e) { return MyronActionResult::error('business_rule_failed', $e->getMessage()); }
    }
}
