<?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::hasColumn('courses', 'start_date')) {
            Schema::table('courses', function (Blueprint $table) {
                $table->date('start_date')->nullable()->after('status');
            });
        }

        if (! Schema::hasColumn('courses', 'expire_date')) {
            Schema::table('courses', function (Blueprint $table) {
                $table->date('expire_date')->nullable()->after('start_date');
            });
        }

        if (! Schema::hasColumn('users', 'is_active')) {
            Schema::table('users', function (Blueprint $table) {
                $table->boolean('is_active')->default(true)->after('remember_token');
            });
        }
    }

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

        if (Schema::hasColumn('courses', 'start_date')) {
            Schema::table('courses', function (Blueprint $table) {
                $table->dropColumn('start_date');
            });
        }

        if (Schema::hasColumn('users', 'is_active')) {
            Schema::table('users', function (Blueprint $table) {
                $table->dropColumn('is_active');
            });
        }
    }
};
