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.PayBoxAddUpdateParam;
import com.zanxiang.game.module.manage.pojo.params.PayBoxListParam;
import com.zanxiang.game.module.manage.pojo.vo.PayBoxListVO;
import com.zanxiang.game.module.manage.service.IPayBoxService;
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("/pay/box")
public class PayBoxController {

    @Autowired
    private IPayBoxService payBoxService;

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

    @ApiOperation(value = "支付盒子列表查询")
    @PostMapping(value = "/list")
    @PreAuthorize(permissionKey = "manage:payBox:list")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = PayBoxListVO.class)})
    public ResultVO<IPage<PayBoxListVO>> list(@Validated @RequestBody PayBoxListParam param) {
        return ResultVO.ok(payBoxService.pageList(param));
    }

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

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