<?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::create('applications', function (Blueprint $table) {
            $table->id();
            $table->foreignId('applicant_id')->constrained('applicants')->cascadeOnDelete();
            $table->foreignId('job_listing_id')->constrained('job_listings')->cascadeOnDelete();
            $table->enum('status', [
                'applied',
                'stage1_passed',
                'stage2_form_filled',
                'stage2_passed',
                'stage3_form_filled',
                'accepted',
                'rejected',
            ])->default('applied');
            $table->integer('current_stage')->default(0);
            $table->timestamp('applied_at')->useCurrent();
            $table->timestamp('stage1_passed_at')->nullable();
            $table->timestamp('stage2_filled_at')->nullable();
            $table->timestamp('stage2_passed_at')->nullable();
            $table->timestamp('stage3_filled_at')->nullable();
            $table->timestamp('final_decision_at')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('applications');
    }
};
