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


import com.zanxiang.game.module.sdk.annotation.UnSignCheck;
import com.zanxiang.game.module.sdk.annotation.ValidLogin;
import com.zanxiang.game.module.sdk.enums.DataTypeEnum;
import com.zanxiang.game.module.sdk.pojo.param.*;
import com.zanxiang.game.module.sdk.pojo.vo.CustomerVO;
import com.zanxiang.game.module.sdk.pojo.vo.GameShareVO;
import com.zanxiang.game.module.sdk.pojo.vo.UserLoginVO;
import com.zanxiang.game.module.sdk.pojo.vo.UserVO;
import com.zanxiang.game.module.sdk.service.*;
import com.zanxiang.module.util.pojo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

/**
 * @author : lingfeng
 * @time : 2022-06-16
 * @description : 用户接口
 */
@Api(tags = "用户接口")
@RestController
@RequestMapping(value = "/api/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @Autowired
    private IUserCardService userCardService;

    @Autowired
    private IGameUserRoleService gameUserRoleService;

    @Autowired
    private IUserShareService userShareService;

    @Autowired
    private IGameShellLogService gameShellLogService;

    @Autowired
    private IMsgSceneCheckService msgSceneCheckService;

    @ApiOperation(value = "游戏分享信息")
    @GetMapping("/share/game")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameShareVO.class)})
    public ResultVO<GameShareVO> shareGame(UserData userData) {
        return ResultVO.ok(userShareService.getGameShare(userData));
    }

    @ApiOperation(value = "忘记密码找回")
    @PostMapping("/find/password")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = UserLoginVO.class)})
    public ResultVO<Boolean> findPassword(@Validated @RequestBody FindPasswordParam param, UserData userData) {
        return userService.findPassword(param, userData);
    }

    @ApiOperation(value = "用户修改密码")
    @PostMapping("/update/password")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = UserLoginVO.class)})
    public ResultVO<Boolean> updatePassword(@Validated @RequestBody UpdatePasswordParam param, @ValidLogin UserData userData) {
        return userService.updatePassword(param, userData);
    }

    @ApiOperation(value = "用户绑定手机")
    @PostMapping("/bind/phone")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = UserLoginVO.class)})
    public ResultVO<Boolean> bindPhone(@Validated @RequestBody BindPhoneParam param, @ValidLogin UserData userData) {
        return userService.bindPhone(param, userData);
    }

    @ApiOperation(value = "用户实名认证")
    @PostMapping("/authentication")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = UserLoginVO.class)})
    public ResultVO<Boolean> userAuthentication(@Validated @RequestBody UserCardUpdateParam param, @ValidLogin UserData userData) {
        return userCardService.userAuthentication(param, userData);
    }

    @ApiOperation(value = "获取用户信息")
    @GetMapping("/get/detail")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = UserVO.class)})
    public ResultVO<UserVO> getUserDetail(@ValidLogin UserData userData) {
        return ResultVO.ok(userService.getUserDetail(userData));
    }

    @ApiOperation(value = "获取客服信息")
    @GetMapping("/get/customer")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = CustomerVO.class)})
    public ResultVO<CustomerVO> getUserCustomer(UserData userData) {
        return ResultVO.ok(userService.getUserCustomer(userData));
    }

    @ApiOperation(value = "上传角色信息")
    @PostMapping("/update/game/role")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> updateUserGameRole(@Validated @RequestBody GameUserRoleUpdateParam param, @ValidLogin UserData userData) {
        Boolean result = gameUserRoleService.updateUserGameRole(param, userData);
        //创建角色通知监听服务
        if (Objects.equals(param.getDataType(), DataTypeEnum.TYPE_CREATE_ROLE.getDateType())) {
            gameUserRoleService.callListenIn(param, userData);
        }
        return ResultVO.ok(result);
    }

    @ApiOperation(value = "用户活跃信息上报")
    @PostMapping("/active/call/role")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> gameRoleActiveCall(@Validated @RequestBody GameRoleActiveCallParam param, @ValidLogin UserData userData) {
        return ResultVO.ok(gameUserRoleService.gameRoleActiveCall(userData, param));
    }

    @UnSignCheck
    @ApiOperation(value = "用户进入壳包上报")
    @PostMapping("/game/shell/call")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> gameShellLogAdd(@Validated @RequestBody GameShellLogParam param, HttpServletRequest request) {
        return ResultVO.ok(gameShellLogService.gameShellLogAdd(param, request));
    }

    @ApiOperation(value = "敏感词检测")
    @PostMapping("/msg/check")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = String.class)})
    public ResultVO<String> msgCheck(@Validated @RequestBody MsgSceneCheckParam param, @ValidLogin UserData userData) {
        return ResultVO.ok(msgSceneCheckService.msgCheck(param, userData));
    }
}
