<?php

namespace App\Http\Requests;

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

class AccountRequest 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('subheadcommit'))
        {
           return $this->storeSubHead();
        }
        elseif($current_path === url('subheadupdate'))
        {
           return $this->updateSubHead();
        }
    }

    public function storeSubHead(){
      
                                  

    try
        {
             return [

           // 'code'           =>  'required|min:0|max:999999999999999999999',
           'name'           =>  'required|min:0|max:100',
           'type'           =>  'required|in:General,Cash,Bank,Expense,Liability',
           'head_id'        =>  ['required', new ExistRule('heads','id')],
           'bank'           =>  [new ExistRule('banks','id',false)],



           
                   
            ];

        

        }
        catch (\Exception $e) 
        {
            
        }
   }


    public function updateSubHead()
    {
        return [

           // 'code'           =>  'required|min:0|max:999999999999999999999',
           'name'           =>  'required|min:0|max:100',
           'type'           =>  'nullable|in:General,Cash,Bank,Expense,Liability',
           'subhead_id'     =>  ['required', new ExistRule('accounts','id')],
           'bank'           =>  [new ExistRule('banks','id',false)],
           
           
        ];
    }
}
