package com.cretin.webapi.controller.v2

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 org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartFile
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse


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

    @Autowired
    private var desktopTranslateService: V2TranslateService? = null


    /**
     * 下载翻译
     */
    @PostMapping("/list")
    fun list(
        @RequestBody data: AdminTranslateListRequest,
        httpServletRequest: HttpServletRequest
    ): Any? {
        return Resp(desktopTranslateService?.list(data, httpServletRequest))
    }

    /**
     * 语言渠道配置
     */
    @PostMapping("/channel/select")
    fun channelSelect(
        @RequestBody data: TranslateChannelConfigRequest,
        httpServletRequest: HttpServletRequest
    ): Any? {
        desktopTranslateService?.channelSelect(data, httpServletRequest)
        return Resp.createSuccess()
    }

    /**
     * 导出excel
     */
    @PostMapping("/excel/export")
    fun exportExcel(
        @RequestBody data: TranslateExcelExportRequest,
        httpServletResponse: HttpServletResponse
    ) {
        desktopTranslateService?.excelExport(data, httpServletResponse)
    }

    /**
     * 导入excel
     */
    @PostMapping("/excel/import")
    fun importExcel(
//        @RequestBody data: TranslateExcelExportRequest,
        @RequestParam("appId") appId: Int,
        @RequestParam("file") file: MultipartFile,
        httpServletResponse: HttpServletResponse
    ): Any? {
        return Resp(desktopTranslateService?.importExcel(appId,file, httpServletResponse))
    }

    /**
     * 获取应用信息
     */
    @PostMapping("/app/info")
    fun appInfo(
        httpServletResponse: HttpServletResponse
    ): Any? {
        return Resp(desktopTranslateService?.appInfo(httpServletResponse))
    }

    /**
     * 在线翻译
     */
    @PostMapping("/online/convert")
    fun onlineConvert(
        @RequestBody data: TranslateOnlineConvertRequest,
        httpServletRequest: HttpServletRequest
    ): Any? {
        return Resp(desktopTranslateService?.onlineConvert(data, httpServletRequest))
    }

    /**
     * 项目列表
     */
    @PostMapping("/project/list")
    fun projectList(@RequestBody data: TranslateProjectListRequest, httpServletRequest: HttpServletRequest): Any? {
        return Resp(desktopTranslateService?.projectList(data, httpServletRequest))
    }

    /**
     * 项目创建
     */
    @PostMapping("/project/create")
    fun projectCreate(@RequestBody data: TranslateProjectCreateRequest, httpServletRequest: HttpServletRequest): Any? {
        desktopTranslateService?.projectCreate(data, httpServletRequest)
        return Resp.createSuccess()
    }

    /**
     * 配置module
     */
    @PostMapping("/module/config")
    fun moduleConfig(
        @RequestBody data: TranslateModuleConfigRequest,
        httpServletRequest: HttpServletRequest
    ): Any? {
        desktopTranslateService?.moduleConfig(data, httpServletRequest)
        return Resp.createSuccess()
    }

    /**
     * 渠道列表获取
     */
    @PostMapping("/channel/list")
    fun translateAllChannelList(
        @RequestBody data: TranslateChannelListRequest,
        httpServletRequest: HttpServletRequest
    ): Any? {
        return Resp(desktopTranslateService?.translateAllChannelList(data, httpServletRequest))
    }

    /**
     * 渠道列表更新
     */
    @PostMapping("/channel/list/update")
    fun translateAllChannelListUpdate(
        @RequestBody data: TranslateChannelUpdateRequest,
        httpServletRequest: HttpServletRequest
    ): Any? {
        desktopTranslateService?.translateAllChannelListUpdate(data, httpServletRequest)
        return Resp.createSuccess()
    }


    /**
     * 修改翻译
     */
    @PostMapping("/edit")
    fun editTranslate(
        @RequestBody data: TranslateEditRequest,
        httpServletRequest: HttpServletRequest
    ): Any? {
        desktopTranslateService?.editTranslate(data, httpServletRequest)
        return Resp.createSuccess()
    }

}