<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('llm_overlays', function (Blueprint $table) {
            $table->id();
            $table->dateTime('ran_at');
            $table->date('forecast_for_week')->comment('The Monday this overlay annotates');
            $table->enum('direction', ['rising', 'falling', 'flat']);
            $table->unsignedTinyInteger('confidence')->comment('0..75 (cap enforced in code — web-searched LLMs are systematically overconfident)');
            $table->text('reasoning');
            $table->json('events_json')->comment('Cited events with verified URLs');
            $table->boolean('agrees_with_ridge');
            $table->boolean('major_impact_event')->default(false);
            $table->boolean('volatility_flag_on')->default(false)->comment('Whether the volatility regime flag was active when this row was written');
            $table->boolean('search_used')->default(true);
            $table->timestamps();

            $table->index(['forecast_for_week', 'ran_at']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('llm_overlays');
    }
};
