package com.ssyf.module.common.controller.auth;

import com.ssyf.common.web.aop.RequestSynchronization;
import com.ssyf.common.web.apicode.ApiCodeThird;
import com.ssyf.common.web.result.Result;
import com.ssyf.module.common.domain.query.BaiduTranslateRequest;
import com.ssyf.third.trans.baidu.BaiduTranslateResult;
import com.ssyf.third.trans.baidu.BaiduTranslateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
* com.ssyf.auth.entity.Script模型开放接口
*
* @author: auth
* @date: 2022-12-12
*/
@Slf4j
@Api(tags="开放接口-百度翻译")
@RestController
@RequestMapping("/auth/BaiduTranslate")
public class BaiduTranslateAuthController {

    @Autowired
    private BaiduTranslateService baiduTranslateService;
    @RequestSynchronization
    @ApiOperation(value = "文本翻译", notes = "文本翻译")
    @PostMapping(value = "/texttrans")
    public Result translate(@RequestBody BaiduTranslateRequest request) {
        BaiduTranslateResult result = baiduTranslateService.translate(request.getText(), request.getFrom(), request.getTo());
        if(result.getTransResult() == null || result.getTransResult().isEmpty()){
            return Result.fail(ApiCodeThird.ERROR.getCode() ,"翻译错误");
        }
        return Result.success(result.getTransResult().get(0).getDst());
    }
}
