<?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('class_progress_reports')) {
            return;
        }

        Schema::table('class_progress_reports', function (Blueprint $table) {
            if (! Schema::hasColumn('class_progress_reports', 'school_year')) {
                $table->string('school_year', 20)->nullable()->after('teacher_id')->index();
            }
            if (! Schema::hasColumn('class_progress_reports', 'semester')) {
                $table->string('semester', 20)->nullable()->after('school_year')->index();
            }
        });
    }

    public function down(): void
    {
        if (! Schema::hasTable('class_progress_reports')) {
            return;
        }

        Schema::table('class_progress_reports', function (Blueprint $table) {
            if (Schema::hasColumn('class_progress_reports', 'semester')) {
                $table->dropColumn('semester');
            }
            if (Schema::hasColumn('class_progress_reports', 'school_year')) {
                $table->dropColumn('school_year');
            }
        });
    }
};
