<?php

namespace App\Models;

use App\Enums\ModuleType;
use App\Enums\NotificationType;
use App\Models\Traits\Filterable;
use App\Models\Traits\SelectOptions;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Notification extends Model
{
  use HasFactory, Filterable, SelectOptions;

  protected $fillable = [
    'user_id',
    'department_id',
    'approval_log_id',
    'budget_id',
    'transaction_id',
    'payment_id',
    'module_type',
    'type',
    'title',
    'message',
    'link',
    'is_read',
    'read_at',
  ];

  protected $casts = [
    'module_type' => ModuleType::class,
    'type' => NotificationType::class,
    'is_read' => 'boolean',
    'read_at' => 'datetime',
  ];

  public function user()
  {
    return $this->belongsTo(User::class, 'user_id');
  }

  public function department()
  {
    return $this->belongsTo(Department::class, 'department_id');
  }

  public function budget()
  {
    return $this->belongsTo(Budget::class, 'budget_id');
  }

  public function transaction()
  {
    return $this->belongsTo(Transaction::class, 'transaction_id');
  }

  public function payment()
  {
    return $this->belongsTo(Payment::class, 'payment_id');
  }

  public function approvalLog()
  {
    return $this->belongsTo(ApprovalLog::class, 'approval_log_id');
  }
}
