<?php

namespace App\Http\Requests;

use App\Tier;
use App\TierHelper;
use Illuminate\Foundation\Http\FormRequest;

class LookupRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return TierHelper::isAllowed(tenant('tier'), Tier::PRO->value);
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, mixed>
     */
    public function rules()
    {
        return [
            'registration_number' => [
                'required',
                'alpha_num',
            ],
            'mileage' => [
                'required',
                'numeric',
                'min:0',
            ],
        ];
    }

    protected function prepareForValidation(): void
    {
        $this->merge([
            'registration_number' => str_replace(' ', '', $this->input('registration_number'))
        ]);
    }
}
