/*
 * Copyright (c) 2017, University of Oslo
 *
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 * Neither the name of the HISP project nor the names of its contributors may
 * be used to endorse or promote products derived from this software without
 * specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.hisp.dhis.android.core.program;

import android.support.annotation.Nullable;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.google.auto.value.AutoValue;

import org.hisp.dhis.android.core.common.Access;
import org.hisp.dhis.android.core.common.BaseIdentifiableObject;
import org.hisp.dhis.android.core.common.FormType;
import org.hisp.dhis.android.core.common.ObjectStyle;
import org.hisp.dhis.android.core.common.ObjectWithUid;
import org.hisp.dhis.android.core.period.PeriodType;

import java.util.List;

@AutoValue
@JsonDeserialize(builder = AutoValue_ProgramStage.Builder.class)
@SuppressWarnings({"PMD.ExcessivePublicCount"})
public abstract class ProgramStage extends BaseIdentifiableObject {

    @Nullable
    public abstract String description();

    @Nullable
    public abstract String displayDescription();

    @Nullable
    public abstract String executionDateLabel();

    @Nullable
    public abstract Boolean allowGenerateNextVisit();

    @Nullable
    public abstract Boolean validCompleteOnly();

    @Nullable
    public abstract String reportDateToUse();

    @Nullable
    public abstract Boolean openAfterEnrollment();

    @Nullable
    public abstract Boolean repeatable();

    @Nullable
    public abstract Boolean captureCoordinates();

    @Nullable
    public abstract FormType formType();

    @Nullable
    public abstract Boolean displayGenerateEventBox();

    @Nullable
    public abstract Boolean generatedByEnrollmentDate();

    @Nullable
    public abstract Boolean autoGenerateEvent();

    @Nullable
    public abstract Integer sortOrder();

    @Nullable
    public abstract Boolean hideDueDate();

    @Nullable
    public abstract Boolean blockEntryForm();

    @Nullable
    public abstract Integer minDaysFromStart();

    @Nullable
    public abstract Integer standardInterval();

    @Nullable
    public abstract List<ProgramStageSection> programStageSections();

    @Nullable
    public abstract List<ProgramStageDataElement> programStageDataElements();

    @Nullable
    public abstract ObjectStyle style();

    @Nullable
    public abstract PeriodType periodType();

    @Nullable
    public abstract ObjectWithUid program();

    String programUid() {
        ObjectWithUid program = program();
        return program == null ? null : program.uid();
    }

    @Nullable
    public abstract Access access();

    @Nullable
    public abstract Boolean remindCompleted();

    public static Builder builder() {
        return new AutoValue_ProgramStage.Builder();
    }

    @AutoValue.Builder
    @JsonPOJOBuilder(withPrefix = "")
    public static abstract class Builder extends BaseIdentifiableObject.Builder<Builder> {
        public abstract Builder description(String description);

        public abstract Builder displayDescription(String displayDescription);

        public abstract Builder executionDateLabel(String executionDateLabel);

        public abstract Builder allowGenerateNextVisit(Boolean allowGenerateNextVisit);

        public abstract Builder validCompleteOnly(Boolean validCompleteOnly);

        public abstract Builder reportDateToUse(String reportDateToUse);

        public abstract Builder openAfterEnrollment(Boolean openAfterEnrollment);

        public abstract Builder repeatable(Boolean repeatable);

        public abstract Builder captureCoordinates(Boolean captureCoordinates);

        public abstract Builder formType(FormType formType);

        public abstract Builder displayGenerateEventBox(Boolean displayGenerateEventBox);

        public abstract Builder generatedByEnrollmentDate(Boolean generatedByEnrollmentDate);

        public abstract Builder autoGenerateEvent(Boolean autoGenerateEvent);

        public abstract Builder sortOrder(Integer sortOrder);

        public abstract Builder hideDueDate(Boolean hideDueDate);

        public abstract Builder blockEntryForm(Boolean blockEntryForm);

        public abstract Builder minDaysFromStart(Integer minDaysFromStart);

        public abstract Builder standardInterval(Integer standardInterval);

        public abstract Builder programStageSections(List<ProgramStageSection> programStageSections);

        public abstract Builder programStageDataElements(List<ProgramStageDataElement> programStageDataElements);

        public abstract Builder style(ObjectStyle style);

        public abstract Builder periodType(PeriodType periodType);

        public abstract Builder program(ObjectWithUid program);

        public abstract Builder access(Access access);

        public abstract Builder remindCompleted(Boolean remindCompleted);

        public abstract ProgramStage build();
    }
}
@@ -2084,16 +2084,70 @@
 ithUid;%0A
+import org.hisp.dhis.android.core.period.FeatureType;%0A
 import o
@@ -2191,16 +2191,16 @@
 odType;%0A
-
 %0Aimport 
@@ -2907,24 +2907,122 @@
 eatable();%0A%0A
+    /**%0A     * @deprecated since 2.29, replaced by %7B@link #featureType()%7D%0A     */%0A    @Deprecated%0A
     @Nullabl
@@ -3070,24 +3070,86 @@
 dinates();%0A%0A
+    @Nullable%0A    public abstract FeatureType featureType();%0A%0A
     @Nullabl
@@ -4392,24 +4392,66 @@
 r();%0A    %7D%0A%0A
+    public abstract Builder toBuilder();%0A%0A
     @AutoVal
@@ -5202,24 +5202,24 @@
 peatable);%0A%0A
-
         publ
@@ -5283,24 +5283,95 @@
 rdinates);%0A%0A
+        public abstract Builder featureType(FeatureType featureType);%0A%0A
         publ

add property featureType on ProgramStage