<?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('uploads', function (Blueprint $table) {
            $table->string('processing_state', 32)
                ->default('pending_scan')
                ->index()
                ->after('status');
        });

        DB::table('uploads')
            ->whereNull('processing_state')
            ->update(['processing_state' => 'pending_scan']);
    }

    public function down(): void
    {
        Schema::table('uploads', function (Blueprint $table) {
            $table->dropIndex(['processing_state']);
            $table->dropColumn('processing_state');
        });
    }
};
