package com.webchat.controller.admin;

import com.webchat.common.bean.APIPageResponseBean;
import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.common.enums.WalletTransEventEnum;
import com.webchat.common.helper.SessionHelper;
import com.webchat.config.annotation.ValidatePermission;
import com.webchat.domain.vo.response.UserWalletDetailResponseVO;
import com.webchat.service.UserWalletService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author 程序员七七， https://www.coderutil.com网站作者
 * @date 2024/11/9 05:34
 */
@Api(tags = "【管理后台】用户钱包管理")
@RestController
@RequestMapping("/api/user/wallet")
public class AdminUserWalletController {

    @Autowired
    private UserWalletService userWalletService;

    /**
     * 管理员为用户钱包充值
     *
     * @return
     */
    @ApiOperation("管理员为用户钱包充值")
    @ValidatePermission
    @PostMapping("/grant/{userId}/{money}")
    public APIResponseBean<Boolean> grant(@PathVariable String userId, @PathVariable BigDecimal money) {
        String adminUserId = SessionHelper.getCurrentUserId();
        // 系统充钱
        userWalletService.doTrans(WalletTransEventEnum.SYSTEM_GRANT, userId, adminUserId, money);
        return APIResponseBeanUtil.success();
    }

    @ApiOperation("钱包资金流转记录查询")
    @ValidatePermission
    @GetMapping("/page")
    public APIPageResponseBean<List<UserWalletDetailResponseVO>> page(
            @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {

        return userWalletService.page(pageNo, pageSize);
    }

}
