<?php

namespace App\Http\Requests;

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

class TaxRequest 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('taxcommit'))
        {
           return $this->storeTax();
        }

        elseif($current_path === url('taxupdate'))
        {
            return $this->updateTax();
        }
       
    }

    public function storeTax()
    {
    
        return [

             'title'      =>  'required|min:1|max:50',
             'percentage' =>  'required|integer|between:1,35',
             'minimum'    =>  'required|integer|bail|gt:0',
             'maximum'    =>  'required|integer|bail|gt:'.$this->minimum,  
        ];
    }

    public function updateTax()
    {
      
        return [

             'tax'        =>  ['required', new ExistRule('taxes','id')],
             'title'      =>  'required|min:1|max:50',
             'percentage' =>  'required|integer|between:1,35',
             'minimum'    =>  'required|integer|bail|gt:0',
             'maximum'    =>  'required|integer|bail|gt:'.$this->minimum,
        ];
    }

  
}
