<?php

namespace App\Http\Requests;

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

class DepartmentRequest 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('departmentcommit'))
        {
           return $this->storeDepartment();
        }

        elseif($current_path === url('departmentupdate'))
        {
            return $this->updateDepartment();
        }
         elseif($current_path === url('assigndepartment'))
        {
            return $this->assignDepartment();
        }

    }
     public function storeDepartment()
    {
        $validate = $this->input();
        $department_label_list = EF::departmentWhiteLabel();      
   
        return [
                    $department_label_list['department_code']  => 'required|unique:departments|max:50',

                    $department_label_list['department_name'] => 'required|min:3|max:50',

                    $department_label_list['department_description'] => 'required|max:500',
                      
          
        ];
    }
    public function updateDepartment()
    {
        $validate = $this->input();
        $department_label_list = EF::departmentWhiteLabel();      
   
        return [
                   'department'            => ['required', new ExistRule('departments','id')],
                    $department_label_list['department_code']  => ['required','min:3','max:50', new UpdateUniqueRule('departments','code',$this->department)],

                    $department_label_list['department_name'] => 'required|min:3|max:50',

                    $department_label_list['department_description'] => 'required|max:500',
                      
          
        ];
    }

    public function assignDepartment()
    {
        return 
        [

             'department'            => ['required', new ExistRule('departments','id')],
             'user_id'               => ['required', new ExistRule('users','id')],
        ];

    }
}
