<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use App\Rules\ExistRule;
use EF;

class HeadRequest 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('headcommit'))
        {
           return $this->storeHead();
        }
        elseif($current_path === url('headupdate'))
        {
           return $this->updateHead();
        }
    
    }

    public function storeHead(){

        $nature_list = implode(',', EF::getNatureList());

    try
        {
             return [

           'code'           =>  'required',
           'name'           =>  'required|min:0|max:100',
           'nature'         =>  'required|in:'.$nature_list,
           // EF::branchWhiteLabel()['module']  =>  ['required', new ExistRule('branches','id')],
           
                   
            ];

        }
        catch (\Exception $e) 
        {
            
        }
   }


    public function updateHead()
    {
     
        $nature_list = implode(',', EF::getNatureList());
     
        return [

           'head_id'        =>  ['required', new ExistRule('heads','id')],
           // 'code'           =>  'required|min:0|max:999999999999999999999|integer',
           'name'           =>  'required|min:0|max:100',
           // 'nature'         =>  'required|in:'.$nature_list,
           // EF::branchWhiteLabel()['module']  =>  ['required', new ExistRule('branches','id')],
           
           
        ];
    }
}
