<?php

namespace App\Http\Requests;

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

class ScaleRequest 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('scalecommit'))
        {
           return $this->storeScale();
        }

        elseif($current_path === url('scaleupdate'))
        {
            return $this->updateScale();
        }
       
    }

     public function storeScale()
    {
      
        return [

             'code'                          =>  'required|unique:scales|min:3|max:50',
             'title'                         =>  'required|min:1|max:50',
            
           
             
          
        ];
    }


     public function updateScale()
    {
      
        return [

             'scale'                         =>  ['required', new ExistRule('scales','id')],
             'title'                         =>  'required|min:1|max:50',
              'code'                         => ['required','min:3','max:50', new UpdateUniqueRule('scales','code',$this->scale)],
             
             
          
        ];
    }

    }
