<?php

    namespace Modules\Lpj\Http\Requests;

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

    class JenisLampiranRequest extends FormRequest
    {
        /**
         * Determine if the user is authorized to make this request.
         *
         * @return bool
         */
        public function authorize()
        {
            return true;
        }

        /**
         * Get the validation rules that apply to the request.
         *
         * @return array
         */
        public function rules()
        {
            $rules = [
                'nama' => [
                    'required',
                    'string',
                    'max:255',
                    Rule::unique('jenis_lampiran')->where(function ($query) {
                        return $query->whereNull('deleted_at');
                    })->ignore($this->route('jenis_lampiran')),
                ],
                'deskripsi' => 'nullable|string',
            ];

            return $rules;
        }

        /**
         * Get custom messages for validator errors.
         *
         * @return array
         */
        public function messages()
        {
            return [
                'nama.required' => 'Nama jenis lampiran harus diisi.',
                'nama.max'      => 'Nama jenis lampiran tidak boleh lebih dari 255 karakter.',
            ];
        }
    }
