<?php

namespace App\Http\Requests;

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

class CommissionRequest 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('commissioncommit'))
        {
           return $this->storeCommission();
        }
         elseif($current_path === url('commissionupdate'))
        {
           return $this->updateCommission();
        }
        elseif($current_path === url('extrachargescommit'))
        {
           return $this->storeExtraCharges();
        }
         elseif($current_path === url('extrachargesupdate'))
        {
           return $this->updateExtraCharges();
        }
    
    }

    public function storeCommission()
    {
        $validate = $this->input();
        
 
        return [

             'user_id'               =>  ['required', new ExistRule('users','id'), new CommissionExistRule($validate)],
             'percentage'            =>  'required|between:0.001,100',
             'amount'                =>  'required',
             'description'           =>  'required|min:1|max:100',
  

          
        ];
    }
      public function storeExtraCharges()
    {
        $validate = $this->input();

        $allowed_type = 'Document Charges,Miscellaneous Charges';
 
        return [

             'charges_type'                  => 'In:'.$allowed_type,
             'amount'                        =>  'required|gt:0',
             'description'                   =>  'required|min:1|max:100',
  

          
        ];
    }
     public function updateCommission()
    {
        $validate = $this->input();
        return [

             'percentage'            =>  'required|between:0.001,100',
            
             'updateamount'                =>  'required',
             'description'                 =>  'required|min:1|max:100',
          
        ];
    }
     public function updateExtraCharges()
    {
        $validate = $this->input();
        return [

            
             'updateamount'                =>  'required|gt:0',
             'description'                 =>  'required|min:1|max:100',
          
        ];
    }
}