<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class ContractDetailRequest 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()
    {
         $current_path = url()->current();

        if($current_path === url('updatecontractdetail'))
        {
            $validation = $this->getValidationList();

          

            return $validation;
        }
    }


    public function getValidationList()
    {
        if($this->percentage > 0)
        {
           
            return [

                'amount'       => 'nullable|In:0',
                'percentage'    => 'required|integer|bail|between:0.001,100',

                // 'detail_id'    => ['required', new ExistRule('contract_details','id')]
                    
                ];
        }
        else
        {
            return [

                'amount'       => 'required|integer|bail|gt:0',
                'percentage'    => 'nullable|In:0',

            // 'detail_id'    => ['required', new ExistRule('contract_details','id')]

                
            ];
        }

      
    }
}
