<?php

namespace App\Http\Requests\Auth;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\Password;

class ResetPasswordRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        return [
            'token' => ['required'],
            'email' => [
                'required',
                'email',
                Rule::exists('users', 'email')->where(
                    fn ($query) => $query
                        ->where('is_active', true)
                        ->whereNull('invitation_token')
                ),
            ],
            'password' => ['required', 'confirmed', Password::defaults()],
        ];
    }
}
