package it.integry.integrywmsnative.core.data_store.db;

import android.app.Application;
import android.os.Handler;

import java.util.concurrent.ExecutorService;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import it.integry.integrywmsnative.core.data_store.db.dao.ArticoloGrigliaDao;
import it.integry.integrywmsnative.core.data_store.db.dao.ArticoloOrdineDao;
import it.integry.integrywmsnative.core.data_store.db.dao.GrigliaDao;
import it.integry.integrywmsnative.core.data_store.db.dao.InventarioDao;
import it.integry.integrywmsnative.core.data_store.db.dao.InventarioRowDao;
import it.integry.integrywmsnative.core.data_store.db.dao.MtbColrDao;
import it.integry.integrywmsnative.core.data_store.db.dao.MtbColtDao;
import it.integry.integrywmsnative.core.data_store.db.dao.OrdineDao;
import it.integry.integrywmsnative.core.data_store.db.dao.RawDao;
import it.integry.integrywmsnative.core.data_store.db.repository.ArticoliOrdineRepository;
import it.integry.integrywmsnative.core.data_store.db.repository.ArticoloGrigliaRepository;
import it.integry.integrywmsnative.core.data_store.db.repository.GrigliaRepository;
import it.integry.integrywmsnative.core.data_store.db.repository.MtbColrDataSource;
import it.integry.integrywmsnative.core.data_store.db.repository.MtbColtRepository;
import it.integry.integrywmsnative.core.data_store.db.repository.OrdineRepository;
import it.integry.integrywmsnative.core.data_store.db.repository.datasource.ArticoliGrigliaDataSource;
import it.integry.integrywmsnative.core.data_store.db.repository.datasource.ArticoliOrdineDataSource;
import it.integry.integrywmsnative.core.data_store.db.repository.datasource.GrigliaDataSource;
import it.integry.integrywmsnative.core.data_store.db.repository.datasource.OrdineDataSource;
import it.integry.integrywmsnative.core.data_store.db.repository.datasource.SqlMtbColrDataSource;
import it.integry.integrywmsnative.core.data_store.db.repository.datasource.SqlMtbColtDataSource;
import it.integry.integrywmsnative.core.data_store.db.respository_new.InventarioRepository;
import it.integry.integrywmsnative.core.data_store.db.respository_new.InventarioRowRepository;
import it.integry.integrywmsnative.core.data_store.db.respository_new.data_source.InventarioLocalDataSource;
import it.integry.integrywmsnative.core.data_store.db.respository_new.data_source.InventarioRowLocalDataSource;
import it.integry.integrywmsnative.core.mapper.InventarioMapper;
import it.integry.integrywmsnative.core.mapper.InventarioRowMapper;
import it.integry.integrywmsnative.core.rest.consumers.InventarioRESTConsumer;

@Module
public class RoomModule {

    private AppDatabase appDatabase;

    public RoomModule(Application applicationContext) {
        appDatabase = AppDatabase.getInstance(applicationContext);
    }

    @Singleton
    @Provides
    AppDatabase providesRoomDatabase() {
        return appDatabase;
    }


    @Singleton
    @Provides
    RawDao providesRawDao(AppDatabase appDatabase) {
        return appDatabase.rawDao();
    }

    @Singleton
    @Provides
    ArticoloGrigliaDao providesArticoloGrigliaDao(AppDatabase appDatabase) {
        return appDatabase.articoloGrigliaDao();
    }

    @Singleton
    @Provides
    GrigliaDao providesGrigliaDao(AppDatabase appDatabase) {
        return appDatabase.grigliaDao();
    }

    @Singleton
    @Provides
    OrdineDao providesOrdineDao(AppDatabase appDatabase) {
        return appDatabase.ordineDao();
    }

    @Singleton
    @Provides
    ArticoloOrdineDao providesArticoloOrdineDao(AppDatabase appDatabase) {
        return appDatabase.articoloOrdineDao();
    }

