<?php

namespace App\Http\Requests\Admin\FrontSettings;
use Illuminate\Foundation\Http\FormRequest;

class ExamResultSearch extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'exam' => 'required',
            'admission_number' => ['required', 'string', 'max:50', studentAdmissionNumberValidationRule()]
        ];
    }

    protected function prepareForValidation()
    {
        if ($this->has('admission_number')) {
            $this->merge([
                'admission_number' => normalizeAdmissionNumber($this->admission_number),
            ]);
        }
    }

    public function messages()
    {
        return [
            'admission_number.regex' => 'Enter a valid Admission Number, e.g. MMF-201-012-2026.',
        ];
    }
}
