<?php

namespace App\Http\Requests\V3\ObservedItem;

use Illuminate\Foundation\Http\FormRequest;

class StoreRequest 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 [
            'road_patrol_id' => 'required|integer|exists:road_patrols,id',
            'observed_items' => 'required|array|min:1',
            'observed_items.*.item_id' => 'required|integer|exists:info_items,item',
            'observed_items.*.sub_item_id' => 'required|integer',
            'observed_items.*.start_point' => 'required|string',
            'observed_items.*.description' => 'nullable|string',
            'observed_items.*.instant_action' => 'required|in:0,1',
            'observed_items.*.priority' => 'required_if:observed_items.*.instant_action,0|in:1,2,3',
            'observed_items.*.end_point' => 'required_if:observed_items.*.instant_action,1|string',
        ];
    }
}
