<?php

namespace App\Http\Requests\Bill;

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

class BillRequest 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()
    {
        parent::errorMessage('Required form validation.');

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

        if($current_path === url('commit_category'))
        {
          $validation = $this->getValidationList();
          return $validation;
        }
        if($current_path === url('commit_subcategory'))
        {
          $validation = $this->getValidationList2();
          return $validation;
        }
        if($current_path === url('commit_bill'))
        {
          $validation = $this->getValidationList3();
          return $validation;
        }
    }

    public function getValidationList()
    {
        $validation = [
          'expense_type'    => 'required|in:Cost of Sales,Administrative',
          'name'            => 'required|min:1|max:100',
        ];

        return $validation;
    }

    public function getValidationList2()
    {
        $validation = [
          'category_id'    => 'required',
          'name'            => 'required|min:1|max:100',
        ];

        return $validation;
    }

    public function getValidationList3()
    {
      $lia_list = implode(',', EF::getBillLaibilityType());
      $pay_list = implode(',', EF::getBilPayableType());
        $validation = [
          'subcategory'            => 'required',
          'total'            => 'required|min:1',
          'laibility_type'            => 'required|in:'.$lia_list,
          'payable_type'            => 'required|in:'.$pay_list,
        ];

        return $validation;
    }



}
