<?php

namespace App\Http\Requests;

use App\Rules\UniqueByTerm;
use Illuminate\Foundation\Http\FormRequest;

class UserCreate 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 [
            'email' => ['required', function ($attribute, $value, $fail) {
                if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
                    $fail('Полето емаил не е валидно.');
                }
            }],
            'name' => ['required', 'min:3'],
            'highschool' => ['required'],
            'highschool_year' => ['required', 'in:1,2,3,4'],

            // 'surname' => ['required', 'min:3', 'regex:/^[a-zA-Z\s]*$/'],
            // 'birth_date.day' => ['required'],
            // 'birth_date.month' => ['required'],
            // 'birth_date.year' => ['required'],
            // 'highschool' => ['required'],
            'phone' => ['required', 'regex:/^07\d{7}$/']
        ];
    }

    public function messages(): array
    {
        return [
            'phone.regex' => 'Невалиден формат, внесете формат 07XXXXXXX',
            'highschool_year.in' => 'Полето година е задолжително.'
        ];
    }


}
