<?php

    namespace Modules\Lpj\Http\Requests;

    use Illuminate\Foundation\Http\FormRequest;

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

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

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