<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Enums\PaymentType;
use App\Enums\PaymentMethodType;
use App\Enums\PaymentStatusType;

return new class extends Migration {
  /**
   * Run the migrations.
   */
  public function up(): void
  {
    Schema::create('payments', function (Blueprint $table) {
      $table->id();
      $table->foreignId('company_id')->constrained('companies');
      $table->foreignId('budget_id')->constrained('budgets');
      $table->foreignId('department_id')->nullable()->constrained('departments');
      $table->foreignId('user_review_id')->nullable()->constrained('users');
      $table->foreignId('user_bank_id')->nullable()->constrained('user_banks');
      $table->foreignId('company_bank_id')->nullable()->constrained('user_banks');
      $table->foreignId('transaction_id')->nullable()->constrained('transactions');
      $table->string('code')->index();
      $table->string('type')->default(PaymentType::Full)->nullable()->index();
      $table->string('method')->default(PaymentMethodType::EBanking)->nullable()->index();
      $table->bigInteger('amount');
      $table->bigInteger('max_amount')->nullable();
      $table->float('payment_percentage')->nullable();
      $table->date('payment_date');
      $table->date('due_date');
      $table->string('cheque_number')->nullable();
      $table->text('description')->nullable();
      $table->string('status')->default(PaymentStatusType::Pending)->index();
      $table->text('status_message')->nullable();
      $table->timestamp('review_at')->nullable();
      $table->timestamps();
    });
  }

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