package com.xy.service;

import com.xy.annotate.RestMappingController;
import com.xy.dto.TranslateDto;
import com.xy.service.impl.SysMenuServiceImpl;
import com.xy.translate.baidu.TransApi;
import com.xy.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * 翻译服务
 */
@Api(tags = "翻译服务")
@Slf4j
@Service
@RequiredArgsConstructor
@RestMappingController("/translate")
public class TranslateService {


    private final SysMenuServiceImpl sysMenuService;

    @PostMapping("/menuOne")
    @ApiOperation("单个菜单翻译-同步返回结果")
    public R<String> translateMenuOne(@RequestBody @Validated TranslateDto.One one) {
        String content = one.getContent();
        String targetType = one.getTargetType();
        String translatedValue = TransApi.translate(content, "zh", targetType);
        return R.ok(translatedValue);
    }


    /**
     * 全量菜单翻译
     *
     * @return
     */
    @PostMapping("/menuAll")
    @ApiOperation("菜单全量翻译-已翻译的忽略")
    public R<?> translateMenuAll() {
        sysMenuService.translateAllMenu();
        return R.ok();
    }


}
