<?php

namespace Seka\Portal\Modul\Vzdelavanie\Models\Kniznica;

use Elceka\Laravel\HashId\Http\Traits\Hashidable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
 * Class Kategoria
 *
 * @package Seka\Portal\Modul\Vzdelavanie\Models\Kniznica
 */
class Kategoria extends Model
{
    use Hashidable;
    use HasFactory;

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

    /**
     * @var array
     */
    protected $fillable = [
        'id',
        'nazov',
        'obrazok',
    ];

    protected static function boot(): void
    {
        parent::boot();

        static::deleting(function (Kategoria $kategoria) {
            $kategoria->ucebnice->each->delete();
        });
    }

    public function ucebnice(): HasMany
    {
        return $this->hasMany(Ucebnica::class, 'kategoria_id', 'id');
    }

    /**
     * @param string      $childType
     * @param mixed       $value
     * @param string|null $field
     *
     * @return \Illuminate\Database\Eloquent\Model|void|null
     */
    public function resolveChildRouteBinding($childType, $value, $field)
    {
        // TODO: Implement resolveChildRouteBinding() method.
    }
}
