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 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 : 应用管理
 */
@RestController
@RequestMapping("/pay/application")
public class PayApplicationController {

    @Autowired
    private IPayApplicationService payApplicationService;

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

    @PostMapping(value = "/list")
    @PreAuthorize(permissionKey = "manage:payApplication:list")
    public ResultVO<IPage<PayApplicationVO>> list(@Validated @RequestBody PayApplicationListParam param) {
        return ResultVO.ok(payApplicationService.pageList(param));
    }

    @DeleteMapping(value = "/delete")
    @PreAuthorize(permissionKey = "manage:payApplication:delete")
    public ResultVO<Boolean> deleteById(@RequestParam Long id) {
        return ResultVO.ok(payApplicationService.deleteById(id));
    }

    @PatchMapping(value = "/status/update")
    @PreAuthorize(permissionKey = "manage:payApplication:statusUpdate")
    public ResultVO<Boolean> statusUpdate(@RequestParam Long id, @RequestParam Integer status) {
        return ResultVO.ok(payApplicationService.statusUpdate(id, status));
    }

    @GetMapping(value = "/qr/code")
    @PreAuthorize(permissionKey = "manage:payApplication:qrCode")
    public ResultVO<String> getQrCode(@RequestParam Long id) {
        return ResultVO.ok(payApplicationService.getQrCode(id));
    }

}
