<?php

namespace Modules\Lpj\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class JenisLaporanRequest 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:jenis_laporan,code,' . $this->id;
        } else {
            $rules['code'] = 'required|max:5|unique:jenis_laporan,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 Jenis Laporan Wajib diisi!',
            'code.max' => 'Kode Jenis Laporan maksimum 5 huruf!',
            'code.unique' => 'Kode Jenis Laporan tidak boleh sama!',
            'name.required' => 'Nama Jenis Laporan Wajib diisi!',
            'name.max' => 'Nama Jenis Laporan Wajib diisi!'
        ];
    }
}
