<?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::table('managed_environments', function (Blueprint $table) {
            $table->string('rbac_group_id')->nullable()->after('metadata');
            $table->string('rbac_role_assignment_id')->nullable()->after('rbac_group_id');
            $table->string('rbac_role_key')->nullable()->after('rbac_role_assignment_id');
            $table->string('rbac_scope_mode')->nullable()->after('rbac_role_key');
            $table->string('rbac_scope_id')->nullable()->after('rbac_scope_mode');

            $table->index(['rbac_group_id', 'rbac_role_assignment_id'], 'managed_environments_rbac_artifacts_idx');
        });
    }

    public function down(): void
    {
        Schema::table('managed_environments', function (Blueprint $table) {
            $table->dropIndex('managed_environments_rbac_artifacts_idx');
            $table->dropColumn([
                'rbac_group_id',
                'rbac_role_assignment_id',
                'rbac_role_key',
                'rbac_scope_mode',
                'rbac_scope_id',
            ]);
        });
    }
};
