<?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('transactions', function (Blueprint $table) {
        $table->id();
        $table->foreignId('user_id')->constrained()->onDelete('cascade');
        $table->foreignId('product_id')->nullable(); // Engké hubungkeun ka tabel products
        $table->string('invoice_number')->unique();
        $table->string('customer_name')->nullable();
        $table->string('customer_phone')->nullable();
        $table->decimal('amount', 15, 2);
        $table->decimal('base_price', 15, 2)->default(0); // Jang ngitung untung
        $table->string('status')->default('pending'); // pending, success, failed, refund
        $table->string('payment_method')->nullable();
        $table->string('api_transaction_id')->nullable(); // ID ti Digiflazz
        $table->text('api_response')->nullable();
        $table->timestamps();
    });
}

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