<?php

declare(strict_types=1);

final class MicTableDeleteAction implements MyronAction
{
    public function __construct(private readonly MicTableService $service)
    {
    }

    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata(
            uri: '/api/v1/content/tables/{tableId}',
            method: 'DELETE',
            domain: 'content.tables',
            resource: 'table',
            verb: 'delete',
            inputSchema: ['type' => 'object', 'properties' => ['tableId' => ['type' => 'string']], 'required' => ['tableId']],
            outputSchema: ['type' => 'object', 'properties' => ['tableId' => ['type' => 'string'], 'deleted' => ['type' => 'boolean']]],
            requiredScope: MyronApiScopes::CONTENT_WRITE,
            summary: 'Delete a reusable Content Bank table.',
            sideEffects: ['deletes mic_tables row'],
            audienceClass: 4,
            adminAliases: ['tables.delete'],
            exposeToMcp: true,
        );
    }

    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        try {
            return MyronActionResult::ok($this->service->delete((string) ($input['tableId'] ?? '')));
        } catch (InvalidArgumentException $e) {
            return MyronActionResult::error('precondition_failed', $e->getMessage());
        }
    }
}

