package org.jeecg.modules.okki.translate.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHeaders;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.okki.translate.dto.TranslateRequestDto;
import org.jeecg.modules.okki.translate.dto.TranslateResults;
import org.jeecg.modules.okki.translate.service.TranslateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;

@RestController
@Slf4j
@RequestMapping("/website")
public class TranslateApiController {

    @Autowired
    private TranslateService translateService;

    @PostMapping(value = "/translate")
    public Result<TranslateResults> add(@RequestBody TranslateRequestDto translateRequestDto, @RequestHeader(HttpHeaders.AUTHORIZATION) String authorization) throws UnsupportedEncodingException {
        log.info("请求参数 param{} authorization{}", translateRequestDto.toString(), authorization);
        String Authorization = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImRlYW4iLCJleHAiOjE3MTQ0NjU5Njl9.QdCBYR8mioXcKGi1n5RdMQ5RbJHCSGbE8dkdwYuOXh4";

        if (!authorization.equals(Authorization)) {
            return Result.error("sign 验证不通过");
        }

        TranslateResults translateResults = translateService.doTranslate(translateRequestDto);

        return Result.OK(translateResults);
    }
}
