<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class RideRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true; // Add authorization logic as needed
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        $rules = [
            'name' => ['required', 'string', 'max:255'],
            'description' => ['nullable', 'string'],
            'is_active' => ['boolean'],
        ];

        // For updates, make name unique except for current record
        if ($this->route('ride')) {
            $rules['name'][] = 'unique:rides,name,' . $this->route('ride')->id;
        } else {
            $rules['name'][] = 'unique:rides,name';
        }

        return $rules;
    }

    /**
     * Get custom messages for validator errors.
     */
    public function messages(): array
    {
        return [
            'name.required' => 'The ride name is required.',
            'name.unique' => 'A ride with this name already exists.',
        ];
    }
}