<?php

namespace Gisplus\Package\Crm\Requests;

use App\Rules\ExistRule;
use App\Rules\UpdateUniqueRule;
use Illuminate\Support\Facades\Request;
use Illuminate\Foundation\Http\FormRequest;

class BusinessReferralRequest 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('referralcommit')) {

          
            $validation = $this->getValidationList();
            return $validation;
        }
        else if (Request::is('updatebusinessreferral')) {
            $validation = $this->getValidationList();


            $validation['business_referral'] = ['required', new ExistRule('business_referrals', 'id')];

            $validation['email'] = ['nullable', 'email', new UpdateUniqueRule('business_referrals', 'email', $this->business_referral_id)];


            return $validation;
        }
    
      

    }



    public function getValidationList()
    {
        $validation = [

            'referral_name'     =>  'required|min:0|max:50',
            'referral_cnic'     =>  'required|min:0|max:50,',
            'referral_email'    =>  'nullable|min:0|max:60',
            'referral_contact'  =>  'nullable|min:0|max:60',
            'company_name'      =>  'nullable|min:0|max:100',


        ];

        return $validation;
    }
}
