<?php

declare(strict_types=1);

namespace Seka\Vzdelavanie\Models\Testovanie;

use Core\Http\Traits\Hashidable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Seka\Vzdelavanie\Enums\ModelStatusEnum;

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

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

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

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

    /**
     * @param \Illuminate\Database\Eloquent\Builder $query
     *
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopePublikovana(Builder $query)
    {
        return $query->where('stav', ModelStatusEnum::PUBLIKOVANE());
    }

    /**
     * @param \Illuminate\Database\Eloquent\Builder $query
     *
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeSpravna(Builder $query)
    {
        return $query->where('hodnotenie', HodnotenieOdpovedeEnum::SPRAVNA());
    }

    /**
     * @param \Illuminate\Database\Eloquent\Builder $query
     *
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeNespravna(Builder $query)
    {
        return $query->where('hodnotenie', HodnotenieOdpovedeEnum::NESPRAVNA());
    }

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