<?php

declare(strict_types=1);

/** APO-194 Card 7 — GET /api/v1/files */
final class MyronListFilesAction implements MyronAction
{
    public function __construct(private readonly MyronFileRepository $repo) {}

    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri: '/api/v1/files', method: 'GET',
            domain: 'content', resource: 'file', verb: 'list',
            inputSchema: [
                'type' => 'object',
                'properties' => ['mediaClass' => ['type' => 'string']],
            ],
            outputSchema: ['type' => 'object', 'properties' => ['items' => ['type' => 'array']]],
            requiredScope: MyronApiScopes::CONTENT_READ,
            summary: 'List uploaded files; optional mediaClass filter (image|document|video).',
            audienceClass: 3,
            snapshotInclude: true, snapshotKey: 'content.files',
            exposeToMcp: true,
        );
    }

    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        $mc = trim((string) ($input['mediaClass'] ?? ''));
        $items = $mc !== '' ? $this->repo->listFilesByMediaClass($mc) : $this->repo->listFiles();
        return MyronActionResult::ok(['items' => $items]);
    }
}
