<?php

namespace Eform\Instruction\Http\Controllers;

use App\Http\Controllers\Controller as BaseController;
use Exception;
use Eform\Instruction\Http\Requests\InstructionCategoryActionsRequest;
use Eform\Instruction\Actions\InstructionCategoryActions;

/**
 * Admin web controller class.
 */
class InstructionCategoryActionsController extends BaseController
{

    /**
     * Action controller function for instruction_category.
     *
     * @param Model $model
     * @param action next action for the model.
     *
     * @return Response
     */
    public function __invoke(InstructionCategoryActionsRequest $request, $action)
    {
        try {
            $instruction_category = InstructionCategoryActions::run($request, $action);
            return $this->response->message(trans('messages.success.updated', ['Module' => trans('instruction::instruction_category.name')]))
                ->code(204)
                ->data(compact('data'))
                ->status('success')
                ->url(guard_url('instruction/instruction_category/' . $action))
                ->redirect();
        } catch (Exception $e) {
            return $this->response->message($e->getMessage())
                ->code(400)
                ->status('error')
                ->url(guard_url('instruction/instruction_category/' . $action))
                ->redirect();
        }
    }
}