<?php

declare(strict_types=1);

namespace App\Models\Pracovisko;

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

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

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

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

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

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

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function pouzivatelia(): HasMany
    {
        return $this->hasMany(Pouzivatel::class, 'pracovisko_id', 'id');
    }

    /**
     * Route notifications for the mail channel.
     *
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return array|string
     */
    public function routeNotificationForMail($notification)
    {
        return [$this->email => $this->nazov];
    }
}
