<?php

namespace App\Models\Administration;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class OfficeUser extends Model
{
    use HasFactory;

    protected $table = 'sc_office_users';
    public $timestamps = false;

    protected $fillable = [
        'id',
        'fk_office',
        'fk_user',
        'fk_role',
        'visible',
        'available',
        'fk_usercreator',
        'created_at',
        'fk_userupdater',
        'udapted_at',
        'is_active',
    ];

    protected $casts = [
        'id' => 'integer',
        'fk_office' => 'integer',
        'fk_user' => 'integer',
        'fk_role' => 'integer',
        'visible' => 'boolean',
        'available' => 'boolean',
        'fk_usercreator' => 'integer',
        'created_at' => 'timestamp',
        'fk_userupdater' => 'integer',
        'updated_at' => 'timestamp',
        'is_active' => 'boolean'
    ];

    protected $hidden = [
        'id',
        'fk_office',
        'fk_user',
        'fk_role',
        'visible',
        'fk_usercreator',
        'fk_userupdater',
        'is_active',
    ];

    public function office()
    {
        return $this->belongsTo(Office::class, 'fk_office', 'id');
    }

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

    public function role()
    {
        return $this->belongsTo(Role::class, 'fk_role', 'id');
    }

    public function user_creator()
    {
        return $this->hasOne(User::class, 'id', 'fk_usercreator');
    }

    public function user_updater()
    {
        return $this->hasOne(User::class, 'id', 'fk_userupdater');
    }
}
