<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * Kolom metadata gateway Duitku pada billing.
     */
    public function up(): void
    {
        Schema::table('billings', function (Blueprint $table) {
            $table->string('duitku_reference', 100)->nullable()->unique()->after('payment_method');
            $table->text('duitku_payment_url')->nullable()->after('duitku_reference');
            $table->string('duitku_payment_method', 50)->nullable()->after('duitku_payment_url');
            $table->string('duitku_status_code', 20)->nullable()->after('duitku_payment_method');
            $table->string('duitku_status_message')->nullable()->after('duitku_status_code');
            $table->timestamp('duitku_requested_at')->nullable()->after('duitku_status_message');
            $table->timestamp('duitku_callback_received_at')->nullable()->after('duitku_requested_at');
            $table->json('duitku_response')->nullable()->after('duitku_callback_received_at');
            $table->json('duitku_callback_payload')->nullable()->after('duitku_response');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('billings', function (Blueprint $table) {
            $table->dropColumn([
                'duitku_reference',
                'duitku_payment_url',
                'duitku_payment_method',
                'duitku_status_code',
                'duitku_status_message',
                'duitku_requested_at',
                'duitku_callback_received_at',
                'duitku_response',
                'duitku_callback_payload',
            ]);
        });
    }
};
