package cz.moneta.test.harness.support.rest;

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

public enum AllowedContentTypes {

    PDF("pdf", "application/pdf");

    private final String extension;
    private final String contentType;

    private static final Map<String, AllowedContentTypes> CONTENT_TYPES_VALUE_LOOKUP = EnumSet.allOf(AllowedContentTypes.class).stream()
            .collect(Collectors.toMap(el -> el.contentType, Function.identity()));

    AllowedContentTypes(String extension, String contentType) {
        this.extension = extension;
        this.contentType = contentType;
    }

    public String getExtension() {
        return extension;
    }

    public static AllowedContentTypes getByMimeType(String contentType) {
        if (CONTENT_TYPES_VALUE_LOOKUP.get(contentType) != null) {
            return CONTENT_TYPES_VALUE_LOOKUP.get(contentType);
        }
        throw new IllegalStateException("Content type of Base64 String is not allowed: " + contentType);
    }
}
