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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zanxiang.erp.security.annotation.PreAuthorize;
import com.zanxiang.game.module.manage.pojo.params.*;
import com.zanxiang.game.module.manage.pojo.vo.*;
import com.zanxiang.game.module.manage.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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author : lingfeng
 * @time : 2022-06-29
 * @description : 玩家管理接口
 */
@Api(tags = {"玩家管理接口"})
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private IUserService userService;

    @Autowired
    private IUserAddressService userAddressService;

    @Autowired
    private IUserLoginLogService userLoginLogService;

    @Autowired
    private IOrderService orderService;

    @Autowired
    private IGameUserService gameUserService;

    @Autowired
    private IGameUserRoleService gameUserRoleService;

    @Autowired
    private IUserCardService userCardService;

    @ApiOperation(value = "玩家列表")
    @PostMapping(value = "/list")
    @PreAuthorize(permissionKey = "manage:user:list")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = UserListVO.class)})
    public ResultVO<IPage<UserListVO>> list(@Validated @RequestBody UserListParam param) {
        return ResultVO.ok(userService.list(param));
    }

    @ApiOperation(value = "玩家信息编辑")
    @PostMapping(value = "/update")
    @PreAuthorize(permissionKey = "manage:user:update")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> userUpdate(@Validated @RequestBody UserUpdateParam param) {
        return ResultVO.ok(userService.userUpdate(param));
    }

    @ApiOperation(value = "玩家详细信息")
    @GetMapping(value = "/info")
    @PreAuthorize(permissionKey = "manage:user:info")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = UserVO.class)})
    public ResultVO<UserVO> getUserInfo(@RequestParam Long id) {
        return ResultVO.ok(userService.getUserInfo(id));
    }

    @ApiOperation(value = "玩家登录记录列表")
    @PostMapping(value = "/login/list")
    @PreAuthorize(permissionKey = "manage:user:loginList")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = UserRoleLoginVO.class)})
    public ResultVO<IPage<UserRoleLoginVO>> loginList(@RequestBody UserLoginLogParam param) {
        return ResultVO.ok(userLoginLogService.loginList(param));
    }

    @ApiOperation(value = "玩家下单记录列表")
    @PostMapping(value = "/order/list")
    @PreAuthorize(permissionKey = "manage:user:orderList")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = UserOrderListVO.class)})
    public ResultVO<IPage<UserOrderListVO>> orderList(@Validated @RequestBody UserOrderListParam param) {
        return ResultVO.ok(orderService.orderList(param));
    }

    @ApiOperation(value = "玩家收货地址列表")
    @GetMapping(value = "/address/list")
    @PreAuthorize(permissionKey = "manage:user:addressList")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = UserAddressVO.class, responseContainer = "list")})
    public ResultVO<List<UserAddressVO>> list(@RequestParam Long userId) {
        return ResultVO.ok(userAddressService.list(userId));
    }

    @ApiOperation(value = "玩家游戏列表")
    @PostMapping(value = "/game/list")
    @PreAuthorize(permissionKey = "manage:user:gameList")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameUserListVO.class)})
    public ResultVO<IPage<GameUserListVO>> gameUserList(@Validated @RequestBody GameUserListParam param) {
        return ResultVO.ok(gameUserService.gameUserList(param));
    }

    @ApiOperation(value = "玩家游戏角色")
    @GetMapping(value = "/game/role/list")
    @PreAuthorize(permissionKey = "manage:user:gameRoleList")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameUserRoleVO.class, responseContainer = "list")})
    public ResultVO<List<GameUserRoleVO>> roleList(@RequestParam Long userId) {
        return ResultVO.ok(gameUserRoleService.roleList(userId));
    }

    @ApiOperation(value = "玩家游戏角色列表")
    @PostMapping(value = "/role/list")
    @PreAuthorize(permissionKey = "manage:user:roleList")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameUserRoleListVO.class)})
    public ResultVO<IPage<GameUserRoleListVO>> roleList(@Validated @RequestBody GameUserRoleListParam param) {
        return ResultVO.ok(gameUserRoleService.list(param));
    }

    @ApiOperation(value = "玩家游戏角色Excel下载")
    @PostMapping(value = "/role/list/excel")
    @PreAuthorize(permissionKey = "manage:user:roleListExcel")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功")})
    public void getGameUserRoleExcel(@Validated @RequestBody GameUserRoleListParam param, HttpServletResponse response) {
        gameUserRoleService.getGameUserRoleExcel(param, response);
    }

    @ApiOperation(value = "玩家实名认证列表")
    @PostMapping(value = "/card/list")
    @PreAuthorize(permissionKey = "manage:userCard:list")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = UserCardVO.class)})
    public ResultVO<IPage<UserCardVO>> authList(@Validated @RequestBody UserNameAuthListParam param) {
        return ResultVO.ok(userCardService.getUserCardList(param));
    }

    @ApiOperation(value = "获取用户微信信息")
    @GetMapping(value = "/weChat/info")
    @PreAuthorize(permissionKey = "manage:user:weChatInfo")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = UserWeChatVO.class)})
    public ResultVO<UserWeChatVO> getUserWeChat(@RequestParam Long userId) {
        return ResultVO.ok(userService.getUserWeChat(userId));
    }

    @ApiOperation(value = "小游戏玩家导量到H5游戏")
    @PatchMapping(value = "/applet/to/h5")
    @PreAuthorize(permissionKey = "manage:user:appletToH5")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> appletToH5(@RequestParam Long userId, @RequestParam String mobile, @RequestParam Integer type) {
        return ResultVO.ok(userService.appletToH5(userId, mobile, type));
    }
}
