<?php

namespace Modules\Lpj\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class JenisPenilaianKJPPRequest extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        $rules = [
            'code'                       => 'required|max:5',
            'name'                       => 'required|max:255',
        ];

        if ($this->method() == 'PUT') {
            $rules['code'] = 'required|max:5|unique:tujuan_penilaian_kjpp,code,' . $this->id;
        } else {
            $rules['code'] = 'required|max:5|unique:tujuan_penilaian_kjpp,code';
        }

        return $rules;
    }
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    public function messages(): array
    {
        return [
            'code.required' => 'Kode Tujuan Penilaian KJPP Wajib diisi!',
            'code.max' => 'Kode Tujuan Penilaian KJPP maksimum 5 huruf!',
            'code.unique' => 'Kode Tujuan Penilaian KJPP tidak boleh sama!',
            'name.required' => 'Nama Tujuan Penilaian KJPP Wajib diisi!',
            'name.max' => 'Nama Tujuan Penilaian KJPP Wajib diisi!'
        ];
    }
}
