<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('stage_academy_course_categories', function (Blueprint $table) {
            $table->string('name_ar', 255)->nullable()->after('id');
            $table->string('name_en', 255)->nullable()->after('name_ar');
            $table->text('description_ar')->nullable()->after('name_en');
            $table->text('description_en')->nullable()->after('description_ar');
        });

        DB::table('stage_academy_course_categories')->whereNull('name_ar')->update([
            'name_ar' => DB::raw('name'),
            'name_en' => DB::raw('name'),
            'description_ar' => DB::raw('description'),
            'description_en' => DB::raw('description'),
        ]);

        Schema::table('stage_academy_course_categories', function (Blueprint $table) {
            $table->dropColumn(['name', 'description']);
        });
    }

    public function down(): void
    {
        Schema::table('stage_academy_course_categories', function (Blueprint $table) {
            $table->string('name', 255)->after('id');
            $table->text('description')->nullable()->after('name');
        });

        DB::table('stage_academy_course_categories')->update([
            'name' => DB::raw('name_en'),
            'description' => DB::raw('description_en'),
        ]);

        Schema::table('stage_academy_course_categories', function (Blueprint $table) {
            $table->dropColumn(['name_ar', 'name_en', 'description_ar', 'description_en']);
        });
    }
};
