package com.blueland.common.core.controller;

import com.blueland.common.core.domain.International;
import com.mybatisflex.core.paginate.Page;
import io.swagger.annotations.*;
import com.blueland.common.core.result.AjaxResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.blueland.common.core.service.InternationalService;
import org.springframework.web.multipart.MultipartFile;

import java.io.Serializable;
import java.util.List;

/**
 * 国际化 控制层。
 *
 * @author mybatis-flex-helper automatic generation
 * @since 1.0
 */
@RestController
@RequestMapping("/international")
@Api(value = "国际化", tags = "国际化")
public class InternationalController {

    @Autowired
    private InternationalService internationalService;

    /**
     * 添加 国际化
     *
     * @param international 国际化
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("/save")
    @ApiOperation(value = "添加国际化", notes = "添加国际化", httpMethod = "POST")
    public AjaxResult<Boolean> save(@RequestBody International international) {
        return AjaxResult.operates(internationalService.insert(international));
    }


    /**
     * 根据主键删除国际化
     *
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @PostMapping("/remove")
    @ApiOperation(value = "根据主键删除国际化", notes = "根据主键删除国际化")
    public AjaxResult<Boolean> remove(@RequestBody International international) {
        return AjaxResult.operates(internationalService.deleteById(international.getId()));
    }


    /**
     * 根据主键更新国际化
     *
     * @param international 国际化
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PostMapping("/update")
    @ApiOperation(value = "根据主键更新国际化", notes = "根据主键更新国际化")
    public AjaxResult<Boolean> update(@RequestBody International international) {
        return AjaxResult.operates(internationalService.updateInternational(international));
    }


    /**
     * 查询所有国际化
     *
     * @return 所有数据
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询所有国际化(根据租户)", notes = "查询所有国际化(根据租户)")
    public AjaxResult<List<International>> list(@RequestBody International international) {
        return AjaxResult.success(internationalService.listAll(international));
    }

    /**
     * 返回对应的语言包
     *
     * @return 所有数据
     */
    @GetMapping("/findLangPackage")
    @ApiOperation(value = "返回对应的语言包", notes = "返回对应的语言包")
    public AjaxResult findLangPackage(@RequestParam("type") @ApiParam("类型（前端：front，后端：back）") String type) {
        return AjaxResult.success(internationalService.findLangPackage(type));
    }


    /**
     * 根据国际化主键获取详细信息。
     *
     * @param id international主键
     * @return 国际化详情
     */
    @GetMapping("/getInfo/{id}")
    @ApiOperation(value = "根据国际化主键获取详细信息", notes = "根据国际化主键获取详细信息")
    public AjaxResult<International> getInfo(@PathVariable Serializable id) {
        return AjaxResult.success(internationalService.getById(id));
    }


    /**
     * 分页查询国际化
     *
     * @return 分页对象
     */
    @PostMapping("/page")
    @ApiOperation(value = "分页查询国际化", notes = "分页查询国际化")
    public AjaxResult<Page<International>> page(@RequestBody International international) {
        return AjaxResult.success(internationalService.pageList(international));
    }

    /**
     * 一键复制
     *
     * @param targetLang 目标语言
     * @param sourceLang 源语言
     * @return {@link AjaxResult}<{@link Boolean}>
     */
    @GetMapping("/copy")
    @ApiOperation(value = "一键复制", notes = "例如：数据库只有中文，要翻译成英文")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "tenantId", value = "租户id", dataType = "String", paramType = "query", required = false),
                    @ApiImplicitParam(name = "targetLang", value = "目标语言", dataType = "String", paramType = "query", required = true),
                    @ApiImplicitParam(name = "sourceLang", value = "源语言", dataType = "String", paramType = "query", required = true)
            }
    )
    public AjaxResult<Boolean> copy(@RequestParam("targetLang") String targetLang,
                                    @RequestParam("sourceLang") String sourceLang,
                                    @RequestParam(value = "tenantId", required = false) String tenantId) {
        return AjaxResult.operates(internationalService.copy(targetLang, sourceLang, tenantId));
    }

    @GetMapping("/dowloadTemplate")
    @ApiOperation(value = "下载模板", notes = "下载模板")
    public void dowloadTemplate() {
        internationalService.dowloadTemplate();
    }

    /**
     * 导入
     */
    @PostMapping("/importList")
    @ApiOperation("导入数据")
    public AjaxResult<Boolean> importList(@RequestParam("file") MultipartFile file) {
        return AjaxResult.operates(internationalService.importList(file));
    }

    /**
     * 一键复制（从其他租户复制）
     *
     * @param sourceLang 源语言
     * @return {@link AjaxResult}<{@link Boolean}>
     */
    @GetMapping("/tenantIdCopy")
    @ApiOperation(value = "一键复制（从其他租户复制）", notes = "例如：bio里面有en语言包，现在要复制到AHI里面")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "tenantId", value = "租户id", dataType = "String", paramType = "query", required = true),
                    @ApiImplicitParam(name = "sourceLang", value = "源语言", dataType = "String", paramType = "query", required = true)
            }
    )
    public AjaxResult<Boolean> tenantIdCopy(@RequestParam("sourceLang") String sourceLang,
                                            String tenantId) {
        return AjaxResult.operates(internationalService.tenantIdCopy(sourceLang, tenantId));
    }

}