<?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('alert_rule_destinations', function (Blueprint $table): void {
            $table->id();
            $table->foreignId('workspace_id')->constrained()->cascadeOnDelete();
            $table->foreignId('alert_rule_id')->constrained()->cascadeOnDelete();
            $table->foreignId('alert_destination_id')->constrained()->cascadeOnDelete();
            $table->timestamps();

            $table->unique(['alert_rule_id', 'alert_destination_id']);
            $table->index(['workspace_id', 'alert_rule_id']);
        });
    }

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