<?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('gmail_sell_settings') && !Schema::hasColumn('gmail_sell_settings', 'admin_price')) {
            Schema::table('gmail_sell_settings', function (Blueprint $table) {
                $table->decimal('admin_price', 12, 2)->default(0)->after('price');
            });
        }

        if (Schema::hasTable('gmail_sales') && !Schema::hasColumn('gmail_sales', 'admin_price')) {
            Schema::table('gmail_sales', function (Blueprint $table) {
                $table->decimal('admin_price', 12, 2)->nullable()->after('rate');
            });
        }
    }

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

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