<?php

namespace App\Http\Controllers\Hr;

use Illuminate\Http\Request;
use App\Http\Requests\ScaleRequest;
use Illuminate\Contracts\Encryption\DecryptException;
use App\Http\Controllers\Controller;
use App\Scale;

class ScaleController extends Controller
{
    public function index()
    {   
        $scale = new Scale;
        
        return view('hr.scale.manage_scale',
        	[

        		'scale_list'       => $scale->getScaleList(),
        		
        	]
    );
       
    }

    public function storeScale(ScaleRequest $request)
    {
        $scale = new Scale;

        $form_collect = $request->input();

        $curr_scale = $scale->storeScale($form_collect);

        if(isset($curr_scale->id))
        {
            parent::setLogMessage('Scale "'.$curr_scale->title.'" has been created');

            parent::successMessage('Scale has been created.',parent::getLogMessage());
        }

        return redirect('scales');
    }


     public function updateScale(ScaleRequest $request)
    {
        try 
        {
            $id = decrypt($request->scale);

            $form_collect = $request->input();

            $scale = new Scale;


            $curr_scale = $scale->updateScale($form_collect,$id);

            if(isset($curr_scale))
            {
                parent::setLogMessage('Scale "'.$curr_scale->title.'" has been updated');

                parent::successMessage('Scale has been updated.',parent::getLogMessage());
            }
        } 
        catch (DecryptException $e) 
        {
            
        }

        return redirect('scales');
    }


}
