<?php

namespace Eform\Faq\Http\Controllers;

use App\Http\Controllers\Controller as BaseController;
use Exception;
use Eform\Faq\Http\Requests\FaqActionsRequest;
use Eform\Faq\Actions\FaqActions;

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

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