<?php

namespace App\Models;

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

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

  protected $fillable = [
    'user_id',
    'manager_id',
    'department_id',
    'type',
  ];

  protected $casts = [
    'type' => UserDepartmentType::class,
  ];

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

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

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

  public function members()
  {
    return $this->hasMany(UserDepartment::class, 'manager_id', 'user_id');
  }
}
