package com.prolog.eis.init;

import com.prolog.eis.constants.cache.EisCache;
import com.prolog.eis.model.config.RoadwayAllStrategyConfig;
import com.prolog.eis.service.config.RoadwayAllStrategyConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor
public class RoadwayAllocation implements CommandLineRunner {

    private final RoadwayAllStrategyConfigService roadwayAllStrategyConfigService;

    @Override
    public void run(String... args) throws Exception {
        List<RoadwayAllStrategyConfig> roadwayAllStrategyConfigList = roadwayAllStrategyConfigService.findAllConfig();
        for (RoadwayAllStrategyConfig roadwayAllStrategyConfig : roadwayAllStrategyConfigList) {
            EisCache.ROADWAY_ALLOCATION_STRATEGY_MAP.put(roadwayAllStrategyConfig.getPriority(), roadwayAllStrategyConfig.getStrategyName());
        }
    }
}
