<?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('applications', function (Blueprint $table): void {
            if (! Schema::hasColumn('applications', 'status')) {
                $table->string('status', 40)->default('applied')->index()->after('source_attribution');
            }

            if (! Schema::hasColumn('applications', 'notes')) {
                $table->text('notes')->nullable()->after('status');
            }

            if (! Schema::hasColumn('applications', 'follow_up_at')) {
                $table->date('follow_up_at')->nullable()->index()->after('notes');
            }
        });
    }

    public function down(): void
    {
        Schema::table('applications', function (Blueprint $table): void {
            if (Schema::hasColumn('applications', 'follow_up_at')) {
                $table->dropColumn('follow_up_at');
            }

            if (Schema::hasColumn('applications', 'notes')) {
                $table->dropColumn('notes');
            }

            if (Schema::hasColumn('applications', 'status')) {
                $table->dropColumn('status');
            }
        });
    }
};
