<?php

declare(strict_types=1);

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_policies', function (Blueprint $table): void {
            $table->id();
            $table->string('name');
            $table->string('priority');
            $table->integer('first_response_hours');
            $table->integer('resolution_hours');
            $table->boolean('business_hours_only')->default(true);
            $table->timestamps();
        });

        // Add FK constraint to departments now that sla_policies exists
        Schema::table('departments', function (Blueprint $table): void {
            $table->foreign('sla_policy_id')->references('id')->on('sla_policies')->nullOnDelete();
        });
    }

    public function down(): void
    {
        Schema::table('departments', function (Blueprint $table): void {
            $table->dropForeign(['sla_policy_id']);
        });

        Schema::dropIfExists('sla_policies');
    }
};
