<?php

namespace App\Http\Requests\Qms;

use Illuminate\Foundation\Http\FormRequest;

class AuditChecklistStoreRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'year' => 'required|integer|min:2020|max:2100',
            'quarter' => 'required|integer|in:1,2,3,4',
            'type' => 'nullable|string|max:30',
            'categories' => 'required|array|min:1',
            'categories.*.title' => 'required|string|max:200',
            'categories.*.sort_order' => 'nullable|integer|min:0',
            'categories.*.items' => 'required|array|min:1',
            'categories.*.items.*.name' => 'required|string|max:200',
            'categories.*.items.*.description' => 'nullable|string',
            'categories.*.items.*.sort_order' => 'nullable|integer|min:0',
        ];
    }

    public function messages(): array
    {
        return [
            'categories.required' => __('validation.required', ['attribute' => '카테고리']),
            'categories.*.title.required' => __('validation.required', ['attribute' => '카테고리 제목']),
            'categories.*.items.required' => __('validation.required', ['attribute' => '점검 항목']),
            'categories.*.items.*.name.required' => __('validation.required', ['attribute' => '항목명']),
        ];
    }
}
