/*
 * Copyright (C) 2007-2015, GoodData(R) Corporation. All rights reserved.
 */
package com.gooddata.featureflag;

import com.fasterxml.jackson.annotation.*;
import com.gooddata.project.Project;
import org.springframework.web.util.UriTemplate;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import static com.gooddata.util.Validate.notEmpty;
import static org.springframework.util.CollectionUtils.isEmpty;

@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME)
@JsonTypeName("featureFlags")
@JsonIgnoreProperties(ignoreUnknown = true)
public class ProjectFeatureFlags implements Iterable<ProjectFeatureFlag> {

    public static final String PROJECT_FEATURE_FLAGS_URI = Project.URI + "/projectFeatureFlags";
    public static final UriTemplate PROJECT_FEATURE_FLAGS_TEMPLATE = new UriTemplate(PROJECT_FEATURE_FLAGS_URI);

    private final List<ProjectFeatureFlag> items = new LinkedList<>();

    @JsonCreator
    ProjectFeatureFlags(@JsonProperty("items") List<ProjectFeatureFlag> items) {
        if (!isEmpty(items)) {
            this.items.addAll(items);
        }
    }

    @Override
    public Iterator<ProjectFeatureFlag> iterator() {
        return items.iterator();
    }

    /**
     * Returns true if the project feature flag with given name exists and is enabled, false otherwise.
     *
     * @param flagName the name of project feature flag
     * @return true if the project feature flag with given name exists and is enabled, false otherwise
     */
    public boolean isEnabled(final String flagName) {
        notEmpty(flagName, "flagName");
        for (final ProjectFeatureFlag flag : items) {
            if (flagName.equalsIgnoreCase(flag.getName())) {
                return flag.isEnabled();
            }
        }
        return false;
    }

    /**
     * @deprecated use {@link #isEnabled(String)} method or {@link Iterable} feature of this class
     * @return list of project feature flags
     */
    @Deprecated
    public List<ProjectFeatureFlag> getItems() {
        return items;
    }
}

@@ -876,24 +876,51 @@
 LAGS_URI);%0A%0A
+    @JsonProperty(%22items%22)%0A
     private 
@@ -1863,259 +1863,6 @@
  %7D%0A%0A
-    /**%0A     * @deprecated use %7B@link #isEnabled(String)%7D method or %7B@link Iterable%7D feature of this class%0A     * @return list of project feature flags%0A     */%0A    @Deprecated%0A    public List%3CProjectFeatureFlag%3E getItems() %7B%0A        return items;%0A    %7D%0A
 %7D%0A

remove deprecated ProjectFeatureFlags.getItems