<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class DepartmentUser extends Model
{
    use SoftDeletes;

    protected $table = 'department_user';

    protected $fillable = [
        'tenant_id',
        'department_id',
        'user_id',
        'is_primary',
        'joined_at',
        'left_at',
        'created_by',
        'updated_by',
        'deleted_by',
    ];

    protected $casts = [
        'tenant_id' => 'integer',
        'department_id' => 'integer',
        'user_id' => 'integer',
        'is_primary' => 'boolean',
        'joined_at' => 'datetime',
        'left_at' => 'datetime',
    ];

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

    /**
     * 사용자
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class, 'user_id');
    }
}
