package com.zanxiang.game.module.manage.controller;

import com.zanxiang.erp.security.annotation.PreAuthorize;
import com.zanxiang.game.module.manage.pojo.params.KfApiParam;
import com.zanxiang.game.module.manage.pojo.params.KfUserUpdateParam;
import com.zanxiang.game.module.manage.pojo.vo.KfGameVO;
import com.zanxiang.game.module.manage.service.IKfMsgService;
import com.zanxiang.game.module.manage.service.IKfUserService;
import com.zanxiang.module.util.JsonUtil;
import com.zanxiang.module.util.pojo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import reactor.util.function.Tuple2;

import java.util.List;

/**
 * @author : lingfeng
 * @time : 2023-11-29
 * @description : 客服系统接口
 */
@RestController
@RequestMapping("/kf")
@Slf4j
public class KfMsgController {

    @Autowired
    private IKfMsgService kfMsgService;

    @Autowired
    private IKfUserService kfUserService;

    @PostMapping(value = "/upload/msg")
    @PreAuthorize(permissionKey = "manage:kf:uploadMsg")
    public ResultVO<Tuple2<String, String>> uploadMsg(String param, MultipartFile files) {
        return ResultVO.ok(kfMsgService.uploadMsg(JsonUtil.toObj(param, KfApiParam.class), files));
    }

    @GetMapping(value = "/game/list")
    @PreAuthorize(permissionKey = "manage:kf:gameList")
    public ResultVO<List<KfGameVO>> list() {
        return ResultVO.ok(kfMsgService.getKfGameList());
    }

    @PostMapping(value = "/comm/api")
    @PreAuthorize(permissionKey = "manage:kf:commApi")
    public ResultVO<String> list(@Validated @RequestBody KfApiParam param) {
        return ResultVO.ok(kfMsgService.kfApi(param));
    }

    @GetMapping(value = "/auth/code")
    @PreAuthorize(permissionKey = "manage:kf:authCode")
    public ResultVO<String> getAuthCode(@RequestParam String appId) {
        return ResultVO.ok(kfUserService.getAuthCode(appId));
    }

    @PostMapping(value = "/user/update")
    @PreAuthorize(permissionKey = "manage:kf:userUpdate")
    public ResultVO<Boolean> kfUserUpdate(@Validated @RequestBody KfUserUpdateParam param) {
        return ResultVO.ok(kfUserService.kfUserUpdate(param));
    }
}
