<?php

declare(strict_types=1);

/** APO-194 Card 7 — GET /api/v1/files/video-assets/{assetId} */
final class MyronGetVideoAssetAction implements MyronAction
{
    public function __construct(private readonly MyronVideoAssetRepository $repo) {}

    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri: '/api/v1/files/video-assets/{assetId}', method: 'GET',
            domain: 'content', resource: 'video-asset', verb: 'get',
            inputSchema: ['type' => 'object', 'properties' => ['assetId' => ['type' => 'string']], 'required' => ['assetId']],
            outputSchema: ['type' => 'object', 'properties' => []],
            requiredScope: MyronApiScopes::CONTENT_READ,
            summary: 'Get a single video asset by ID with all renditions.',
            audienceClass: 3,
            snapshotInclude: false,
            exposeToMcp: true,
        );
    }

    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        $id = trim((string) ($input['assetId'] ?? ''));
        if ($id === '') return MyronActionResult::error('input_invalid', 'assetId is required.');
        $row = $this->repo->getVideoAssetById($id);
        if (!is_array($row)) return MyronActionResult::error('precondition_failed', 'Video asset not found.');
        return MyronActionResult::ok($row);
    }
}
