/*
 * 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.database.Cursor;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.gabrielittner.auto.value.cursor.ColumnName;
import com.google.auto.value.AutoValue;

import org.hisp.dhis.android.core.common.BaseNameableObjectModel;

@AutoValue
public abstract class ProgramTrackedEntityAttributeModel extends BaseNameableObjectModel {

    public static final String TABLE = "ProgramTrackedEntityAttribute";

    public static class Columns extends BaseNameableObjectModel.Columns {
        public static final String MANDATORY = "mandatory";
        public static final String TRACKED_ENTITY_ATTRIBUTE = "trackedEntityAttribute";
        public static final String ALLOW_FUTURE_DATES = "allowFutureDate";
        public static final String DISPLAY_IN_LIST = "displayInList";
        public static final String PROGRAM = "program";
        public static final String SORT_ORDER = "sortOrder";
    }

    @NonNull
    public static ProgramTrackedEntityAttributeModel.Builder builder() {
        return new $$AutoValue_ProgramTrackedEntityAttributeModel.Builder();
    }

    @NonNull
    public static ProgramTrackedEntityAttributeModel create(Cursor cursor) {
        return AutoValue_ProgramTrackedEntityAttributeModel.createFromCursor(cursor);
    }

    @Nullable
    @ColumnName(Columns.MANDATORY)
    public abstract Boolean mandatory();

    @NonNull
    @ColumnName(Columns.TRACKED_ENTITY_ATTRIBUTE)
    public abstract String trackedEntityAttribute();

    @Nullable
    @ColumnName(Columns.ALLOW_FUTURE_DATES)
    public abstract Boolean allowFutureDates();

    @Nullable
    @ColumnName(Columns.DISPLAY_IN_LIST)
    public abstract Boolean displayInList();

    @Nullable
    @ColumnName(Columns.SORT_ORDER)
    public abstract Integer sortOrder();

    @AutoValue.Builder
    public static abstract class Builder extends BaseNameableObjectModel.Builder<Builder> {

        public abstract Builder mandatory(@Nullable Boolean mandatory);

        public abstract Builder trackedEntityAttribute(@NonNull String trackedEntityAttribute);

        public abstract Builder allowFutureDates(@Nullable Boolean allowFutureFate);

        public abstract Builder displayInList(@Nullable Boolean displayInList);

        public abstract Builder sortOrder(@Nullable Integer sortOrder);

        abstract ProgramTrackedEntityAttributeModel build();
    }
}

@@ -1623,16 +1623,64 @@
 Cursor;%0A
+import android.database.sqlite.SQLiteStatement;%0A
 import a
@@ -1920,16 +1920,134 @@
 ctModel;
+%0Aimport org.hisp.dhis.android.core.utils.Utils;%0A%0Aimport static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind;
 %0A%0A@AutoV
@@ -2700,16 +2700,322 @@
 Order%22;%0A
+        public static final String SEARCHABLE = %22searchable%22;%0A%0A        @Override%0A        public String%5B%5D all() %7B%0A            return Utils.appendInNewArray(super.all(), MANDATORY, TRACKED_ENTITY_ATTRIBUTE, ALLOW_FUTURE_DATES,%0A                    DISPLAY_IN_LIST, PROGRAM, SORT_ORDER, SEARCHABLE);%0A        %7D%0A
     %7D%0A%0A 
@@ -3824,60 +3824,785 @@
 mns.
-SORT_ORDER)%0A    public abstract Integer sortOrder();
+PROGRAM)%0A    public abstract String program();%0A%0A    @Nullable%0A    @ColumnName(Columns.SORT_ORDER)%0A    public abstract Integer sortOrder();%0A%0A    @Nullable%0A    @ColumnName(Columns.SEARCHABLE)%0A    public abstract Boolean searchable();%0A%0A    @Override%0A    public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) %7B%0A        super.bindToStatement(sqLiteStatement);%0A        sqLiteBind(sqLiteStatement, 11, mandatory());%0A        sqLiteBind(sqLiteStatement, 12, trackedEntityAttribute());%0A        sqLiteBind(sqLiteStatement, 13, allowFutureDates());%0A        sqLiteBind(sqLiteStatement, 14, displayInList());%0A        sqLiteBind(sqLiteStatement, 15, program());%0A        sqLiteBind(sqLiteStatement, 16, sortOrder());%0A        sqLiteBind(sqLiteStatement, 17, searchable());%0A    %7D
 %0A%0A  
@@ -5048,24 +5048,92 @@
 ayInList);%0A%0A
+        public abstract Builder program(@Nullable String program);%0A%0A
         publ
@@ -5189,24 +5189,99 @@
 ortOrder);%0A%0A
+        public abstract Builder searchable(@Nullable Boolean searchable);%0A%0A
         abst
@@ -5336,9 +5336,8 @@
 %0A    %7D%0A%7D
-%0A

add searchable to PTEAModel