<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('policy_versions', function (Blueprint $table) {
            $table->json('assignments')->nullable()->after('metadata');
            $table->json('scope_tags')->nullable()->after('assignments');
            $table->string('assignments_hash', 64)->nullable()->after('scope_tags');
            $table->string('scope_tags_hash', 64)->nullable()->after('assignments_hash');

            $table->index('assignments_hash');
            $table->index('scope_tags_hash');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('policy_versions', function (Blueprint $table) {
            $table->dropIndex(['assignments_hash']);
            $table->dropIndex(['scope_tags_hash']);
            $table->dropColumn(['assignments', 'scope_tags', 'assignments_hash', 'scope_tags_hash']);
        });
    }
};
