<?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::create('transactions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('order_id')->constrained('orders')->cascadeOnDelete();
            $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
            $table->string('gateway');
            $table->string('gateway_name')->nullable();
            $table->unsignedBigInteger('amount')->default(0);
            $table->enum('status', ['pending', 'success', 'failed'])->default('pending');
            $table->string('track_id')->nullable();
            $table->string('ref_number')->nullable();
            $table->string('card_number')->nullable();
            $table->json('gateway_response')->nullable();
            $table->string('error_code')->nullable();
            $table->string('error_message')->nullable();
            $table->timestamp('paid_at')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('transactions');
    }
};
