<?php

namespace App\Http\Requests;

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

class DeductionRequest 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('deductioncommit')||('payrolldeductioncommit'))
        {
            $validation = $this->getValidationList();

            $validation['status'] = 'nullable';

            return $validation;
        }
         elseif($current_path === url('deductionupdate'))
        {
            $validation = $this->getValidationList();

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



            $validation['employee'] = 'nullable';



            return $validation;
           
        }
    }

    public function getValidationList()
    {

        return [


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

            'amount'          =>'required|integer|bail|gt:0',
            
        ];
    }
}
