package com.ss.android.ugc.effectmanager.algorithm;

import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.effectmanager.LoadedModelList;
import com.ss.android.ugc.effectmanager.common.Multimap;
import com.ss.android.ugc.effectmanager.common.utils.Preconditions;
import com.ss.android.ugc.effectmanager.model.ModelInfo;
import java.util.HashMap;

public class ServerConfig {
    public Multimap<String, ModelInfo> data;
    public LoadedModelList loadedModelList;

    static {
        Covode.recordClassIndex(125214);
    }

    private void checkContent() {
        HashMap hashMap = new HashMap();
        for (com.ss.ugc.effectplatform.model.algorithm.ModelInfo next : this.data.values()) {
            String name = next.getName();
            if (!hashMap.containsKey(name)) {
                hashMap.put(name, next.getVersion());
            } else if (!((String) hashMap.get(name)).equals(next.getVersion())) {
                throw new RuntimeException("model " + name + " has different versions in ServerTable,Please modify the file to the correct format ");
            }
        }
    }

    public LoadedModelList getLoadedModelList() {
        if (this.loadedModelList == null) {
            checkContent();
            this.loadedModelList = new LoadedModelList();
            Multimap multimap = new Multimap();
            for (String next : this.data.keySet()) {
                for (ModelInfo modelInfoState : this.data.get(next)) {
                    multimap.put(next, new LoadedModelList.ModelInfoState(modelInfoState));
                }
            }
            this.loadedModelList.setRequirementModelInfoStateMap(multimap);
        }
        return this.loadedModelList;
    }

    public ServerConfig(Multimap<String, ModelInfo> multimap) {
        Preconditions.checkNotNull(multimap);
        this.data = multimap;
    }
}
