<?php

namespace App\Models\Traits;

use Modules\Employee\Models\Employee;
use Illuminate\Database\Eloquent\Builder;

trait HasEmployeeUser
{
    public function employee()
    {
        return $this->hasOne(Employee::class);
    }

    public function isEmployeeUser(): bool
    {
        return $this->relationLoaded('employee') ? $this->employee !== null : $this->employee()->exists();
    }

    public function isSystemUser(): bool
    {
        return !$this->isEmployeeUser();
    }

    public function scopeEmployeeUsers(Builder $query): Builder
    {
        return $query->whereHas('employee');
    }
    
    public function scopeSystemUsers(Builder $query): Builder
    {
        return $query->whereDoesntHave('employee');
    }
}
