<?php

namespace App\Http\Requests\V3\AccidentReceipt;

use App\Enums\AccidentStates;
use Illuminate\Foundation\Http\FormRequest;

class UpdateRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return $this->accident->status === AccidentStates::BEDON_EGHDAM->value;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'is_foreign' => 'required|boolean',
            'province_id' => 'required|integer|exists:provinces,id',
            'city_id' => 'required|integer|exists:cities,id',
            'axis_name' => 'required|string',
            'driver_name' => 'required_if:is_foreign,0|string',
            'plaque' => 'required_if:is_foreign,0|string',
            'driver_national_code' => 'required_if:is_foreign,0|string',
            'driver_phone_number' => 'required_if:is_foreign,0|string',
            'lat' => 'required|numeric',
            'lng' => 'required|numeric',
            'accident_type' => 'required|integer',
            'accident_date' => 'required|date',
            'accident_time' => 'required|string',
            'report_base' => 'required|in:0,1',
            'police_file' => 'file|mimes:pdf,jpg,jpeg,png',
            'police_serial' => 'required_if:report_base,0|string',
            'police_file_date' => 'required_if:report_base,0|date',
            'damage_picture1' => 'file|mimes:pdf,jpg,jpeg,png',
            'damage_picture2' => 'file|mimes:pdf,jpg,jpeg,png',
            'damage_items' => 'required|array',
            'damage_items.*.value' => 'required',
            'damage_items.*.amount' => 'required',
        ];
    }
}
