<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('platform_accounts', function (Blueprint $table) {
            $table->unsignedTinyInteger('consecutive_failures')->default(0)->after('status');
        });

        DB::table('platform_accounts')->where('status', 'active')->update(['status' => 'healthy']);
    }

    public function down(): void
    {
        // Not a true inverse: accounts the health check marked healthy also become 'active'.
        DB::table('platform_accounts')->where('status', 'healthy')->update(['status' => 'active']);

        Schema::table('platform_accounts', function (Blueprint $table) {
            $table->dropColumn('consecutive_failures');
        });
    }
};
