<?php

namespace App\Http\Requests\Design\BomTemplate;

use App\Support\Validation\BomItemRules;
use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        $itemRules = collect(BomItemRules::base())
            ->mapWithKeys(fn ($rule, $key) => ["items.*.$key" => $rule])
            ->all();

        return ['items' => 'required|array|min:1'] + $itemRules;
    }

    public function messages(): array
    {
        return [
            'items.required' => __('validation.required', ['attribute' => 'items']),
            'items.array' => __('validation.array', ['attribute' => 'items']),
            'items.min' => __('validation.min.array', ['attribute' => 'items', 'min' => 1]),
        ];
    }
}
