<?php

namespace App\Console\Commands;

use App\Services\Forecasting\VolatilityRegimeService;
use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
use Illuminate\Console\Command;

#[Signature('forecast:evaluate-volatility')]
#[Description('Evaluate the volatility regime triggers and update volatility_regimes accordingly. Hourly cron.')]
class EvaluateVolatilityRegime extends Command
{
    public function handle(VolatilityRegimeService $service): int
    {
        $regime = $service->evaluate();

        if ($regime === null) {
            $this->info('Volatility regime: OFF');
        } else {
            $this->info(sprintf(
                'Volatility regime: ON (trigger=%s, since %s)',
                $regime->trigger,
                $regime->flipped_on_at->toIso8601String(),
            ));
        }

        return self::SUCCESS;
    }
}
