<?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
    {
        Schema::table('order_courier_shipments', function (Blueprint $table) {
            if (! Schema::hasColumn('order_courier_shipments', 'actual_delivery_cost')) {
                $table->decimal('actual_delivery_cost', 24, 8)->nullable()->after('collectable_amount');
            }

            if (! Schema::hasColumn('order_courier_shipments', 'actual_return_cost')) {
                $table->decimal('actual_return_cost', 24, 8)->nullable()->after('actual_delivery_cost');
            }

            if (! Schema::hasColumn('order_courier_shipments', 'actual_cod_charge')) {
                $table->decimal('actual_cod_charge', 24, 8)->nullable()->after('actual_return_cost');
            }
        });
    }

    public function down(): void
    {
        Schema::table('order_courier_shipments', function (Blueprint $table) {
            foreach (['actual_delivery_cost', 'actual_return_cost', 'actual_cod_charge'] as $column) {
                if (Schema::hasColumn('order_courier_shipments', $column)) {
                    $table->dropColumn($column);
                }
            }
        });
    }
};
