<?php

namespace App\Http\Requests;

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


class RightRequest 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('rightupdate'))
        {
           return $this->updateRight();
        }
        else if($current_path === url('assignrightcommit'))
        {
           return $this->storeAssignRight();

        }
    
    }

    public function updateRight()
    {
        
        return [

            'module'                =>'in:'.implode(',',EF::getModuleList()),
            'feature'               =>'required|min:0|max:25',
            'navigation_type'       =>'in:'.implode(',',EF::getNavigationTypeList()),
            'icon'                  =>'required|min:0|max:25',
            'navigation_priority'   =>'in:'.implode(',',EF::getPriorityList()),
            'status'                =>'in:'.implode(',',EF::getStatusList()),
            'right'                 => new ExistRule('rights','id'),


        ];
    }

    public function storeAssignRight()
    {
        return [

            'user'                 => new ExistRule('users','id'),


        ];
    }
}
