package com.bytesw.bytebot.model.enums;

import com.bytesw.bytebot.model.AnnualCalendarException;
import com.bytesw.bytebot.model.RangeCalendarException;
import com.bytesw.bytebot.model.UniqueCalendarException;
import com.bytesw.bytebot.model.UniqueWeeklyCalendarException;

import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;

public enum FrequencyType {
    ANNUAL(AnnualCalendarException.DISCRIMINATOR_VALUE),
    UNIQUE(UniqueCalendarException.DISCRIMINATOR_VALUE),
    UniqueWeekly(UniqueWeeklyCalendarException.DISCRIMINATOR_VALUE),
    RANGE(RangeCalendarException.DISCRIMINATOR_VALUE);

    private final String name;

    private static final Map<String, FrequencyType> map = new HashMap<>();

    static {
        for (FrequencyType type : FrequencyType.values()) {
            map.put(type.name, type);
        }
    }

    FrequencyType(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public static FrequencyType fromString(String name) {
        if (map.containsKey(name)) {
            return map.get(name);
        }
        throw new NoSuchElementException(name + " not found");
    }
}
