<?php

namespace App\Models\Tenants\Pivots;

use App\Models\Commons\IdeHelperDepartmentUser;
use App\Models\Members\User;
use App\Models\Tenants\Department;
use App\Traits\BelongsToTenant;
use App\Traits\ModelTrait;
use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * @mixin IdeHelperDepartmentUser
 */
class DepartmentUser extends Pivot
{
    use BelongsToTenant, ModelTrait, SoftDeletes;

    protected $table = 'department_user';

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

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

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

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