<?php

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

return new class extends Migration {
  /**
   * Run the migrations.
   */
  public function up(): void
  {
    Schema::create('notifications', function (Blueprint $table) {
      $table->id();
      $table->foreignId('user_id')->constrained('users');
      $table->foreignId('department_id')->nullable()->constrained('departments');
      $table->foreignId('approval_log_id')->nullable()->constrained('approval_logs');
      $table->foreignId('budget_id')->nullable()->constrained('budgets');
      $table->foreignId('transaction_id')->nullable()->constrained('transactions');
      $table->foreignId('payment_id')->nullable()->constrained('payments');
      $table->string('module_type')->default(ModuleType::Budget)->index();
      $table->string('type')->default(NotificationType::Info)->index();
      $table->string('title')->nullable();
      $table->text('message')->nullable();
      $table->string('link')->nullable();
      $table->boolean('is_read')->default(false)->index();
      $table->timestamp('read_at')->nullable();
      $table->timestamps();
    });
  }

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