package com.m2pool.lease.controller;


import com.m2pool.lease.annotation.Decrypt;
import com.m2pool.lease.annotation.LedgerLog;
import com.m2pool.lease.annotation.LoginRequired;
import com.m2pool.lease.dto.*;
import com.m2pool.lease.service.LeaseUserService;
import com.m2pool.lease.vo.BalancePageVo;
import com.m2pool.lease.vo.BalanceVo;
import com.m2pool.lease.vo.ChainAndCoinVo;
import com.m2pool.lease.vo.RecordTypePageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author yyb
 * @since 2025-07-23
 */
@Api(tags = "用户信息控制器")
@LoginRequired
@RestController
@RequestMapping("/user")
public class LeaseUserController {

    @Resource
    private LeaseUserService leaseUserService;


    @PostMapping("/bindWallet")
    @ApiOperation(value = "买家：充值步骤选择链和钱包后自动绑定钱包")
    public Result<UserWalletDataDto> bindWallet(@RequestBody ChainAndCoinVo chainAndCoinVo){
        return leaseUserService.bindWallet(chainAndCoinVo);
    }

    @PostMapping("/getWalletInfo")
    @ApiOperation(value = "获取用户相关钱包信息")
    public Result<List<UserWalletDataDto>> getWalletInfo() {
        return leaseUserService.getWalletInfo();
    }


    @LedgerLog(value = "买家钱包--余额提现申请")
    @Decrypt
    @PostMapping("/withdrawBalance")
    @ApiOperation(value = "申请余额提现")
    public Result<String> withdrawBalance(@RequestBody BalanceVo balanceVo){
        return leaseUserService.withdrawBalance(balanceVo);
    }


    @PostMapping("/balanceWithdrawList")
    @ApiOperation(value = "买家：余额提现记录列表")
    @Deprecated
    public PageResult<PayWithdrawMessageDto> balanceWithdrawList(@RequestBody BalancePageVo balancePageVo){
        return leaseUserService.balanceWithdrawList(balancePageVo);
    }


    @PostMapping("/balanceRechargeList")
    @ApiOperation(value = "买家：余额充值记录列表")
    @Deprecated
    public PageResult<PayRechargeMessageDto> balanceRechargeList(@RequestBody BalancePageVo balancePageVo){
        return leaseUserService.balanceRechargeList(balancePageVo);
    }

    @PostMapping("/balancePayList")
    @ApiOperation(value = "卖家:钱包交易(收款)记录列表")
    public PageResult<PayRecordMessageDto> balancePayList(@RequestBody BalancePageVo balancePageVo){
        return leaseUserService.balancePayList(balancePageVo);
    }

    @PostMapping("/transactionRecord")
    @ApiOperation(value = "买家:交易流水（支付，提现，充值）")
    public PageResult<TransactionRecordDto> transactionRecord(@RequestBody RecordTypePageVo recordTypePageVo){
        return leaseUserService.transactionRecord(recordTypePageVo);
    }

    @PostMapping("/getRecentlyTransaction")
    @ApiOperation(value = "最近5条交易")
    public Result<List<RecentlyTransactionDto>>  getRecentlyTransaction(){
        return leaseUserService.getRecentlyTransaction();
    }


    @PostMapping("/getCharge")
    @ApiOperation(value = "获取系统支持的交易手续费")
    @Deprecated
    public Result<List<ChargeDto>>  getCharge(){
        return leaseUserService.getCharge();
    }

    @GetMapping("/downloadClient")
    @ApiOperation(value = "卖家:下载客户端")
    public void downloadClient(@RequestParam String userEmail,@RequestParam String type,HttpServletRequest request, HttpServletResponse response){
        leaseUserService.downloadClient(userEmail,type,request, response);
    }

    @GetMapping("/getClientVersion")
    @ApiOperation(value = "获取客户端版本号")
    public String getClientVersion(){
        return leaseUserService.getClientVersion();
    }

}

