<?php

declare(strict_types=1);

/** APO-195 Card 4 — DELETE /api/v1/content/menus/items/{menuItemId} */
final class MyronRemoveMenuItemAction implements MyronAction
{
    public function __construct(private readonly MyronMenuActionService $service) {}
    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri: '/api/v1/content/menus/items/{menuItemId}', method: 'DELETE',
            domain: 'content', resource: 'menu-item', verb: 'remove',
            inputSchema: ['type' => 'object', 'properties' => ['menuItemId' => ['type' => 'string']], 'required' => ['menuItemId']],
            outputSchema: ['type' => 'object', 'properties' => ['deleted' => ['type' => 'boolean']]],
            requiredScope: MyronApiScopes::CONTENT_WRITE,
            summary: 'Remove a menu item.',
            sideEffects: ['deletes menu_items row'], audienceClass: 4,
            adminAliases: ['remove-menu-item'], snapshotInclude: false, exposeToMcp: true,
        );
    }
    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        try { return MyronActionResult::ok($this->service->removeMenuItem((string) ($input['menuItemId'] ?? ''), $caller)); }
        catch (InvalidArgumentException $e) { return MyronActionResult::error('input_invalid', $e->getMessage()); }
        catch (Throwable $e) { return MyronActionResult::error('business_rule_failed', $e->getMessage()); }
    }
}
