<?php

declare(strict_types=1);

namespace Seka\Vzdelavanie\Http\Requests\Frontend\Testovanie;

use Illuminate\Foundation\Http\FormRequest;
use Seka\Vzdelavanie\Models\Pouzivatel\Testovanie\Test;
use Seka\Vzdelavanie\Models\Pouzivatel\Testovanie\Otazka;
use Seka\Vzdelavanie\Models\Pouzivatel\Testovanie\Odpoved;

/**
 * Class VyhodnotenieTestuPutRequest
 *
 * @package Seka\Vzdelavanie\Http\Requests\Frontend\Testovanie
 */
final class VyhodnotenieTestuPutRequest extends FormRequest
{
    /**
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * @return bool
     */
    public function expectsJson()
    {
        return true;
    }

    /**
     * @return string[]
     */
    public function rules()
    {
        $nazovTabulkyTestovPouzivatela = (new Test())->getTable();
        $nazovTabulkyOtazokTestuPouzivatela = (new Otazka())->getTable();
        $nazovTabulkyOdpovediOtazkuTestuPouzivatela = (new Odpoved())->getTable();

        return [
            'id' => "required|integer|exists:$nazovTabulkyTestovPouzivatela",
            'otazky' => 'required|array',
            'otazky.*.id' => "required|integer|exists:$nazovTabulkyOtazokTestuPouzivatela",
            'otazky.*.odpovede' => 'required|array',
            'otazky.*.odpovede.*.id' => "required|integer|exists:$nazovTabulkyOdpovediOtazkuTestuPouzivatela",
            'otazky.*.odpovede.*.zvolena' => 'required|boolean',
        ];
    }
}
