package com.seer.teach.pay.app.notify.service;

import cn.hutool.core.collection.CollUtil;
import com.seer.teach.common.enums.pay.PayOrderSourceEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import jakarta.annotation.PostConstruct;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;

/**
 * 订单处理策略工厂
 */
@Component
public class OrderProcessStrategyFactory {

    @Autowired
    private List<OrderPayNotifyHandler> orderProcessStrategies;


    private final Map<PayOrderSourceEnum, OrderPayNotifyHandler> strategyMap = new EnumMap<>(PayOrderSourceEnum.class);

    @PostConstruct
    public void init() {
        if(CollUtil.isEmpty(orderProcessStrategies)){
            return;
        }
        for (OrderPayNotifyHandler strategy : orderProcessStrategies) {
            strategyMap.put(strategy.getOrderSource(), strategy);
        }
    }

    /**
     * 根据订单来源获取处理策略
     */
    public OrderPayNotifyHandler getStrategy(PayOrderSourceEnum orderSource) {
        return strategyMap.get(orderSource);
    }
}