<?php

declare(strict_types=1);

namespace App\Command;

use App\Vector\VectorIndexHealthService;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
    name: 'mto:agent:vector:health',
    description: 'Health-Check für NDJSON/FAISS Konsistenz'
)]
final class VectorHealthCheckCommand extends Command
{
    public function __construct(
        private VectorIndexHealthService $health
    ) {
        parent::__construct();
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $result = $this->health->check();

        $output->writeln(json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));

        return str_starts_with($result['status'], 'OK')
            ? Command::SUCCESS
            : Command::FAILURE;
    }
}
