<?php

namespace App\Models\Pouzivatel;

use Illuminate\Foundation\Auth\User;
use App\Models\Pracovisko\Pracovisko;
use Spatie\Permission\Traits\HasRoles;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Contracts\Auth\Authenticatable;
use Elceka\Laravel\HashId\Http\Traits\Hashidable;

/**
 * Class Pouzivatel
 *
 * @package App\Models\Pouzivatel
 *
 * @property $id
 * @property $pracovisko_id
 * @property $meno
 * @property $stav
 * @property $login
 * @property $password
 * @property $datum_posledneho_prihlasenia
 */
final class Pouzivatel extends User implements Authenticatable
{
    use HasRoles;
    use Notifiable;
    use Hashidable;

    /**
     * @var string
     */
    protected $table = 'pouzivatelia';

    /**
     * @var array
     */
    protected $guarded = ['password'];

    /**
     * @var string[]
     */
    protected $dates = [
        'datum_posledneho_prihlasenia',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'stav' => PouzivatelStavEnum::class,
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function pracovisko()
    {
        return $this->belongsTo(Pracovisko::class, 'pracovisko_id', 'id');
    }

    /**
     * @param \Illuminate\Database\Eloquent\Builder $query
     *
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeAktivny(Builder $query): Builder
    {
        return $query->where('stav', PouzivatelStavEnum::AKTIVNY()->value);
    }

    /**
     * @return bool
     */
    public function jeBlokovany(): bool
    {
        return (bool) $this->getAttribute('stav')->equals(PouzivatelStavEnum::BLOKOVANY());
    }

    /**
     * @return bool
     */
    public function jeAktivny(): bool
    {
        return (bool) $this->getAttribute('stav')->equals(PouzivatelStavEnum::AKTIVNY());
    }
}
