package com.zm.order.tool.server.component;

import com.google.common.collect.Maps;
import com.zm.order.tool.server.handler.refund.RefundBusHandler;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *
 * </p>
 *
 * @author nianchang
 * @date 2024/01/04 2:59 下午
 */
@Component
public class RefundBusHandlerHolder implements InitializingBean {

    @Autowired
    private List<RefundBusHandler> handlerList;

    private Map<Integer, RefundBusHandler> indexOrderGeneratorMap = Maps.newHashMap();

    @Override
    public void afterPropertiesSet() throws Exception {
        handlerList.forEach(eachHandle -> {
            indexOrderGeneratorMap.put(eachHandle.bizType(), eachHandle);
        });
    }

    public RefundBusHandler refundBusHandler(Integer bizType) {
        return indexOrderGeneratorMap.get(bizType);
    }
}
