<?php

namespace LaraBB\Translate\UI\Web\Handlers;

use App\Http\Controllers\Controller;
use LaraBB\Translate\Actions\TranslateAction;
use Illuminate\Http\RedirectResponse;
use LaraBB\Translate\UI\Web\Requests\Store;

/**
 * Class TranslateHandler
 * @package LaraBB\Translate\UI\Web\Handlers
 */
class TranslateHandler extends Controller
{
    /**
     * @var TranslateAction|object
     */
    private $translateAction;

    /**
     * TranslateHandler constructor.
     * @param TranslateAction $translateAction
     */
    public function __construct(TranslateAction $translateAction)
    {
        $this->translateAction = $translateAction;
    }

    /**
     * @param Store $request
     * @return RedirectResponse
     */
    public function __invoke(Store $request): RedirectResponse
    {
        return $this->translateAction->run($request) ? $request->success() : $request->failed();
    }
}
