<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('tier_assessments', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->foreignId('previous_tier_id')->constrained('tiers');
            $table->foreignId('recommended_tier_id')->constrained('tiers');
            $table->foreignId('new_tier_id')->nullable()->constrained('tiers')->nullOnDelete();
            $table->enum('status', ['pending', 'actioned', 'dismissed'])->default('pending');
            $table->enum('trigger', ['auto_suggest', 'manual', 'quarterly'])->default('quarterly');
            $table->foreignId('actioned_by')->nullable()->constrained('admins')->nullOnDelete();
            $table->text('reason')->nullable();
            $table->timestamp('assessed_at');
            $table->timestamp('actioned_at')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('tier_assessments');
    }
};
