<?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('main_categories', function (Blueprint $table) {
            $table->string('name_ar', 255)->nullable()->after('id');
            $table->string('name_en', 255)->nullable()->after('name_ar');
        });

        DB::table('main_categories')->whereNull('name_ar')->update([
            'name_ar' => DB::raw('name'),
            'name_en' => DB::raw('name'),
        ]);

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

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

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

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