<?php

declare(strict_types=1);

/** APO-195 Card 3 — POST /api/v1/content/categories/{categoryId}/archive */
final class MyronArchiveCategoryAction implements MyronAction
{
    public function __construct(private readonly MyronCategoryActionService $service) {}
    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri: '/api/v1/content/categories/{categoryId}/archive', method: 'POST',
            domain: 'content', resource: 'category', verb: 'archive',
            inputSchema: ['type' => 'object', 'properties' => ['categoryId' => ['type' => 'string']], 'required' => ['categoryId']],
            outputSchema: ['type' => 'object', 'properties' => ['isActive' => ['type' => 'boolean']]],
            requiredScope: MyronApiScopes::CONTENT_WRITE,
            summary: 'Archive a category (sets is_active=0; preserves history; hidden from operator pickers).',
            sideEffects: ['updates page_categories.is_active'], audienceClass: 4,
            adminAliases: ['archive-category'], snapshotInclude: false, exposeToMcp: true,
        );
    }
    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        try { return MyronActionResult::ok($this->service->archive((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()); }
    }
}
