<?php

declare(strict_types=1);

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

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

/**
 * Class UdalostiController
 *
 * @package Seka\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);
    }
}
