<?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('orders') || Schema::hasColumn('orders', 'pos_idempotency_key')) {
            return;
        }

        Schema::table('orders', function (Blueprint $table) {
            $table->string('pos_idempotency_key', 160)->nullable()->unique()->after('sale_channel');
        });
    }

    public function down(): void
    {
        if (! Schema::hasTable('orders') || ! Schema::hasColumn('orders', 'pos_idempotency_key')) {
            return;
        }

        Schema::table('orders', function (Blueprint $table) {
            $table->dropColumn('pos_idempotency_key');
        });
    }
};
