package com.cretin.webapi.controller.v2

import com.cretin.webcore.utils.GsonGet
import com.cretin.webdb.common.Resp
import com.cretin.webdb.request.*
import com.cretin.webdb.request.v2.*
import com.cretin.webservices.service.api.v2.V2TranslateService
import com.github.javaparser.JavaParser
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration
import com.google.gson.internal.LinkedTreeMap
import org.apache.http.util.TextUtils
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*
import java.io.File
import java.io.FileInputStream
import javax.management.loading.MLet
import javax.servlet.http.HttpServletRequest


/**
 * 负责桌面端的接口
 */
@RestController
@RequestMapping("/v2/desktop/translate")
@ResponseBody
class DesktopTranslateController {

    @Autowired
    private var desktopTranslateService: V2TranslateService? = null

    /**
     * 上传翻译
     */
    @PostMapping("/upload")
    fun upload(
        @RequestBody data: DesktopTranslateAddRequest,
        httpServletRequest: HttpServletRequest
    ): Any? {
        return Resp(desktopTranslateService?.upload(data, httpServletRequest))
    }

    /**
     * 初始化
     */
    @PostMapping("/init")
    fun init(
        @RequestBody data: DesktopTranslateInitRequest,
        httpServletRequest: HttpServletRequest
    ): Any? {
        return Resp(desktopTranslateService?.init(data, httpServletRequest))
    }

    /**
     * 同步项目信息
     */
    @PostMapping("/project/async")
    fun projectAsync(
        @RequestBody data: DesktopTranslateAsyncRequest,
        httpServletRequest: HttpServletRequest
    ): Any? {
        return Resp(desktopTranslateService?.projectAsync(data, httpServletRequest))
    }

    /**
     * 登录
     */
    @PostMapping("/login")
    fun login(
        @RequestBody data: DesktopTranslateLoginRequest,
        httpServletRequest: HttpServletRequest
    ): Any? {
        return Resp(desktopTranslateService?.login(data, httpServletRequest))
    }

    /**
     * 下载前的预览
     */
    @PostMapping("/download/pre")
    fun downloadPre(
        @RequestBody data: DesktopTranslateListRequest,
        httpServletRequest: HttpServletRequest
    ): Any? {
        return Resp(desktopTranslateService?.downloadPre(data, httpServletRequest))
    }

    /**
     * x2js json 转 xmlbuilder json
     */
    @PostMapping("/download/data_convert")
    fun downloadDataConvert(
        @RequestBody data: DesktopTranslateDataConvertRequest,
        httpServletRequest: HttpServletRequest
    ): Any? {
        return Resp(desktopTranslateService?.downloadDataConvert(data, httpServletRequest))
    }

    /**
     * 上传php信息 直接获取可以写入文件的内容
     */
    @PostMapping("/download/php_data_convert")
    fun downloadPhpDataConvert(
        @RequestBody data: DesktopTranslatePhpDataConvertRequest,
        httpServletRequest: HttpServletRequest
    ): Any? {
        return Resp(desktopTranslateService?.downloadPhpDataConvert(data, httpServletRequest))
    }

    /**
     * 本地php文件转化成可以预览的内容
     */
    @PostMapping("/common/local_php_convert_pre")
    fun commonLocalPhpConvertPre(
        @RequestBody data: DesktopTranslateDataConvertRequest,
        httpServletRequest: HttpServletRequest
    ): Any? {
        return Resp(desktopTranslateService?.commonLocalPhpConvertPre(data, httpServletRequest))
    }

    /**
     * 获取提示信息
     */
    @PostMapping("/common/tips")
    fun commonTips(
        @RequestBody data: DesktopTranslateTipsRequest,
        httpServletRequest: HttpServletRequest
    ): Any? {
        return Resp(desktopTranslateService?.commonTips(data, httpServletRequest))
    }


    /**
     * 应用更新
     */
    @PostMapping("/common/app_update")
    fun commonAppUpdate(
        @RequestBody data: DesktopTranslateAppUpdateRequest,
        httpServletRequest: HttpServletRequest
    ): Any? {
        return Resp(desktopTranslateService?.commonAppUpdate(data, httpServletRequest))
    }

    /**
     * 下载翻译到本地
     */
    @PostMapping("/download/list")
    fun downloadList(
        @RequestBody data: DesktopTranslateListRequest,
        httpServletRequest: HttpServletRequest
    ): Any? {
        return Resp(desktopTranslateService?.downloadList(data, httpServletRequest))
    }

    /**
     * 获取平台数据
     */
    @PostMapping("/platforms")
    fun platfroms(
        httpServletRequest: HttpServletRequest
    ): Any? {
        return Resp(desktopTranslateService?.platfroms(httpServletRequest))
    }

}

