package com.eactive.httpmockserver.api.condition;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Service(value = "ConditionMatcherService")
public class ConditionMatcherService {

    private final Map<String, ConditionMatcher> matchers;

    private final List<ConditionMatcher> matchersList;

    public ConditionMatcherService(List<ConditionMatcher> matchersList) {
        this.matchersList = matchersList;
        this.matchers = this.matchersList.stream().collect(Collectors.toMap(ConditionMatcher::getType, Function.identity()));
    }

    public ConditionMatcher getMatcher(String key) {
        return matchers.get(key);
    }

    public List<ConditionMatcher> getMatchersList() {
        return matchersList;
    }
}
