<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Terminy\Http\Controllers\Backend\Udalosti;

use Illuminate\Contracts\View\View;
use Seka\Portal\Modul\Terminy\Entities\Udalost\Udalost;
use Seka\Portal\Modul\Terminy\Http\Controllers\Controller;
use Seka\Portal\Modul\Terminy\Entities\Udalost\StavUdalosti;
use Seka\Portal\Modul\Terminy\Entities\Udalost\DruhUdalosti;
use Seka\Portal\Modul\Terminy\Entities\Udalost\StavRegistracie;
use Seka\Portal\Modul\Terminy\Entities\MiestoKonania\MiestoKonania;

/**
 * Class UdalostiController
 *
 * @package Seka\Portal\Modul\Terminy\Http\Controllers\Backend\Udalosti
 */
final class UdalostiController extends Controller
{
    /**
     * @return \Illuminate\Contracts\View\View
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     */
    public function index(): View
    {
        return view('Terminy::pages.udalosti.backend.index');
    }

    /**
     * @return \Illuminate\Contracts\View\View
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     */
    public function create(): View
    {
        $udalost = new Udalost();
        $udalost->stav = StavUdalosti::NEZVEREJNENA();
        $udalost->druh = DruhUdalosti::ZAKLADNE_SKOLENIE();
        $udalost->registracia = StavRegistracie::NEPOVOLENA();
        $udalost->miestoKonania()->associate(MiestoKonania::query()->first());

        return view('Terminy::pages.udalosti.backend.nova')
            ->withUdalost($udalost);
    }

    /**
     * @param int $mtUdalostId
     *
     * @return \Illuminate\Contracts\View\View
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     */
    public function edit(int $mtUdalostId): View
    {
        // moznost upravit musi mat aj zneplatnena (trashed) udalost
        $udalost = Udalost::withTrashed()->with('registracie', 'miestoKonania')->findOrFail($mtUdalostId);

        return view('Terminy::pages.udalosti.backend.upravit')
            ->withUdalost($udalost);
    }
}
