/*
 * Copyright (c) 2004-2018, 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.dataset;

import android.database.Cursor;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.gabrielittner.auto.value.cursor.ColumnAdapter;
import com.google.auto.value.AutoValue;

import org.hisp.dhis.android.core.common.BaseModel;
import org.hisp.dhis.android.core.common.CursorModelFactory;
import org.hisp.dhis.android.core.data.database.DbDateColumnAdapter;

import java.util.Date;

@AutoValue
@JsonDeserialize(builder = $$AutoValue_DataSetCompleteRegistration.Builder.class)
public abstract class DataSetCompleteRegistration extends BaseModel {

    public abstract String period();

    public abstract String dataSet();

    public abstract String organisationUnit();

    public abstract String attributeOptionCombo();

    @Nullable
    @ColumnAdapter(DbDateColumnAdapter.class)
    public abstract Date date();

    @Nullable
    public abstract String storedBy();

    @NonNull
    public static DataSetCompleteRegistration create(Cursor cursor) {
        return AutoValue_DataSetCompleteRegistration.createFromCursor(cursor);
    }

    public static final CursorModelFactory<DataSetCompleteRegistration> factory =
            new CursorModelFactory<DataSetCompleteRegistration>() {
        @Override
        public DataSetCompleteRegistration fromCursor(Cursor cursor) {
            return create(cursor);
        }
    };

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


    @AutoValue.Builder
    @JsonPOJOBuilder(withPrefix = "")
    public abstract static class Builder extends BaseModel.Builder<DataSetCompleteRegistration.Builder> {
        public abstract Builder period(@NonNull String period);

        public abstract Builder dataSet(@NonNull String dataSet);

        public abstract Builder organisationUnit(@NonNull String organisationUnit);

        public abstract Builder attributeOptionCombo(@NonNull String attributeOptionCombo);

        @JsonFormat(pattern = "yyyy-MM-dd")
        public abstract Builder date(@Nullable Date date);

        public abstract Builder storedBy(@Nullable String storedBy);

        public abstract DataSetCompleteRegistration build();
    }
}

@@ -1768,16 +1768,70 @@
 Format;%0A
+import com.fasterxml.jackson.annotation.JsonProperty;%0A
 import c
@@ -2094,24 +2094,28 @@
 .common.Base
+Data
 Model;%0Aimpor
@@ -2170,16 +2170,64 @@
 actory;%0A
+import org.hisp.dhis.android.core.common.State;%0A
 import o
@@ -2463,24 +2463,28 @@
 extends Base
+Data
 Model %7B%0A%0A   
@@ -2488,128 +2488,397 @@
     
-public abstract String period();%0A%0A    public abstract String dataSet();%0A%0A    public abstract String organisationUnit();%0A
+@JsonProperty(DataSetCompleteRegistrationFields.PERIOD)%0A    public abstract String period();%0A%0A    @JsonProperty(DataSetCompleteRegistrationFields.DATA_SET)%0A    public abstract String dataSet();%0A%0A    @JsonProperty(DataSetCompleteRegistrationFields.ORGANISATION_UNIT)%0A    public abstract String organisationUnit();%0A%0A    @JsonProperty(DataSetCompleteRegistrationFields.ATTRIBUTE_OPTION_COMBO)
 %0A   
@@ -2936,24 +2936,82 @@
   @Nullable%0A
+    @JsonProperty(DataSetCompleteRegistrationFields.DATE)%0A
     @ColumnA
@@ -3088,24 +3088,87 @@
   @Nullable%0A
+    @JsonProperty(DataSetCompleteRegistrationFields.STORED_BY)%0A
     public a
@@ -3886,16 +3886,20 @@
 nds Base
+Data
 Model.Bu
@@ -3943,16 +3943,88 @@
 lder%3E %7B%0A
+%0A        public Builder() %7B%0A            state(State.SYNCED);%0A        %7D%0A%0A
         

Add state field to DataSetCompleteRegistration