<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Enums\TransactionStatusType;
use App\Enums\TransactionType;

return new class extends Migration {
  /**
   * Run the migrations.
   */
  public function up(): void
  {
    Schema::create('transactions', function (Blueprint $table) {
      $table->id();
      $table->foreignId('budget_detail_id')->constrained('budget_details');
      $table->foreignId('user_id')->constrained('users');
      $table->foreignId('vendor_id')->nullable()->constrained('vendors');
      $table->foreignId('balance_id')->nullable()->constrained('balances');
      $table->string('code')->index();
      $table->string('name');
      $table->string('type')->default(TransactionType::Realization)->index();
      $table->text('description')->nullable();
      $table->bigInteger('price');
      $table->bigInteger('price_total');
      $table->string('status')->default(TransactionStatusType::Pending)->index();
      $table->text('status_message')->nullable();
      $table->timestamps();
    });
  }

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