<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
       Schema::create('payments', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('order_id');
            $table->enum('payment_method', ['cash', 'card', 'transfer', 'ewallet', 'qris']);
            $table->string('payment_channel')->nullable(); // contoh: BCA, Mandiri, OVO, DANA, dll
            $table->decimal('amount', 15, 2);
            $table->enum('status',['paid','unpaid', 'expired','failed'])->default('unpaid');
            $table->date('payment_date')->nullable();
            $table->text('midtrans_qr_string')->nullable();
            $table->string('midtrans_order_id')->nullable()->unique();
            $table->string('midtrans_transaction_id')->nullable();
            $table->text('midtrans_snap_token')->nullable();
            $table->text('midtrans_payment_url')->nullable();
            $table->dateTime('expired_at')->nullable();
            $table->timestamps();

            $table->index(['order_id', 'payment_method', 'status']);
            $table->index('midtrans_order_id');
            $table->foreign('order_id')->references('order_id')->on('orders')->cascadeOnDelete();
});

    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('payments');
    }
};
