<?php

namespace LaraBB\Translate\Actions;

use LaraBB\Translate\Tasks\StoreTranslationsTask;
use Illuminate\Http\Request;

/**
 * Class TranslateAction
 * @package LaraBB\Translate\Actions
 */
class TranslateAction
{
    /**
     * TranslateAction constructor.
     * @param StoreTranslationsTask $storeTranslationsTask
     */
    public function __construct(private readonly StoreTranslationsTask $storeTranslationsTask)
    {
    }

    /**
     * @param Request $request
     * @return false|int
     */
    public function run(Request $request)
    {
        $data['lang']        = $request->get('lang');
        $data['translation'] = json_encode(array_combine($request->get('keys'), $request->get('translations')), JSON_UNESCAPED_UNICODE);

        return $this->storeTranslationTask->run($data);
    }
}
