<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests\CallCenterRequest;
use Illuminate\Contracts\Encryption\DecryptException;
use App\CallCenter;

class CallCenterController extends Controller
{

	public function index()
	{
		$call = new CallCenter;

		return view('callcenter.manage_calls',
			[
				'calls'    =>  $call->getCallsList() ,

			]
		);
	}
	public function storeCall(CallCenterRequest $request)
	{
		try 
		{
			$form_collect = $request->input();

			$call = new CallCenter;

			if($call->storeCall($form_collect))
			{
				parent::successMessage('Call has been recorded.',parent::getLogMessage());

			}
		}

		catch (DecryptException $e) 
		{

		}
		return redirect('callcenter');
	}
	public function updateCall(CallCenterRequest $request)
	{

		try
		{

			$form_collect = $request->input();


			$id = decrypt($form_collect['id']);


			$call = new CallCenter;

			if($call->updateCall($form_collect,$id))
			{
				parent::successMessage('Call has been updated.',parent::getLogMessage());
			}   

		}

		catch (DecryptException $e) 
		{

		}

		return redirect()->back();


	}
	    public function removeCall($id)
    {
        parent::errorMessage('Call not found.');

        try 
        {
            $id = decrypt($id);

            $call = new CallCenter;

            if($call->removeCall($id))
            {
                parent::successMessage('Call has been removed.' ,parent::getLogMessage());
            } 
        } 
        catch (DecryptException $e) 
        {
            
        }

        return redirect('callcenter');
    }
}
