<?php
/**
 * Created by PhpStorm.
 * User: radko
 * Date: 2019-02-11
 * Time: 15:16
 */

namespace Seka\Vzdelavanie\Http\Controllers\Api\Frontend\Kniznica;

use Seka\Vzdelavanie\Http\Resources\SekciaResource;
use Seka\Vzdelavanie\Http\Resources\UcebnicaResource;
use Seka\Vzdelavanie\Services\SekciaServiceInterface;
use Seka\Vzdelavanie\Http\Controllers\Api\Controller;
use Seka\Vzdelavanie\Services\UcebnicaServiceInterface;
use Seka\Vzdelavanie\Http\Requests\VyhladavanieIndexRequest;

/**
 * Class VyhladavanieController
 * @package Seka\Vzdelavanie\Http\Controllers\Api\Frontend\Kniznica
 */
class VyhladavanieController extends Controller
{
    /**
     * @var \Seka\Vzdelavanie\Services\UcebnicaServiceInterface
     */
    private $ucebnicaService;

    /**
     * @var \Seka\Vzdelavanie\Services\SekciaServiceInterface
     */
    private $sekciaService;

    /**
     * VyhladavanieController constructor.
     * @param \Seka\Vzdelavanie\Services\UcebnicaServiceInterface $ucebnicaService
     * @param \Seka\Vzdelavanie\Services\SekciaServiceInterface   $sekciaService
     */
    public function __construct(UcebnicaServiceInterface $ucebnicaService, SekciaServiceInterface $sekciaService)
    {
        $this->ucebnicaService = $ucebnicaService;
        $this->sekciaService = $sekciaService;
    }

    /**
     * @param \Seka\Vzdelavanie\Http\Requests\VyhladavanieIndexRequest $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function index(VyhladavanieIndexRequest $request)
    {
        $text = request('text');

        return response()->json([
            'ucebne_materialy' => UcebnicaResource::collection($this->ucebnicaService->vyhladaj($text)),
            'sekcie' => SekciaResource::collection($this->sekciaService->vyhladaj($text))->hide(['obsah']),
        ]);
    }
}
