<?php

namespace App\Http\Requests\InventoryRequests;

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

class BOQRequest 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('Error in Form Submission.');

        $current_path = url()->current();

        if($current_path === url('boqcommit'))
        {
           return $this->getValidationList();
        }
        elseif($current_path === url('boqaccept'))
        {
           return $this->getValidationListAccept();
        }
        elseif($current_path === url('createpurchasecommit'))
        {
           return $this->getValidationList();
        }
        elseif($current_path === url('qoutationSubmit'))
        {
           return $this->getValidationListQoutation();
        }


    }

     public function getValidationList()
    {

        $validation = [
           'project'                 =>  ['required', new ExistRule('branches','id')],
           //'item.*'                  =>  ['required', new ExistRule('items','id')],
           //'remarks'                 => 'nullable|min:0,max:500',
           //'item_quantity.*'         => 'gt:0',
           'item_date'             =>  'required|date|date_format:Y-m-d|after:1970-01-01',
        ];


        return $validation;
    }


    public function getValidationListAccept()
   {
       $validation = [
          'user_id.*'               =>  ['required', new ExistRule('users','id')],
          //'remarks.*'               => 'required|min:0,max:500',
          //'quotation.*'             => 'nullable|mimes:pdf,doc,docx,xls|max:10240',
          'unit_price.*'         => 'gt:0',
          'item_description.*'      =>  'required|max:500',
          'item_date.*'             =>  'required|date|date_format:Y-m-d|after:1970-01-01',
       ];
       return $validation;
   }

   public function getValidationListQoutation()
  {
      $validation = [
         'user_id'               =>  ['required', new ExistRule('users','id')],
         'remarks'               => 'required|min:0,max:500',
         'file'             => 'required|mimes:pdf,doc,docx,xls|max:10240',
      ];
      return $validation;
  }
}
