package com.muyu.data.processing.strategy.core;

import com.muyu.common.caffeine.enums.CacheNameEnums;
import com.muyu.data.processing.domain.BasicData;
import java.util.HashMap;import java.util.List;
import com.muyu.data.processing.domain.Temporary2;
import com.muyu.data.processing.strategy.StrategyHandler;
import com.muyu.data.processing.strategy.abstractStrategyRouter;
import com.muyu.data.processing.strategy.branch.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 路由节点
 * 根据条件重新导向对应节点
 * @Author: 胡杨
 * @Name: RoutingStrategy
 * @Description: 路由节点
 * @CreatedDate: 2024/9/30 下午7:37
 * @FilePath: com.muyu.data.processing.strategy.branch
 */

@Slf4j
@Component
public class RoutingStrategy   extends abstractStrategyRouter<HashMap<String, BasicData>, Temporary2>
        implements StrategyHandler<HashMap<String, BasicData>, Temporary2> {

    private final static HashMap<String, StrategyHandler<HashMap<String, BasicData>, Temporary2>> map = new HashMap<>();
    static{
        map.put(CacheNameEnums.WARMING.getCode(), new WarningProcessingStrategy());
        map.put(CacheNameEnums.REALTIME.getCode(), new RealTimeProcessingStrategy());
        map.put(CacheNameEnums.FENCE.getCode(), new FenceProcessingStrategy());
        map.put(CacheNameEnums.FAULT.getCode(), new FaultProcessingStrategy());
        map.put(CacheNameEnums.STORAGE.getCode(), new DataStorageProcessStrategy());
    }

    @Override
    protected StrategyMapper<HashMap<String, BasicData>, Temporary2> registerStrategy() {
        log.info("路由节点已通过。。。");
        return param -> {
            // 编写路由规则
            for (String code : map.keySet()) {
                if(param.containsKey(code)){
                    param.remove(code);
                    return map.get(code);
                }
            }
            // 默认返回结束节点
            return new EndStrategy();
        };
    };


    @Override
    public Temporary2 apply(HashMap<String, BasicData> stringListHashMap) {
        return applyStrategy(stringListHashMap);
    }
}
