<?php

namespace Modules\SystemCore\App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

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

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'address_type' => [
                'required',
                'string',
                'in:billing,shipping,office,warehouse,home,other',
            ],
            'address_line_1' => [
                'required',
                'string',
                'max:255',
            ],
            'address_line_2' => [
                'nullable',
                'string',
                'max:255',
            ],
            'city' => [
                'nullable',
                'string',
                'max:100',
            ],
            'state' => [
                'nullable',
                'string',
                'max:100',
            ],
            'country' => [
                'nullable',
                'string',
                'max:100',
            ],
            'postal_code' => [
                'nullable',
                'string',
                'max:20',
            ],
            'latitude' => [
                'nullable',
                'numeric',
                'between:-90,90',
            ],
            'longitude' => [
                'nullable',
                'numeric',
                'between:-180,180',
            ],
            'is_primary' => [
                'boolean',
            ],
            'is_billing' => [
                'boolean',
            ],
            'is_shipping' => [
                'boolean',
            ],
        ];
    }

    /**
     * Get custom messages for validator errors.
     */
    public function messages(): array
    {
        return [
            'address_type.required' => __('Address type is required.'),
            'address_type.in' => __('Invalid address type.'),
            'address_line_1.required' => __('Address line 1 is required.'),
            'address_line_1.max' => __('Address line 1 cannot exceed :max characters.'),
            'address_line_2.max' => __('Address line 2 cannot exceed :max characters.'),
            'city.max' => __('City cannot exceed :max characters.'),
            'state.max' => __('State cannot exceed :max characters.'),
            'country.max' => __('Country cannot exceed :max characters.'),
            'postal_code.max' => __('Postal code cannot exceed :max characters.'),
            'latitude.numeric' => __('Latitude must be a valid number.'),
            'latitude.between' => __('Latitude must be between -90 and 90.'),
            'longitude.numeric' => __('Longitude must be a valid number.'),
            'longitude.between' => __('Longitude must be between -180 and 180.'),
        ];
    }

    /**
     * Get custom attributes for validator errors.
     */
    public function attributes(): array
    {
        return [
            'address_type' => __('address type'),
            'address_line_1' => __('address line 1'),
            'address_line_2' => __('address line 2'),
            'city' => __('city'),
            'state' => __('state'),
            'country' => __('country'),
            'postal_code' => __('postal code'),
            'latitude' => __('latitude'),
            'longitude' => __('longitude'),
            'is_primary' => __('primary'),
            'is_billing' => __('billing'),
            'is_shipping' => __('shipping'),
        ];
    }
}
