<?php
/**
 * Created by PhpStorm.
 * User: radko
 * Date: 23.7.18
 * Time: 14:53
 */

namespace Seka\Vzdelavanie\Repositories\Eloquent;

use Seka\Vzdelavanie\Models\Kniznica\Ucebnica;
use Seka\Vzdelavanie\Repositories\Contracts\UcebnicaRepositoryInterface;

/**
 * Class UcebnicaRepository
 *
 * @package Seka\Vzdelavanie\Repositories\Eloquent
 */
class UcebnicaRepository extends Repository implements UcebnicaRepositoryInterface
{
    /**
     * @return string
     */
    public function model(): string
    {
        return Ucebnica::class;
    }

    /**
     * @param array $attributes
     *
     * @return \Seka\Vzdelavanie\Models\Kniznica\Ucebnica
     * @throws \Seka\Vzdelavanie\Repositories\Exceptions\RepositoryException
     */
    public function create(array $attributes): Ucebnica
    {
        $attributes['kategoria_id'] = $attributes['kategoria'];

        return parent::create($attributes);
    }

    /**
     * @param array $columns
     *
     * @return mixed
     */
    public function all(array $columns = ['*']): mixed
    {
        return $this
            ->query()
            ->allowedIncludes('kategoria')
            ->allowedFilters('id', 'kategoria_id')
            ->allowedSorts('updated_at');
    }
}
