<?php

declare(strict_types=1);

namespace App\Models\Pracovisko;

use App\Models\Pouzivatel\Pouzivatel;
use Elceka\Laravel\HashId\Http\Traits\Hashidable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Notifications\Notifiable;

/**
 * Class Pracovisko
 *
 *
 * @property $id
 * @property $kod
 * @property $nazov
 * @property $email
 */
final class Pracovisko extends Model
{
    use HasFactory;
    use Hashidable;
    use Notifiable;

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

    /**
     * @var string[]
     */
    protected $guarded = [];

    protected static function boot()
    {
        parent::boot();

        self::creating(function (Pracovisko $pracovisko) {
            $pracovisko->email = sprintf('%s@sekait.sk', $pracovisko->kod);
        });
    }

    public function pouzivatelia(): HasMany
    {
        return $this->hasMany(Pouzivatel::class, 'pracovisko_id', 'id');
    }

    /**
     * Route notifications for the mail channel.
     *
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return null|string|array
     */
    public function routeNotificationForMail($notification)
    {
        if (is_null($this->email) || empty(trim($this->email))) {
            return $this->email;
        }

        return [$this->email => $this->nazov];
    }
}
