<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class LoginRequest extends FormRequest
{
    protected function prepareForValidation(): void
    {
        $identifier = $this->input('identifier', $this->input('email'));

        if ($identifier !== null) {
            $this->merge([
                'identifier' => strtolower(trim((string) $identifier)),
            ]);
        }
    }

    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'identifier' => 'required|string|max:255',
            'email' => 'sometimes|nullable|string|max:255',
            'password' => 'required|string',
        ];
    }
}
