package com.brilliance.isc.automatic.engine.config;

import com.brilliance.isc.automatic.engine.model.AutoRoute;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

@Slf4j
public class AutoRouterConfig {
    private List<AutoRoute> routes;

    /**
     * 注册自动化配置
     */
    public AutoRouterConfig(List<AutoRoute> config) {
        routes = config;
        if (ObjectUtils.isEmpty(routes)) {
            log.warn("*************************加载自动化路由器配置为空*************************");
            routes = Collections.emptyList();
        } else {
            Collections.sort(routes, Comparator.comparing(AutoRoute::getStep));

        }
    }

    public List<AutoRoute> getRoutes() {
        return routes;
    }

    public void setRoutes(List<AutoRoute> routes) {
        this.routes = routes;
    }

    public int size() {
        return routes.size();
    }
}
