package org.dromara.payment.thirdPlatform.utils;


import cn.hutool.core.lang.Assert;
import org.dromara.payment.thirdPlatform.xinyujian.config.XinyujianAccountBean;
import org.dromara.payment.thirdPlatform.xinyujian.config.XinyujianConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Service
public class PaymentConfigUtils {
    private static final Logger log = LoggerFactory.getLogger(PaymentConfigUtils.class);


    @Resource
    private XinyujianConfig xinyujianConfig;

    public XinyujianAccountBean getXyjAccountBean(Long paymentConfigId) {
        XinyujianAccountBean accountBean = (XinyujianAccountBean) this.xinyujianConfig.getAccounts().get(paymentConfigId);
        Assert.isNull(accountBean, "益零工配置不存在");
        accountBean.setPaymentConfigId(paymentConfigId);
        return accountBean;
    }

    public List<XinyujianAccountBean> listXyjAccountBeans() {
        List<XinyujianAccountBean> list = new ArrayList<>();
        Map<Long, XinyujianAccountBean> map = this.xinyujianConfig.getAccounts();
        for (Long paymentConfigId : map.keySet()) {
            XinyujianAccountBean bean = map.get(paymentConfigId);
            bean.setPaymentConfigId(paymentConfigId);
            list.add(bean);
        }
        return list;
    }
}
