<?php declare(strict_types=1);

namespace App\Http\Requests;

use App\Contracts\FormRequestDto;
use App\Dto\Request\Authorization;
use Illuminate\Foundation\Http\FormRequest;

final class AuthorizationRequest extends FormRequest implements FormRequestDto
{
    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        $rules = [
            'email' => ['required', 'email', 'max:255'],
            'password' => ['required', 'min:3'],
            'remember' => ['nullable', 'boolean'],
        ];

        if (config('app.captcha', false)) {
            $rules['captcha-verified'] = ['captcha'];
        }

        return $rules;
    }

    public function getDto(): Authorization
    {
        return new Authorization(
            email:    $this->input('email'),
            password: $this->input('password'),
            remember: (bool) $this->input('remember', false)
        );
    }
}
