<?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('items') && ! Schema::hasColumn('items', 'weight_kg')) {
            Schema::table('items', function (Blueprint $table) {
                $table->decimal('weight_kg', 10, 3)->nullable()->after('item_packaging_charge');
            });
        }

        if (Schema::hasTable('temp_products') && ! Schema::hasColumn('temp_products', 'weight_kg')) {
            Schema::table('temp_products', function (Blueprint $table) {
                $table->decimal('weight_kg', 10, 3)->nullable()->after('maximum_cart_quantity');
            });
        }
    }

    public function down(): void
    {
        if (Schema::hasTable('items') && Schema::hasColumn('items', 'weight_kg')) {
            Schema::table('items', function (Blueprint $table) {
                $table->dropColumn('weight_kg');
            });
        }

        if (Schema::hasTable('temp_products') && Schema::hasColumn('temp_products', 'weight_kg')) {
            Schema::table('temp_products', function (Blueprint $table) {
                $table->dropColumn('weight_kg');
            });
        }
    }
};
