<?php

namespace App\Http\Requests\Api\User;

use Illuminate\Foundation\Http\FormRequest;

class PersonalInfoRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize()
    {
        return true; // Adjust based on authentication/authorization if needed
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules()
    {
        return [
            'gender'             => ['required', 'in:male,female,other'],
            'dob'                => ['required', 'date', 'before:today'],
            'personal_email'     => ['required', 'email', 'max:255'],
            'personal_phone'     => ['required', 'string', 'max:20'],
            'is_married'         => ['nullable', 'in:0,1'],
            'marriage_date'      => ['nullable', 'date', 'required_if:is_married,1'],
            'adhar_card_number'  => ['required', 'string', 'max:20'],
        ];
    }

    /**
     * Custom messages
     */
    public function messages()
    {
        return [
            'gender.required'            => 'Gender is required',
            'gender.in'                  => 'Invalid gender selection',
            'dob.required'               => 'Date of birth is required',
            'dob.date'                   => 'Date of birth must be a valid date',
            'dob.before'                 => 'Date of birth cannot be in the future',
            'personal_email.required'    => 'Personal email is required',
            'personal_email.email'       => 'Personal email must be a valid email',
            'personal_email.max'         => 'Personal email cannot exceed 255 characters',
            'personal_phone.required'    => 'Personal phone is required',
            'personal_phone.max'         => 'Personal phone cannot exceed 20 characters',
            'is_married.required'        => 'Marital status is required',
            'is_married.in'              => 'Invalid marital status',
            'marriage_date.required_if'  => 'Marriage date is required if married',
            'marriage_date.date'         => 'Marriage date must be a valid date',
            'adhar_card_number.required' => 'Adhar card number is required',
            'adhar_card_number.max'      => 'Adhar card number cannot exceed 20 characters',
        ];
    }
}
