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.IpBanVO;
import com.zanxiang.game.module.manage.pojo.vo.UserBanVO;
import com.zanxiang.game.module.manage.service.IIpBanService;
import com.zanxiang.game.module.manage.service.IUserBanService;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : lingfeng
 * @time : 2022-06-28
 * @description : 封禁管理接口
 */
@Api(tags = {"封禁管理接口"})
@RestController
@RequestMapping("/ban")
@Slf4j
public class UserBanController {

    @Autowired
    private IIpBanService ipBanService;

    @Autowired
    private IUserBanService userBanService;

    @ApiOperation(value = "查询ip封禁列表")
    @PostMapping(value = "/ip/list")
    @PreAuthorize(permissionKey = "manage:ipBan:list")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = IpBanVO.class)})
    public ResultVO<IPage<IpBanVO>> list(@Validated @RequestBody IpBanListParam param) {
        return ResultVO.ok(ipBanService.list(param));
    }

    @ApiOperation(value = "添加封禁ip")
    @PostMapping(value = "/ip/add")
    @PreAuthorize(permissionKey = "manage:ipBan:add")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> addIp(@Validated @RequestBody IpBanAddParam param) {
        return ResultVO.ok(ipBanService.addIp(param));
    }

    @ApiOperation(value = "ip封禁或者解封")
    @PostMapping(value = "/ip/update")
    @PreAuthorize(permissionKey = "manage:ipBan:update")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> ipBanOrRemove(@Validated @RequestBody IpBanUpdateParam param) {
        return ResultVO.ok(ipBanService.ipBanOrRemove(param));
    }

    @ApiOperation(value = "查询玩家封禁列表")
    @PostMapping(value = "/user/list")
    @PreAuthorize(permissionKey = "manage:userBan:list")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = UserBanVO.class)})
    public ResultVO<IPage<UserBanVO>> list(@Validated @RequestBody UserBanListParam param) {
        return ResultVO.ok(userBanService.list(param));
    }

    @ApiOperation(value = "玩家封禁添加或者更新")
    @PostMapping(value = "/user/add/or/update")
    @PreAuthorize(permissionKey = "manage:userBan:addOrUpdate")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> addOrUpdate(@Validated @RequestBody UserBanUpdateParam param) {
        return ResultVO.ok(userBanService.addOrUpdate(param));
    }
}
