<?php

namespace App\Http\Requests\Destination;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rules\File;

class UpdateDestinationRequest 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 [
            "title" => ["required_without_all:description,start_location,minimum_age,image,country_id", "string", "max:255"],
            "description" => ["required_without_all:title,start_location,minimum_age,image,country_id", "string", "max:2048"],
            "start_location" => ["required_without_all:title,description,minimum_age,image,country_id", "string", "max:255"],
            "minimum_age" => ["required_without_all:title,description,start_location,image,country_id", "integer", "max:200"],
            "image" => ["required_without_all:title,description,start_location,minimum_age,country_id", File::image()
                ->min('1kb')
                ->max('20mb')
            ],
            "country_id" => ["required_without_all:title,description,start_location,minimum_age,image", "integer", "exists:countries,id"]
        ];
    }

    public function messages()
    {
        return [
            'required_without_all' => 'At least one field is required.'
        ];
    }
}