    @Singleton
    @Provides
    MtbColtDao providesMtbColtDao(AppDatabase appDatabase) {
        return appDatabase.mtbColtDao();
    }

    @Singleton
    @Provides
    MtbColrDao providesMtbColrDao(AppDatabase appDatabase) {
        return appDatabase.mtbColrDao();
    }

    @Singleton
    @Provides
    InventarioDao providesInventarioDao(AppDatabase appDatabase) {
        return appDatabase.inventarioDao();
    }

    @Singleton
    @Provides
    InventarioRowDao providesInventarioRowDao(AppDatabase appDatabase) {
        return appDatabase.inventarioRowDao();
    }


    @Singleton
    @Provides
    InventarioRowMapper providesInventarioRowMapper() {
        return new InventarioRowMapper();
    }

    @Singleton
    @Provides
    InventarioMapper providesInventarioMapper(InventarioRowMapper inventarioRowMapper) {
        return new InventarioMapper(inventarioRowMapper);
    }


    @Provides
    InventarioLocalDataSource providesInventarioLocalDataSource(ExecutorService executorService, InventarioDao inventarioDao) {
        return new InventarioLocalDataSource(executorService, inventarioDao);
    }

    @Provides
    InventarioRowLocalDataSource providesInventarioRowLocalDataSource(ExecutorService executorService, InventarioRowDao inventarioRowDao) {
        return new InventarioRowLocalDataSource(executorService, inventarioRowDao);
    }


    @Provides
    ArticoloGrigliaRepository providesArticoloGrigliaRepository(ExecutorService executorService, Handler handler, ArticoloGrigliaDao articoloGrigliaDao) {
        return new ArticoliGrigliaDataSource(executorService, handler, articoloGrigliaDao);
    }


    @Provides
    ArticoliOrdineRepository providesArticoliOrdineRepository(ExecutorService executorService, Handler handler, ArticoloOrdineDao articoloOrdineDao) {
        return new ArticoliOrdineDataSource(executorService, handler, articoloOrdineDao);
    }


    @Provides
    GrigliaRepository providesGrigliaRepository(ExecutorService executorService, Handler handler, GrigliaDao grigliaDao) {
        return new GrigliaDataSource(executorService, handler, grigliaDao);
    }


    @Provides
    OrdineRepository providesOrdineRepository(ExecutorService executorService, Handler handler, OrdineDao ordineDao) {
        return new OrdineDataSource(executorService, handler, ordineDao);
    }

    @Provides
    MtbColtRepository providesMtbColtRepository(ExecutorService executorService, Handler handler, MtbColtDao mtbColtDao) {
        return new SqlMtbColtDataSource(executorService, handler, mtbColtDao);
    }

    @Provides
    MtbColrDataSource providesMtbColrRepository(ExecutorService executorService, Handler handler, MtbColrDao mtbColrDao) {
        return new SqlMtbColrDataSource(executorService, handler, mtbColrDao);
    }

    @Provides
    InventarioRepository providesInventarioRepository(ExecutorService executorService, Handler handler,
                                                      InventarioLocalDataSource inventarioLocalDataSource,
                                                      InventarioRESTConsumer inventarioRESTConsumer,
                                                      InventarioMapper inventarioMapper) {
        return new InventarioRepository(inventarioLocalDataSource, inventarioRESTConsumer, inventarioMapper, handler, executorService);
    }

    @Provides
    InventarioRowRepository providesInventarioRowRepository(ExecutorService executorService, Handler handler,
                                                            InventarioRowLocalDataSource inventarioRowLocalDataSource,
                                                            InventarioRESTConsumer inventarioRESTConsumer,
                                                            InventarioRowMapper inventarioRowMapper) {
        return new InventarioRowRepository(inventarioRowLocalDataSource, inventarioRESTConsumer, inventarioRowMapper, handler);
    }

}
