<?php

namespace App\Http\Requests\Admin;

use Illuminate\Foundation\Http\FormRequest;

class ServerGroupStoreRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return $this->user()->can('create', \App\Models\ServerGroup::class);
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'name' => 'required|string|max:255|unique:server_groups',
            'fill_strategy' => 'required|in:random,fill_first,balanced',
            'servers' => 'nullable|array',
            'servers.*' => 'exists:servers,id',
        ];
    }

    /**
     * Get custom error messages for validator errors.
     */
    public function messages(): array
    {
        return [
            'name.required' => __('admin/server-groups.validation.name.required'),
            'name.unique' => __('admin/server-groups.validation.name.unique'),
            'fill_strategy.required' => __('admin/server-groups.validation.fill_strategy.required'),
            'fill_strategy.in' => __('admin/server-groups.validation.fill_strategy.in'),
            'servers.*.exists' => __('admin/server-groups.validation.servers.exists'),
        ];
    }
}
