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

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
import android.support.annotation.NonNull;

import org.hisp.dhis.android.core.arch.db.binders.StatementBinder;
import org.hisp.dhis.android.core.arch.db.binders.WhereStatementBinder;
import org.hisp.dhis.android.core.common.CursorModelFactory;
import org.hisp.dhis.android.core.common.ObjectWithoutUidStore;
import org.hisp.dhis.android.core.common.StoreFactory;
import org.hisp.dhis.android.core.data.database.DatabaseAdapter;

import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind;

public final class NoteStore {

    private NoteStore() {}

    private static final StatementBinder<NoteModel> BINDER = new StatementBinder<NoteModel>() {
        @Override
        public void bindToStatement(@NonNull NoteModel o, @NonNull SQLiteStatement sqLiteStatement) {
            sqLiteBind(sqLiteStatement, 1, o.enrollment());
            sqLiteBind(sqLiteStatement, 2, o.value());
            sqLiteBind(sqLiteStatement, 3, o.storedBy());
            sqLiteBind(sqLiteStatement, 4, o.storedDate());
        }
    };

    private static final WhereStatementBinder<NoteModel> WHERE_UPDATE_BINDER
            = new WhereStatementBinder<NoteModel>() {
        @Override
        public void bindToUpdateWhereStatement(@NonNull NoteModel o, @NonNull SQLiteStatement sqLiteStatement) {
            sqLiteBind(sqLiteStatement, 5, o.enrollment());
            sqLiteBind(sqLiteStatement, 6, o.value());
            sqLiteBind(sqLiteStatement, 7, o.storedBy());
            sqLiteBind(sqLiteStatement, 8, o.storedDate());
        }
    };

    private static final CursorModelFactory<NoteModel> FACTORY = new CursorModelFactory<NoteModel>() {
        @Override
        public NoteModel fromCursor(Cursor cursor) {
            return NoteModel.create(cursor);
        }
    };

    public static ObjectWithoutUidStore<NoteModel> create(DatabaseAdapter databaseAdapter) {
        return StoreFactory.objectWithoutUidStore(databaseAdapter, NoteModel.TABLE, new NoteModel.Columns(),
                BINDER, WHERE_UPDATE_BINDER, FACTORY);
    }
}
@@ -2284,21 +2284,16 @@
 der%3CNote
-Model
 %3E BINDER
@@ -2311,37 +2311,32 @@
 ementBinder%3CNote
-Model
 %3E() %7B%0A        @O
@@ -2384,37 +2384,32 @@
 nt(@NonNull Note
-Model
  o, @NonNull SQL
@@ -2665,32 +2665,85 @@
 .storedDate());%0A
+            sqLiteBind(sqLiteStatement, 5, o.uid());%0A
         %7D%0A    %7D;
@@ -2794,21 +2794,16 @@
 der%3CNote
-Model
 %3E WHERE_
@@ -2855,29 +2855,24 @@
 tBinder%3CNote
-Model
 %3E() %7B%0A      
@@ -2943,21 +2943,16 @@
 ull Note
-Model
  o, @Non
@@ -3027,25 +3027,25 @@
 eStatement, 
-5
+6
 , o.enrollme
@@ -3087,25 +3087,25 @@
 eStatement, 
-6
+7
 , o.value())
@@ -3142,25 +3142,25 @@
 eStatement, 
-7
+8
 , o.storedBy
@@ -3196,33 +3196,33 @@
 qLiteStatement, 
-8
+9
 , o.storedDate()
@@ -3216,32 +3216,86 @@
 .storedDate());%0A
+            sqLiteBind(sqLiteStatement, 10, o.uid());%0A
         %7D%0A    %7D;
@@ -3344,21 +3344,16 @@
 ory%3CNote
-Model
 %3E FACTOR
@@ -3383,21 +3383,16 @@
 ory%3CNote
-Model
 %3E() %7B%0A  
@@ -3426,21 +3426,16 @@
 lic Note
-Model
  fromCur
@@ -3478,21 +3478,16 @@
 urn Note
-Model
 .create(
@@ -3557,21 +3557,16 @@
 ore%3CNote
-Model
 %3E create
@@ -3676,44 +3676,28 @@
 Note
-Model.TABLE, new NoteModel.Columns()
+TableInfo.TABLE_INFO
 ,%0A  

Unify NoteStore