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.PayApplicationAddUpdateParam;
import com.zanxiang.game.module.manage.pojo.params.PayApplicationListParam;
import com.zanxiang.game.module.manage.pojo.vo.PayApplicationVO;
import com.zanxiang.game.module.manage.service.IPayApplicationService;
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/application")
public class PayApplicationController {

    @Autowired
    private IPayApplicationService payApplicationService;

    @ApiOperation(value = "应用新增或者更新")
    @PostMapping(value = "/add/or/update")
    @PreAuthorize(permissionKey = "manage:payApplication:addOrUpdate")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
    public ResultVO<Boolean> addOrUpdate(@Validated @RequestBody PayApplicationAddUpdateParam param) {
        return ResultVO.ok(payApplicationService.addOrUpdate(param));
    }

    @ApiOperation(value = "应用列表查询")
    @PostMapping(value = "/list")
    @PreAuthorize(permissionKey = "manage:payApplication:list")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = PayApplicationVO.class)})
    public ResultVO<IPage<PayApplicationVO>> list(@Validated @RequestBody PayApplicationListParam param) {
        return ResultVO.ok(payApplicationService.pageList(param));
    }

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

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

    @ApiOperation(value = "获取小程序二维码")
    @GetMapping(value = "/qr/code")
    @PreAuthorize(permissionKey = "manage:payApplication:qrCode")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = String.class)})
    public ResultVO<String> getQrCode(@RequestParam Long id) {
        return ResultVO.ok(payApplicationService.getQrCode(id));
    }

}
