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

import org.hisp.dhis.android.core.arch.db.TableInfo;
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.arch.db.executors.CursorExecutorImpl;
import org.hisp.dhis.android.core.arch.db.stores.LinkModelChildStore;
import org.hisp.dhis.android.core.arch.db.stores.LinkModelChildStoreImpl;
import org.hisp.dhis.android.core.arch.db.stores.SingleParentChildStore;
import org.hisp.dhis.android.core.arch.db.stores.SingleParentChildStoreImpl;
import org.hisp.dhis.android.core.arch.db.tableinfos.LinkTableChildProjection;
import org.hisp.dhis.android.core.arch.db.tableinfos.SingleParentChildProjection;
import org.hisp.dhis.android.core.data.database.DatabaseAdapter;

@SuppressWarnings("PMD.UseVarargs")
public final class StoreFactory {

    private StoreFactory() {}

    @Deprecated
    public static <I extends Model & ObjectWithUidInterface> IdentifiableObjectStore<I>
    objectWithUidStore(DatabaseAdapter databaseAdapter, String tableName, String[] columns,
                       StatementBinder<I> binder, CursorModelFactory<I> modelFactory) {
        SQLStatementBuilder statementBuilder = new SQLStatementBuilder(tableName, columns, new String[]{});
        SQLStatementWrapper statements = new SQLStatementWrapper(statementBuilder, databaseAdapter);
        return new IdentifiableObjectStoreImpl<>(databaseAdapter, statements, statementBuilder, binder, modelFactory);
    }

    public static <I extends Model & ObjectWithUidInterface> IdentifiableObjectStore<I>
    objectWithUidStore(DatabaseAdapter databaseAdapter, TableInfo tableInfo, StatementBinder<I> binder,
                       CursorModelFactory<I> modelFactory) {
        return objectWithUidStore(databaseAdapter, tableInfo.name(), tableInfo.columns().all(), binder, modelFactory);
    }

    public static <I extends Model> ObjectStore<I> objectStore(DatabaseAdapter databaseAdapter,
                                                           TableInfo tableInfo,
                                                           StatementBinder<I> binder,
                                                           CursorModelFactory<I> modelFactory) {
        SQLStatementBuilder statementBuilder =
                new SQLStatementBuilder(tableInfo.name(), tableInfo.columns().all(), new String[]{});
        return new ObjectStoreImpl<>(databaseAdapter, databaseAdapter.compileStatement(statementBuilder.insert()),
                statementBuilder, binder, modelFactory);
    }

    @Deprecated
    public static <I extends Model> ObjectWithoutUidStore<I> objectWithoutUidStore(
            DatabaseAdapter databaseAdapter, String tableName, BaseModel.Columns columns, StatementBinder<I> binder,
            WhereStatementBinder<I> whereBinder, CursorModelFactory<I> modelFactory) {
        SQLStatementBuilder statementBuilder = new SQLStatementBuilder(tableName, columns.all(), columns.whereUpdate());
        return new ObjectWithoutUidStoreImpl<>(databaseAdapter,
                databaseAdapter.compileStatement(statementBuilder.insert()),
                databaseAdapter.compileStatement(statementBuilder.updateWhere()),
                statementBuilder, binder, whereBinder, modelFactory);
    }

    public static <I extends Model> ObjectWithoutUidStore<I> objectWithoutUidStore(
            DatabaseAdapter databaseAdapter, TableInfo tableInfo, StatementBinder<I> binder,
            WhereStatementBinder<I> whereBinder, CursorModelFactory<I> modelFactory) {
        return objectWithoutUidStore(databaseAdapter, tableInfo.name(), tableInfo.columns(), binder, whereBinder,
                modelFactory);
    }

    @Deprecated
    public static <I extends Model> LinkModelStore<I> linkModelStore(
            DatabaseAdapter databaseAdapter, String tableName, BaseModel.Columns columns,
            String masterColumn, StatementBinder<I> binder, CursorModelFactory<I> modelFactory) {
        SQLStatementBuilder statementBuilder = new SQLStatementBuilder(tableName, columns.all(), columns.whereUpdate());
        return new LinkModelStoreImpl<>(databaseAdapter, databaseAdapter.compileStatement(statementBuilder.insert()),
                statementBuilder, masterColumn, binder, modelFactory);
    }

    public static <I extends Model> LinkModelStore<I> linkModelStore(
            DatabaseAdapter databaseAdapter, TableInfo tableInfo, String masterColumn, StatementBinder<I> binder,
            CursorModelFactory<I> modelFactory) {
        SQLStatementBuilder statementBuilder = new SQLStatementBuilder(tableInfo.name(), tableInfo.columns().all(),
                tableInfo.columns().whereUpdate());
        return new LinkModelStoreImpl<>(databaseAdapter, databaseAdapter.compileStatement(statementBuilder.insert()),
                statementBuilder, masterColumn, binder, modelFactory);
    }

    public static <P extends ObjectWithUidInterface,
            C extends ObjectWithUidInterface> LinkModelChildStore<P, C> linkModelChildStore(
                    DatabaseAdapter databaseAdapter,
                    TableInfo linkTableInfo,
                    LinkTableChildProjection linkTableChildProjection,
                    CursorModelFactory<C> childFactory) {
        return new LinkModelChildStoreImpl<>(
                linkTableChildProjection,
                databaseAdapter,
                new SQLStatementBuilder(linkTableInfo),
                new CursorExecutorImpl<>(childFactory));
    }

    public static <P extends ObjectWithUidInterface, C> SingleParentChildStore<P, C> singleParentChildStore(
                    DatabaseAdapter databaseAdapter,
                    SingleParentChildProjection childProjection,
                    CursorModelFactory<C> childFactory) {
        return new SingleParentChildStoreImpl<>(
                childProjection,
                databaseAdapter,
                new SQLStatementBuilder(childProjection.childTableInfo),
                new CursorExecutorImpl<>(childFactory));
    }
}
@@ -2482,32 +2482,16 @@
 y() %7B%7D%0A%0A
-    @Deprecated%0A
     publ
@@ -2630,93 +2630,78 @@
 er, 
-String tableName, String%5B%5D columns,%0A                       StatementBinder%3CI%3E binder,
+TableInfo tableInfo, StatementBinder%3CI%3E binder,%0A                      
  Cur
@@ -2773,32 +2773,48 @@
 atementBuilder =
+%0A               
  new SQLStatemen
@@ -2827,29 +2827,54 @@
 er(table
-Name, columns
+Info.name(), tableInfo.columns().all()
 , new St
@@ -3115,387 +3115,8 @@
  %7D%0A%0A
-    public static %3CI extends Model & ObjectWithUidInterface%3E IdentifiableObjectStore%3CI%3E%0A    objectWithUidStore(DatabaseAdapter databaseAdapter, TableInfo tableInfo, StatementBinder%3CI%3E binder,%0A                       CursorModelFactory%3CI%3E modelFactory) %7B%0A        return objectWithUidStore(databaseAdapter, tableInfo.name(), tableInfo.columns().all(), binder, modelFactory);%0A    %7D%0A%0A
     

Delete deprecated and not used method on StoreFactory