<?php

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

return new class extends Migration
{
    /**
     * Tabel riwayat pembayaran.
     * order_id dikirim frontend ke payment gateway;
     * webhook gateway akan mengupdate status pembayaran di sini.
     */
    public function up(): void
    {
        Schema::create('payments', function (Blueprint $table) {
            $table->id();
            $table->string('email');
            $table->string('name')->nullable();
            $table->string('order_id')->unique();
            $table->string('package_name');
            $table->decimal('amount', 12, 2)->default(0);
            $table->string('gateway')->nullable();
            $table->string('gateway_transaction_id')->nullable();
            $table->enum('payment_status', ['pending', 'paid', 'failed', 'expired'])->default('pending');
            $table->timestamp('paid_at')->nullable();
            $table->timestamps();
        });
    }

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