package com.sckw.payment.dubbo;

import com.sckw.core.exception.BusinessException;
import com.sckw.payment.api.dubbo.PayCenterDubboService;
import com.sckw.payment.api.model.constant.ChannelEnum;
import com.sckw.payment.api.model.dto.MemberDetail;
import com.sckw.payment.api.model.dto.common.R;
import com.sckw.payment.api.model.dto.WalletDto;
import com.sckw.payment.service.KwpWalletRelationService;
import com.sckw.payment.service.PayCenterService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService(group = "design", version = "1.0.0")
@Slf4j
public class PayCenterServiceImpl implements PayCenterDubboService {
    @Resource
    private PayCenterService payCenterService;
    @Resource
    private KwpWalletRelationService kwpWalletRelationService;

    @Override
    public R<MemberDetail> memberDetail(Long entId, ChannelEnum channel) {
//        String uid = kwpWalletRelationService.getRelation(entId);
//        if (StringUtils.isBlank(uid)) {
//            throw new BusinessException("企业未开通电子钱包");
//        }
//        payCenterService.withdrawDetail("kll_0001", "", "1");
//        payCenterService.withdrawIndex("kll_0001", ChannelEnum.HF, 1, 5);
//        payCenterService.walletUnFreeze("kll_0001");
//        payCenterService.withdrawStatus("");
//        payCenterService.withdrawCancel("kll_0001", "123");
//        payCenterService.withdrawTake("kll_0001", ChannelEnum.HF, 123L, "1");
//        payCenterService.totalInfo("kll_0001", ChannelEnum.HF, "kll_0002");
//        payCenterService.operateDownload("kll_0001", ChannelEnum.HF, "kll_0002");
//        payCenterService.operateCategory();
//        payCenterService.operateIndex("kll_0001", ChannelEnum.HF, 1, 5, new String[]{"2023-07-20", "2023-07-21"}, null);
        payCenterService.logCategory();
        payCenterService.record("kll_0001", "kll_0002", 1, 5);

//        payCenterService.payAgentPay("kll_0001");
        return payCenterService.memberDetail("kll_0001", ChannelEnum.HF);
    }

    @Override
    public R<List<WalletDto>> wallet(Long payEntId, ChannelEnum channel, Long receiveEntId) {
        String uid = kwpWalletRelationService.getRelation(payEntId);
        if (StringUtils.isBlank(uid)) {
            throw new BusinessException("付款方企业未开通电子钱包");
        }
        String filter = kwpWalletRelationService.getRelation(receiveEntId);
        if (StringUtils.isBlank(filter)) {
            throw new BusinessException("收款方企业未开通电子钱包");
        }
        return payCenterService.wallet(uid, channel, filter);
    }


}
