<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

use App\Rules\ExistRule;
use EF;

class SettingRequest 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()
    {
        EF::errorMessage("Required form validation.");

       $current_path = url()->current();

       if ($current_path === url('settingcommit')) 
       {
           return $this->getValidationList();

           return $validation;
       }
       elseif ($current_path === url('settingupdate')) 
       {

           return $this->getValidationList();

           $validation += ['setting' => ['required', new ExistRule('settings','id')]];





            return $validation;
       }
    }


    public function getValidationList()
    {

        $setting_type_list = EF::getSettingsTypeList();

        $setting_type_list = implode(',',$setting_type_list);

        $validation = $this->input();

        return [

            'title'      => 'required|min:1|max:50',

            'type'       =>'required|in:'.$setting_type_list,

            'value'      => 'required|integer|between:1,100',
            
        ];
    }
}
