<?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('serenatas', function (Blueprint $table) {
            if (Schema::hasColumn('serenatas', 'iva_rate')) {
                $table->dropColumn('iva_rate');
            }
            if (Schema::hasColumn('serenatas', 'iva_amount')) {
                $table->dropColumn('iva_amount');
            }
        });
    }

    public function down(): void
    {
        Schema::table('serenatas', function (Blueprint $table) {
            if (!Schema::hasColumn('serenatas', 'iva_rate')) {
                $table->decimal('iva_rate', 5, 2)->default(0)->after('commission_amount');
            }
            if (!Schema::hasColumn('serenatas', 'iva_amount')) {
                $table->decimal('iva_amount', 12, 2)->default(0)->after('iva_rate');
            }
        });
    }
};
