<?php

declare(strict_types=1);

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

use Elceka\Laravel\HashId\Http\Traits\Hashidable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
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;
    use HasFactory;

    protected $table = 'terminy_udalost_registracie';

    protected $guarded = [];

    protected $appends = [
        'cele_meno',
    ];

    protected $casts = [
        'moznosti' => ZvoleneMoznostiUdalostiCastable::class,
    ];

    public function udalost(): BelongsTo
    {
        return $this->belongsTo(Udalost::class, 'udalost_id', 'id');
    }

    public function pouzivatel(): ?BelongsTo
    {
        return $this->belongsTo('\App\Models\Pouzivatel\Pouzivatel', 'pouzivatel_id', 'id');
    }

    public function vytvoril(): BelongsTo
    {
        return $this->belongsTo('\App\Models\Pouzivatel\Pouzivatel', 'vytvoril_id', 'id');
    }

    public function pracovisko(): BelongsTo
    {
        return $this->belongsTo('\App\Models\Pracovisko\Pracovisko', 'pracovisko_id', 'id');
    }

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

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