<?php

namespace App\Models\Informacia;

use App\Models\Hodnotenie\HodnotenieTrait;
use App\Models\Informacia\Enums\StavInformacieEnum;
use App\Models\Pouzivatel\Pouzivatel;
use DateTimeInterface;
use Elceka\Laravel\HashId\Http\Traits\Hashidable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class Informacia
 *
 * @package App\Models\Informacia
 *
 * @property int $id
 * @property int $vytvoril_id
 * @property Pouzivatel $vytvoril
 * @property string $titulok
 * @property string $uvod
 * @property string $obsah
 * @property StavInformacieEnum $stav
 * @property array<string>|null $zverejnit_pre_pouzivatelov_podla_role
 * @property DateTimeInterface|null $planovany_cas_zverejnenia
 * @property bool $odoslat_email_na_pek
 * @property bool $odoslat_email_pouzivatelom
 * @property bool $odoslat_push_notifikacie_pouzivatelom
 * @property DateTimeInterface|null $cas_zverejnenia
 * @property bool $odporucane
 */
class Informacia extends Model
{
    use Hashidable;
    use SoftDeletes;
    use HodnotenieTrait;

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

    /**
     * @var array
     */
    protected $guarded = [
        'id',
        'vytvoril_id',
    ];

    /**
     * @var false[]
     */
    protected $attributes = [
        'odporucane' => false,
        'odoslat_email_na_pek' => false,
        'odoslat_email_pouzivatelom' => false,
        'odoslat_push_notifikacie_pouzivatelom' => false,
    ];

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'vytvoril_id',
        'titulok',
        'uvod',
        'obsah',
        'stav',
        'zverejnit_pre_pouzivatelov_podla_role',
        'planovany_cas_zverejnenia',
        'odoslat_email_na_pek',
        'odoslat_email_pouzivatelom',
        'odoslat_push_notifikacie_pouzivatelom',
        'odporucane',
        'cas_zverejnenia',
    ];

    /**
     * @var string[]
     */
    protected $appends = [
        'pocet_vsetkych_hodnoteni',
        'pocet_kladnych_hodnoteni',
        'pocet_zapornych_hodnoteni',
    ];

    /**
     * The attributes that should be cast.
     *
     * @var array
     */
    protected $casts = [
        'stav' => StavInformacieEnum::class,
        'planovany_cas_zverejnenia' => 'datetime',
        'cas_zverejnenia' => 'datetime:Y-m-d\TH:i',
        'zverejnit_pre_pouzivatelov_podla_role' => 'array',
        'odporucane' => 'boolean',
        'odoslat_email_na_pek' => 'boolean',
        'odoslat_email_pouzivatelom' => 'boolean',
        'odoslat_push_notifikacie_pouzivatelom' => 'boolean',
    ];

    /**
     * Definícia vzťahu k modelu Pouzivatel (ak existuje model Pouzivatel).
     *
     * @return BelongsTo
     */
    public function vytvoril(): BelongsTo
    {
        return $this->belongsTo(Pouzivatel::class, 'vytvoril_id');
    }
}
