<?php

namespace App\Http\Requests\V3\RoadItemsProject;

use App\Models\InfoItem;
use App\Models\User;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Symfony\Component\Finder\Exception\AccessDeniedException;

class UpdateRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return !($this->roadItemsProject->user_id != auth()->user()->id || $this->roadItemsProject->status != 2);
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'start_point' => 'required',
            'amount' => 'required|numeric',
            'before_image' => 'image|max:4096',
            'after_image' => 'image|max:4096',
            'machines_id' => 'required|array',
            'machines_id.*' => 'required|exists:cmms_machines,id',
            'rahdaran_id' => 'required|array',
            'rahdaran_id.*' => 'required|exists:rahdaran,id',
        ];
    }
}
