<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Terminy\Entities\Registracia;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Elceka\Laravel\HashId\Http\Traits\Hashidable;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Seka\Portal\Modul\Terminy\Entities\Registracia\Casts\ZvoleneMoznostiUdalostiCastable;
use Seka\Portal\Modul\Terminy\Entities\Udalost\Udalost;

/**
 * Class Registracia
 *
 * @package Seka\Portal\Modul\Terminy\Entities\Registracia
 *
 * @property int                            $id
 * @property int                            $udalost_id
 * @property int                            $vytvoril_id
 * @property int                            $pracovisko_id
 * @property int|null                       $pouzivatel_id
 * @property string|null                    $meno
 * @property string|null                    $priezvisko
 * @property string|null                    $cele_meno
 * @property string|null                    $poznamka
 * @property \Illuminate\Support\Collection $moznosti
 * @property \Carbon\Carbon                 $created_at
 * @property \Carbon\Carbon                 $updated_at
 */
final class Registracia extends Model
{
    use Hashidable;
    use SoftDeletes;

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

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

    /**
     * @var string[]
     */
    protected $appends = [
        'cele_meno',
    ];

    /**
     * @var string[]
     */
    protected $casts = [
        'moznosti' => ZvoleneMoznostiUdalostiCastable::class,
    ];

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

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo|null
     */
    public function pouzivatel(): BelongsTo
    {
        return $this->belongsTo('\App\Models\Pouzivatel\Pouzivatel', 'pouzivatel_id', 'id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function vytvoril(): BelongsTo
    {
        return $this->belongsTo('\App\Models\Pouzivatel\Pouzivatel', 'vytvoril_id', 'id');
    }

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

    /**
     * @return string
     */
    public function getCeleMenoAttribute(): string
    {
        return $this->meno . ' ' . $this->priezvisko;
    }

    /**
     * @return bool
     */
    public function maVytvoreneMoznosti(): bool
    {
        return $this->moznosti->isNotEmpty();
    }
}
