<?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('entra_groups', function (Blueprint $table) {
            $table->id();

            $table->foreignId('managed_environment_id')->constrained()->cascadeOnDelete();

            $table->uuid('entra_id');
            $table->string('display_name');
            $table->jsonb('group_types')->nullable();
            $table->boolean('security_enabled')->default(false);
            $table->boolean('mail_enabled')->default(false);

            $table->timestampTz('last_seen_at')->nullable();

            $table->timestamps();

            $table->unique(['managed_environment_id', 'entra_id']);
            $table->index(['managed_environment_id', 'display_name']);
            $table->index(['managed_environment_id', 'last_seen_at']);
        });
    }

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