<?php

namespace App\Http\Requests\Admin;

use Illuminate\Foundation\Http\FormRequest;

class RackUpdateRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        $rack = $this->route('rack');

        return $this->user()->can('update', $rack);
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'datacenter_id' => 'required|exists:datacenters,id',
            'name' => 'required|string|max:255',
            'row' => 'nullable|string|max:255',
            'total_u' => 'required|integer|min:1|max:60',
            'notes' => 'nullable|string',
        ];
    }

    /**
     * Get custom error messages for validator errors.
     */
    public function messages(): array
    {
        return [
            'datacenter_id.required' => __('admin/racks.validation_datacenter_id_required'),
            'datacenter_id.exists' => __('admin/racks.validation_datacenter_id_exists'),
            'name.required' => __('admin/racks.validation_name_required'),
            'total_u.required' => __('admin/racks.validation_total_u_required'),
            'total_u.integer' => __('admin/racks.validation_total_u_integer'),
            'total_u.min' => __('admin/racks.validation_total_u_min'),
            'total_u.max' => __('admin/racks.validation_total_u_max'),
        ];
    }
}
