<?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('sla_violations', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id');
            $table->unsignedBigInteger('booking_id');
            $table->unsignedBigInteger('sla_metric_id')->nullable();
            $table->string('violation_type', 100)->nullable();
            $table->text('impact_description')->nullable();
            $table->decimal('penalty_amount', 12, 2)->nullable();
            $table->enum('status', ['pending', 'reviewed', 'approved', 'disputed', 'resolved'])
                ->default('pending');
            $table->timestamps();
            
            $table->foreign('tenant_id')->references('id')->on('tenants')->onDelete('cascade');
            $table->foreign('booking_id')->references('id')->on('bookings')->onDelete('cascade');
            $table->foreign('sla_metric_id')->references('id')->on('sla_metrics')->nullOnDelete();
            $table->index('tenant_id');
            $table->index('status');
        });
    }

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