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 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 : 封禁管理接口
 */
@RestController
@RequestMapping("/ban")
@Slf4j
public class UserBanController {

    @Autowired
    private IIpBanService ipBanService;

    @Autowired
    private IUserBanService userBanService;

    @PostMapping(value = "/ip/list")
    @PreAuthorize(permissionKey = "manage:ipBan:list")
    public ResultVO<IPage<IpBanVO>> list(@Validated @RequestBody IpBanListParam param) {
        return ResultVO.ok(ipBanService.list(param));
    }

    @PostMapping(value = "/ip/add")
    @PreAuthorize(permissionKey = "manage:ipBan:add")
    public ResultVO<Boolean> addIp(@Validated @RequestBody IpBanAddParam param) {
        return ResultVO.ok(ipBanService.addIp(param));
    }

    @PostMapping(value = "/ip/update")
    @PreAuthorize(permissionKey = "manage:ipBan:update")
    public ResultVO<Boolean> ipBanOrRemove(@Validated @RequestBody IpBanUpdateParam param) {
        return ResultVO.ok(ipBanService.ipBanOrRemove(param));
    }

    @PostMapping(value = "/user/list")
    @PreAuthorize(permissionKey = "manage:userBan:list")
    public ResultVO<IPage<UserBanVO>> list(@Validated @RequestBody UserBanListParam param) {
        return ResultVO.ok(userBanService.list(param));
    }

    @PostMapping(value = "/user/add/or/update")
    @PreAuthorize(permissionKey = "manage:userBan:addOrUpdate")
    public ResultVO<Boolean> addOrUpdate(@Validated @RequestBody UserBanUpdateParam param) {
        return ResultVO.ok(userBanService.addOrUpdate(param));
    }
}
