<?php

namespace LaraBB\User\UI\Web\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\RedirectResponse;

/**
 * Class Login
 * @package LaraBB\User\UI\Web\Requests
 */
class Login extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules(): array
    {
        return [
            'login-email'    => 'required|email',
            'login-password' => 'required'
        ];
    }

    /**
     * @return array
     */
    public function messages(): array
    {
        return [
            'login-email.required'    => __('Please enter an email address.'),
            'login-email.email'       => __('The given email address has an invalid format.'),
            'login-password.required' => __('Please enter a password.')
        ];
    }

    /**
     * @return RedirectResponse
     */
    public function success(): RedirectResponse
    {
        return redirect()->route('index');
    }

    /**
     * @return RedirectResponse
     */
    public function failed(): RedirectResponse
    {
        return redirect()->back()->with([
            'error' => __('Incorrect credentials.')
        ]);
    }
}
