<?php

namespace App\Http\Requests\Farm;

use Illuminate\Foundation\Http\FormRequest;

class FarmRequest 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 [
            "code" => [
                "required",
                "string",
                $this->route()->farm
                    ? "unique:farms,code," . $this->route()->farm
                    : "unique:farms,code",
            ],
            "name" => ["required"],
            "lead_man_id" => ["nullable", "exists:users,id"],
            "lead_man_name" => ["nullable", "string", "max:255"],
        ];
    }

    public function attributes(): array
    {
        return [
            "lead_man_id" => "lead man",
            "lead_man_name" => "lead man name",
        ];
    }

    public function messages(): array
    {
        return [
            "lead_man_id.exists" =>
            "The selected :attribute doesn't exist in user.",
        ];
    }
}
