<?php

namespace App\Http\Requests\Design;

use Illuminate\Foundation\Http\FormRequest;

class CalculateBomRequest 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.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'parameters' => 'required|array',
            'parameters.W0' => 'nullable|integer|min:500|max:15000',
            'parameters.H0' => 'nullable|integer|min:500|max:15000',
            'parameters.product_type' => 'nullable|string|in:screen,steel,blind',
            'parameters.installation_type' => 'nullable|string|in:window,wall,ceiling',
            'parameters.power_source' => 'nullable|string|in:manual,electric,automatic',
            'parameters.motor_type' => 'nullable|string|in:standard,low_noise,high_torque',
            'parameters.material_grade' => 'nullable|string|in:standard,premium,luxury',
            'company_name' => 'nullable|string|max:100',
        ];
    }

    /**
     * Get custom messages for validator errors.
     *
     * @return array<string, string>
     */
    public function messages(): array
    {
        return [
            'parameters.required' => __('error.validation.required'),
            'parameters.array' => __('error.validation.array'),
            'parameters.W0.integer' => __('error.validation.integer'),
            'parameters.W0.min' => __('error.validation.min.numeric'),
            'parameters.W0.max' => __('error.validation.max.numeric'),
            'parameters.H0.integer' => __('error.validation.integer'),
            'parameters.H0.min' => __('error.validation.min.numeric'),
            'parameters.H0.max' => __('error.validation.max.numeric'),
            'parameters.product_type.string' => __('error.validation.string'),
            'parameters.product_type.in' => __('error.validation.in'),
            'parameters.installation_type.string' => __('error.validation.string'),
            'parameters.installation_type.in' => __('error.validation.in'),
            'parameters.power_source.string' => __('error.validation.string'),
            'parameters.power_source.in' => __('error.validation.in'),
            'parameters.motor_type.string' => __('error.validation.string'),
            'parameters.motor_type.in' => __('error.validation.in'),
            'parameters.material_grade.string' => __('error.validation.string'),
            'parameters.material_grade.in' => __('error.validation.in'),
            'company_name.string' => __('error.validation.string'),
            'company_name.max' => __('error.validation.max.string'),
        ];
    }

    /**
     * Get custom attributes for validator errors.
     *
     * @return array<string, string>
     */
    public function attributes(): array
    {
        return [
            'parameters' => '계산 파라미터',
            'parameters.W0' => '오픈사이즈 가로(mm)',
            'parameters.H0' => '오픈사이즈 세로(mm)',
            'parameters.product_type' => '제품타입',
            'parameters.installation_type' => '설치타입',
            'parameters.power_source' => '동력원',
            'parameters.motor_type' => '모터타입',
            'parameters.material_grade' => '자재등급',
            'company_name' => '업체명',
        ];
    }
}
