package io.delphiplatform.api.v3.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import java.util.Collection;
import java.util.Set;

import io.delphiplatform.api.util.CollectionUtils;

/**
 * Names of child objects to include
 */
public enum IncludeStreams {

    DEMOGRAPHICS("demographics"),
    DSP_STREAMS_INFO("dsp_streams_info"),
    SAVES("saves"),
    SKIPS("skips"),
    ALL("all");

    private static final Set<IncludeStreams> INCLUDES_DEMOGRAPHICS = Set
        .of(DEMOGRAPHICS, SAVES, SKIPS, DSP_STREAMS_INFO, ALL);

    private final String value;

    IncludeStreams(String value) {
        this.value = value;
    }

    public static boolean isDemographicsIncluded(Collection<IncludeStreams> includeStreams) {
        return CollectionUtils.containsAny(includeStreams, INCLUDES_DEMOGRAPHICS);
    }

    @JsonCreator
    public static IncludeStreams fromValue(String value) {
        for (IncludeStreams b : IncludeStreams.values()) {
            if (b.value.equals(value)) {
                return b;
            }
        }
        throw new IllegalArgumentException("Unexpected value '" + value + "'");
    }

    @JsonValue
    public String getValue() {
        return value;
    }

    @Override
    public String toString() {
        return String.valueOf(value);
    }
}
