/*
 * 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.trackedentity;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue;

import org.hisp.dhis.android.core.common.BaseNameableObject;
import org.hisp.dhis.android.core.data.api.Field;
import org.hisp.dhis.android.core.data.api.Fields;

import java.util.Date;

@AutoValue
public abstract class TrackedEntityType extends BaseNameableObject {
    public static final Field<TrackedEntityType, String> uid = Field.create(UID);
    public static final Field<TrackedEntityType, String> code = Field.create(CODE);
    public static final Field<TrackedEntityType, String> name = Field.create(NAME);
    public static final Field<TrackedEntityType, String> displayName = Field.create(DISPLAY_NAME);
    public static final Field<TrackedEntityType, String> created = Field.create(CREATED);
    public static final Field<TrackedEntityType, String> lastUpdated = Field.create(LAST_UPDATED);
    public static final Field<TrackedEntityType, Boolean> deleted = Field.create(DELETED);
    public static final Field<TrackedEntityType, String> shortName = Field.create(SHORT_NAME);
    public static final Field<TrackedEntityType, String> displayShortName = Field.create(DISPLAY_SHORT_NAME);
    public static final Field<TrackedEntityType, String> description = Field.create(DESCRIPTION);
    public static final Field<TrackedEntityType, String> displayDescription = Field.create(DISPLAY_DESCRIPTION);

    static final Fields<TrackedEntityType> allFields = Fields.<TrackedEntityType>builder().fields(
            uid, code, name, displayName, created, lastUpdated, deleted, shortName, displayShortName, description,
            displayDescription).build();

    @JsonCreator
    public static TrackedEntityType create(
            @JsonProperty(UID) String uid,
            @JsonProperty(CODE) String code,
            @JsonProperty(NAME) String name,
            @JsonProperty(DISPLAY_NAME) String displayName,
            @JsonProperty(CREATED) Date created,
            @JsonProperty(LAST_UPDATED) Date lastUpdated,
            @JsonProperty(SHORT_NAME) String shortName,
            @JsonProperty(DISPLAY_SHORT_NAME) String displayShortName,
            @JsonProperty(DESCRIPTION) String description,
            @JsonProperty(DISPLAY_DESCRIPTION) String displayDescription,
            @JsonProperty(DELETED) Boolean deleted) {

        return new AutoValue_TrackedEntityType(
                uid, code, name, displayName, created, lastUpdated, deleted,
                shortName, displayShortName, description, displayDescription);
    }
}

@@ -1597,16 +1597,61 @@
 ntity;%0A%0A
+import android.support.annotation.Nullable;%0A%0A
 import c
@@ -1695,16 +1695,16 @@
 reator;%0A
-
 import c
@@ -1851,16 +1851,70 @@
 Object;%0A
+import org.hisp.dhis.android.core.common.ObjectStyle;%0A
 import o
@@ -2005,16 +2005,72 @@
 .Fields;
+%0Aimport org.hisp.dhis.android.core.data.api.NestedField;
 %0A%0Aimport
@@ -2167,16 +2167,66 @@
 bject %7B%0A
+    private final static String STYLE = %22style%22;%0A%0A
     publ
@@ -3261,16 +3261,120 @@
 IPTION);
+%0A    private static final NestedField%3CTrackedEntityType, ObjectStyle%3E style = NestedField.create(STYLE);
 %0A%0A    st
@@ -3611,16 +3611,23 @@
 cription
+, style
 ).build(
@@ -3626,24 +3626,105 @@
 ).build();%0A%0A
+    @Nullable%0A    @JsonProperty(STYLE)%0A    public abstract ObjectStyle style();%0A%0A
     @JsonCre
@@ -4324,32 +4324,84 @@
 layDescription,%0A
+            @JsonProperty(STYLE) ObjectStyle style,%0A
             @Jso
@@ -4560,24 +4560,24 @@
 d, deleted,%0A
-
             
@@ -4640,16 +4640,23 @@
 cription
+, style
 );%0A    %7D

add object style to TrackedEntityType