<?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('provider_connections', function (Blueprint $table): void {
            $table->dropIndex(['managed_environment_id', 'provider', 'status']);
            $table->dropIndex(['managed_environment_id', 'provider', 'health_status']);
            $table->dropIndex(['workspace_id', 'provider', 'status']);
            $table->dropIndex(['workspace_id', 'provider', 'health_status']);
            $table->dropColumn(['status', 'health_status']);
        });
    }

    public function down(): void
    {
        Schema::table('provider_connections', function (Blueprint $table): void {
            $table->string('status')->default('needs_consent');
            $table->string('health_status')->default('unknown');
            $table->index(['managed_environment_id', 'provider', 'status']);
            $table->index(['managed_environment_id', 'provider', 'health_status']);
            $table->index(['workspace_id', 'provider', 'status']);
            $table->index(['workspace_id', 'provider', 'health_status']);
        });
    }
};
