<?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
    {
        if (! Schema::hasTable('policies') || Schema::hasColumn('policies', 'missing_from_provider_at')) {
            return;
        }

        Schema::table('policies', function (Blueprint $table): void {
            $table->timestamp('missing_from_provider_at')->nullable()->after('ignored_at');
            $table->index('missing_from_provider_at');
        });
    }

    public function down(): void
    {
        if (! Schema::hasTable('policies') || ! Schema::hasColumn('policies', 'missing_from_provider_at')) {
            return;
        }

        Schema::table('policies', function (Blueprint $table): void {
            $table->dropIndex(['missing_from_provider_at']);
            $table->dropColumn('missing_from_provider_at');
        });
    }
};
