<?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('transactions', function (Blueprint $table) {
            $table->string('provider')->nullable()->after('payment_method');
            $table->string('provider_order_number')->nullable()->unique()->after('payment_reference');
            $table->string('provider_transaction_id')->nullable()->after('provider_order_number');
            $table->json('provider_payload')->nullable()->after('provider_transaction_id');
            $table->timestamp('approved_at')->nullable()->after('provider_payload');
            $table->timestamp('rejected_at')->nullable()->after('approved_at');
        });
    }

    public function down(): void
    {
        Schema::table('transactions', function (Blueprint $table) {
            $table->dropUnique(['provider_order_number']);
            $table->dropColumn([
                'provider',
                'provider_order_number',
                'provider_transaction_id',
                'provider_payload',
                'approved_at',
                'rejected_at',
            ]);
        });
    }
};
