<?php

declare(strict_types=1);

/** APO-195 Card 4 — POST /api/v1/content/menus */
final class MyronCreateMenuAction implements MyronAction
{
    public function __construct(private readonly MyronMenuActionService $service) {}
    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri: '/api/v1/content/menus', method: 'POST',
            domain: 'content', resource: 'menu', verb: 'create',
            inputSchema: ['type' => 'object', 'properties' => ['name' => ['type' => 'string']], 'required' => ['name']],
            outputSchema: ['type' => 'object', 'properties' => ['menuId' => ['type' => 'string']]],
            requiredScope: MyronApiScopes::CONTENT_WRITE,
            summary: 'Create a new menu (named container for menu items).',
            sideEffects: ['inserts menus row'], audienceClass: 4,
            adminAliases: ['create-menu'], snapshotInclude: false, exposeToMcp: true,
        );
    }
    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        try { return MyronActionResult::ok($this->service->createMenu((string) ($input['name'] ?? ''), $caller)); }
        catch (InvalidArgumentException $e) { return MyronActionResult::error('input_invalid', $e->getMessage()); }
        catch (Throwable $e) { return MyronActionResult::error('business_rule_failed', $e->getMessage()); }
    }
}
