<?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->foreignId('sale_id')->constrained()->cascadeOnDelete();
            $table->foreignId('account_id')->constrained()->restrictOnDelete();
            $table->foreignId('created_by_user_id')->constrained('users')->restrictOnDelete();

            $table->date('payment_date');
            $table->decimal('amount', 12, 2);
            $table->enum('currency', ['USD', 'BOB'])->default('USD');

            $table->decimal('fee_amount', 10, 2)->default(0);
            $table->decimal('net_amount', 12, 2)->default(0);

            $table->text('note')->nullable();

            $table->timestamps();

            $table->index('sale_id');
            $table->index('account_id');
            $table->index('payment_date');
        });
    }

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