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.GamePayWayAddUpdateParam;
import com.zanxiang.game.module.manage.pojo.params.GamePayWayListParam;
import com.zanxiang.game.module.manage.pojo.vo.GamePayWayListVO;
import com.zanxiang.game.module.manage.service.IGamePayWayService;
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.*;

/**
 * @author : lingfeng
 * @time : 2022-11-25
 * @description : 游戏支付配置管理
 */
@Api(tags = "支付配置管理")
@RestController
@RequestMapping("/game/pay/way")
public class GamePayWayController {

    @Autowired
    private IGamePayWayService gamePayWayService;

    @ApiOperation(value = "游戏支付配置新增或者更新")
    @PostMapping(value = "/add/or/update")
    @PreAuthorize(permissionKey = "manage:gamePayWay:addOrUpdate")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> addOrUpdate(@Validated @RequestBody GamePayWayAddUpdateParam param) {
        return ResultVO.ok(gamePayWayService.addOrUpdate(param));
    }

    @ApiOperation(value = "游戏支付配置列表查询")
    @PostMapping(value = "/list")
    @PreAuthorize(permissionKey = "manage:gamePayWay:list")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GamePayWayListVO.class)})
    public ResultVO<IPage<GamePayWayListVO>> pageList(@Validated @RequestBody GamePayWayListParam param) {
        return ResultVO.ok(gamePayWayService.pageList(param));
    }

    @ApiOperation(value = "游戏支付配置删除")
    @DeleteMapping(value = "/delete")
    @PreAuthorize(permissionKey = "manage:gamePayWay:delete")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> deleteById(@RequestParam Long id) {
        return ResultVO.ok(gamePayWayService.deleteById(id));
    }

    @ApiOperation(value = "游戏支付配置状态变更")
    @PatchMapping(value = "/status/update")
    @PreAuthorize(permissionKey = "manage:gamePayWay:statusUpdate")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> statusUpdate(@RequestParam Long id, @RequestParam Integer status) {
        return ResultVO.ok(gamePayWayService.statusUpdate(id, status));
    }
}
