<?php

namespace App\Http\Requests;

use Illuminate\Validation\Rule;
use Illuminate\Foundation\Http\FormRequest;

class UpdateCategoryRequest 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
    {
        $prefix = config("srm_config.installer.table_prefix", "srm_");
        return [
            'name' => ["required", "min:4", "max:50", Rule::unique("{$prefix}categories", 'name')
                ->ignore($this->route('category')->id, 'id')],
            "description" => ["nullable", "max:255"],
            "icon" => ["required"]
        ];
    }

    public function messages()
    {
        return [
            "name.required" => "The category name can't be empty.",
            "name.unique" => "This category name is already existed in the database, please try a different name for the category.",
            "name.min" => "The category name must be between 4 and 50 characters.",
            "name.max" => "The category name must be between 4 and 50 characters.",
            "icon.required" => "Please select an icon for this category."
        ];
    }
}
