<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('c2_seedlab_beneficiaries', function (Blueprint $table) {
            // Drop old module columns (no longer needed)
            $table->dropColumn([
                'module_1', 'module_2', 'module_3', 'module_4',
                'module_5', 'module_6', 'module_7', 'module_8'
            ]);

            // Add Bootcamp modules after 'education_level' for logical order
            for ($i = 1; $i <= 5; $i++) {
                $table->enum("bootcamp_module_{$i}", ['Not Completed', 'Completed'])
                    ->default('Not Completed')
                    ->after('education_level');
            }

            // Add Pitch fields
            $table->enum('pitch_presentation', ['Not Completed', 'Completed'])
                ->default('Not Completed')
                ->after('bootcamp_module_5');
            $table->enum('pitch_outcome', ['Failed', 'Passed'])
                ->nullable()
                ->after('pitch_presentation');

            // Add Accelerator modules (nullable for non-participants)
            for ($i = 1; $i <= 10; $i++) {
                $table->enum("accelerator_module_{$i}", ['Failed', 'Passed'])
                    ->nullable()
                    ->after($i === 1 ? 'pitch_outcome' : "accelerator_module_" . ($i - 1));
            }
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('c2_seedlab_beneficiaries', function (Blueprint $table) {
            // Re-add old columns if rolling back (with original enums)
            for ($i = 1; $i <= 8; $i++) {
                $table->enum("module_{$i}", ['Not Started', 'Ongoing', 'Completed'])
                    ->default('Not Started')
                    ->after('education_level');
            }

            // Drop new columns
            $columns = [];
            for ($i = 1; $i <= 5; $i++) {
                $columns[] = "bootcamp_module_{$i}";
            }
            $columns[] = 'pitch_presentation';
            $columns[] = 'pitch_outcome';
            for ($i = 1; $i <= 10; $i++) {
                $columns[] = "accelerator_module_{$i}";
            }
            $table->dropColumn($columns);
        });
    }
};