<?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->foreignIdFor(\App\Models\User::class)->constrained()->cascadeOnDelete();
            $table->foreignIdFor(\App\Models\PaymentMethod::class)->constrained()->cascadeOnDelete();
            $table->string('payment_identifier')->unique();
            $table->string('gateway_id')->nullable()->default(null);
            $table->float('amount')->default(0)->comment('amount before charge');
            $table->float('charge')->default(0)->comment('gateway charge of amount');
            $table->float('payable')->default(0)->comment('amount + charge');
            $table->float('conversion_rate')->default(1.0)->comment('currency conversion rate');
            $table->enum('type', \App\Enums\PaymentTypeEnum::values())->default(\App\Enums\PaymentTypeEnum::DEPOSIT);
            $table->longText('meta')->nullable()->comment('json encoded array');
            $table->string('currency', 10)->default('USD');
            $table->enum('status', \App\Enums\PaymentStatusEnum::values())->default(\App\Enums\PaymentStatusEnum::PENDING);
            $table->timestamps();
        });
    }

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