<?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('baseline_tenant_assignments', function (Blueprint $table): void {
            $table->id();
            $table->foreignId('workspace_id')->constrained('workspaces')->cascadeOnDelete();
            $table->foreignId('managed_environment_id')->constrained('managed_environments')->cascadeOnDelete();
            $table->foreignId('baseline_profile_id')->constrained('baseline_profiles')->cascadeOnDelete();
            $table->jsonb('override_scope_jsonb')->nullable();
            $table->foreignId('assigned_by_user_id')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamps();

            $table->unique(['workspace_id', 'managed_environment_id']);
            $table->index(['workspace_id', 'baseline_profile_id']);
        });
    }

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