<?php

declare(strict_types=1);

namespace Seka\Vzdelavanie\Models\Pouzivatel\Testovanie;

use Illuminate\Database\Eloquent\Model;
use Elceka\Laravel\HashId\Http\Traits\Hashidable;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Seka\Vzdelavanie\Models\Testovanie\HodnotenieOdpovedeEnum;

/**
 * Class Odpoved
 *
 * @package Seka\Vzdelavanie\Models\Pouzivatel\Testovanie
 */
class Odpoved extends Model
{
    use Hashidable;

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

    /**
     * @var string[]
     */
    protected $fillable = [
        'znenie',
        'zvolena',
        'hodnotenie',
    ];

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

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

    /**
     * @return bool
     */
    public function jeSpravna(): bool
    {
        return HodnotenieOdpovedeEnum::SPRAVNA()->equals($this->getAttribute('hodnotenie'));
    }

    /**
     * @return bool
     */
    public function jeNespravna(): bool
    {
        return HodnotenieOdpovedeEnum::NESPRAVNA()->equals($this->getAttribute('hodnotenie'));
    }

    /**
     * @return bool
     */
    public function jeZvolena(): bool
    {
        return (bool) true === $this->getAttribute('zvolena') ?? false;
    }

    /**
     * @return bool
     */
    public function jeNezvolena(): bool
    {
        return (bool) false === $this->getAttribute('zvolena') ?? false;
    }
}
