<?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('weekly_forecasts', function (Blueprint $table) {
            $table->id();
            $table->date('forecast_for')->comment('Monday the forecast covers');
            $table->string('model_version', 64);
            $table->enum('direction', ['rising', 'falling', 'flat']);
            $table->smallInteger('magnitude_pence')->comment('Predicted Δ × 100, signed');
            $table->unsignedTinyInteger('ridge_confidence')->comment('0..100 calibrated from backtest residuals');
            $table->boolean('flagged_duty_change')->default(false)->comment('±4 weeks of a known duty change');
            $table->text('reasoning')->comment('Generated from features actually used');
            $table->dateTime('generated_at');
            $table->timestamps();

            $table->unique(['forecast_for', 'model_version']);
            $table->index(['forecast_for', 'generated_at']);
        });
    }

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