package com.hzs.member.account.controller.api;

import com.hzs.common.core.constant.EnumsPrefixConstants;
import com.hzs.common.core.enums.EOrderType;
import com.hzs.common.core.enums.ETradeType;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.core.web.domain.EnumEntity;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.member.account.service.ICuMemberAccountService;
import com.hzs.member.account.service.ICuMemberTradeRecoilService;
import com.hzs.member.account.service.ICuMemberTradeService;
import com.hzs.member.account.vo.CuMemberAccountVO;
import com.hzs.member.account.vo.CuMemberTradeVO;
import com.hzs.member.account.vo.CuMemberWalletBalanceVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 我的钱包
 *
 * @Description:
 * @Author: ljc
 * @Time: 2023/2/8 11:19
 * @Classname: CuMemberWalletControllerApi
 * @Package_name: com.hzs.member.account.controller.api
 */
@RestController
@RequestMapping("/api/wallet")
public class ApiCuMemberWalletController extends BaseController {

    @Autowired
    ICuMemberAccountService memberAccountService;

    @Autowired
    ICuMemberTradeService memberTradeService;

    @Autowired
    ICuMemberTradeRecoilService memberTradeRecoilService;


    /**
     * 查询钱包余额
     *
     * @return
     */
    @GetMapping("/balance")
    public AjaxResult getWalletBalance() {
        Long pkMember = SecurityUtils.getUserId();
        Integer pkCountry = SecurityUtils.getPkCountry();
        return AjaxResult.success(memberAccountService.queryWalletBalanceByPkMember(pkMember, pkCountry));
    }


    /**
     * 查询交易类型
     *
     * @return
     */
    @GetMapping("/trade-type")
    public AjaxResult tradeType() {
        // 查询交易类型
        List<Integer> tradeTypes = memberTradeService.selectTradeType(SecurityUtils.getUserId(), SecurityUtils.getPkCountry());
        List<EnumEntity> enumEntityList = new ArrayList<>();
        for (ETradeType value : ETradeType.values()) {
            if (tradeTypes.contains(value.getValue())) {
                enumEntityList.add(new EnumEntity(value.getValue(), value.getLabel(), EnumsPrefixConstants.TRADE_TYPE));
            }
        }
        return AjaxResult.success(enumEntityList);
    }


    /**
     * 查询交易明细
     *
     * @param cuMemberTradeVO 交易记录表
     * @return TableDataInfo
     */
    @PostMapping("/transaction-details")
    public TableDataInfo selectWattleDetail(@RequestBody CuMemberTradeVO cuMemberTradeVO) {
        cuMemberTradeVO.setPkCountry(SecurityUtils.getPkCountry());
        cuMemberTradeVO.setPkMember(SecurityUtils.getUserId());
        startPage();
        List<CuMemberTradeVO> cuMemberTradeVOList = memberTradeService.selectWattleDetail(cuMemberTradeVO);
        return getDataTable(cuMemberTradeVOList);
    }

    /**
     * 复消明细
     * @param cuMemberTradeVO
     * @return TableDataInfo
     */
    @PostMapping("/recoil-details")
    public TableDataInfo selectRecoilDetail(@RequestBody CuMemberTradeVO cuMemberTradeVO) {
        cuMemberTradeVO.setPkCountry(SecurityUtils.getPkCountry());
        cuMemberTradeVO.setPkMember(SecurityUtils.getUserId());
        startPage();
        List<CuMemberTradeVO> cuMemberTradeVOList = memberTradeRecoilService.selectRecoilDetail(cuMemberTradeVO);
        return getDataTable(cuMemberTradeVOList);
    }


}
