<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Enums\ModuleType;
use App\Enums\ActionStatusType;
use App\Enums\UserDepartmentType;

return new class extends Migration {
  /**
   * Run the migrations.
   */
  public function up(): void
  {
    Schema::create('approval_logs', function (Blueprint $table) {
      $table->id();
      $table->foreignId('user_id')->constrained('users');
      $table->foreignId('department_id')->nullable()->constrained('departments');
      $table->foreignId('approval_department_id')->nullable()->constrained('departments');
      $table->foreignId('parent_id')->nullable()->constrained('approval_logs');
      $table->foreignId('budget_id')->nullable()->constrained('budgets');
      $table->foreignId('budget_detail_id')->nullable()->constrained('budget_details');
      $table->foreignId('payment_id')->nullable()->constrained('payments');
      $table->string('module_type')->default(ModuleType::Budget)->index();
      $table->string('action')->default(ActionStatusType::Submit)->index();
      $table->string('submit_level')->nullable()->default(UserDepartmentType::User)->index();
      $table->string('approval_level')->nullable()->default(UserDepartmentType::Manager)->index();
      $table->boolean('is_finance')->default(false)->index();
      $table->text('note')->nullable();
      $table->string('ip_address')->nullable();
      $table->longText('user_agent')->nullable();
      $table->longText('detail')->nullable();
      $table->timestamps();
    });
  }

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