<?php

namespace App\Http\Requests\Auth;

use App\Http\Requests\ApiFormRequest;

class RegisterRequest extends ApiFormRequest
{
    public static function ruleset(): array
    {
        return (new self())->rules();
    }

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

    public function rules(): array
    {
        return [
            'firstname' => ['required', 'regex:/^[a-zA-Z\s-]+$/', 'min:2', 'max:30'],
            'lastname' => ['required', 'regex:/^[a-zA-Z\s-]+$/', 'min:2', 'max:30'],
            'gender' => ['required', 'in:Male,Female'],
            'email' => ['required', 'email', 'max:50'],
            'confirm_email' => ['required', 'same:email'],
            'cellphone' => ['required', 'regex:/^[\d\s\-\(\)\.]+$/', 'min:10', 'max:20'],
            'address_street' => ['nullable', 'regex:/^[a-zA-Z0-9\s\-]+$/', 'max:150'],
            'apt' => ['nullable', 'regex:/^[a-zA-Z0-9\s-]+$/', 'max:10'],
            'city' => ['required', 'regex:/^[a-zA-Z\s]+$/', 'min:2', 'max:30'],
            'state' => ['required', 'in:CT,ME,MA,NH,NY,RI,VT'],
            'zip' => ['required', 'regex:/^\d{5}$/'],
            'accept_school_policy' => ['required'],
            'captcha' => ['required', 'alpha_num', 'min:4', 'max:10'],
            'is_parent' => ['nullable', 'boolean'],
            'no_second_parent_info' => ['nullable', 'boolean'],
            'second_firstname' => ['exclude_if:no_second_parent_info,1', 'required_if:is_parent,1', 'regex:/^[a-zA-Z\s\-]+$/', 'min:2', 'max:30'],
            'second_lastname' => ['exclude_if:no_second_parent_info,1', 'required_if:is_parent,1', 'regex:/^[a-zA-Z\s\-]+$/', 'min:2', 'max:30'],
            'second_gender' => ['exclude_if:no_second_parent_info,1', 'required_if:is_parent,1', 'in:Male,Female'],
            'second_email' => ['exclude_if:no_second_parent_info,1', 'required_if:is_parent,1', 'email', 'max:50'],
            'second_cellphone' => ['exclude_if:no_second_parent_info,1', 'required_if:is_parent,1', 'regex:/^[\d\s\-\(\)\.]+$/', 'min:10', 'max:20'],
        ];
    }
}
