<?php

declare(strict_types=1);

/** APO-195 Card 7 — GET /api/v1/content/categories */
final class MyronListCategoriesAction implements MyronAction
{
    public function __construct(private readonly MyronContentRepository $repo) {}
    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri: '/api/v1/content/categories', method: 'GET',
            domain: 'content', resource: 'category', verb: 'list',
            inputSchema: ['type' => 'object', 'properties' => ['activeOnly' => ['type' => 'boolean']]],
            outputSchema: ['type' => 'object', 'properties' => ['items' => ['type' => 'array']]],
            requiredScope: MyronApiScopes::CONTENT_READ,
            summary: 'List page categories. Optional activeOnly flag (default false; include archived).',
            audienceClass: 3,
            snapshotInclude: true, snapshotKey: 'content.categories',
            exposeToMcp: true,
        );
    }
    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        $activeOnly = (bool) ($input['activeOnly'] ?? false);
        return MyronActionResult::ok(['items' => $this->repo->listPageCategories($activeOnly)]);
    }
}
