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

import android.os.Handler;

import java.util.List;
import java.util.concurrent.ExecutorService;

import javax.inject.Inject;

import it.integry.integrywmsnative.core.data_store.db.dao.MtbColrDao;
import it.integry.integrywmsnative.core.data_store.db.entity.SqlMtbColr;
import it.integry.integrywmsnative.core.data_store.db.repository.MtbColrDataSource;
import it.integry.integrywmsnative.core.expansion.RunnableArgs;

public class SqlMtbColrDataSource extends BaseDataSource implements MtbColrDataSource {

    private final MtbColrDao mMtbColrDao;

    @Inject
    public SqlMtbColrDataSource(ExecutorService executorService,
                                Handler handler,
                                MtbColrDao mtbColrDao) {
        super(executorService, handler);
        this.mMtbColrDao = mtbColrDao;
    }

    public void selectAll(RunnableArgs<List<SqlMtbColr>> onSuccess, RunnableArgs<Exception> onError) {
        execute(mMtbColrDao::getAll, onSuccess, onError);
    }

    public void selectAllByDocumentID(long documentId, RunnableArgs<List<SqlMtbColr>> onSuccess, RunnableArgs<Exception> onError) {
        execute(() -> mMtbColrDao.getDocumentRows(documentId), onSuccess, onError);
    }

    public void insert(SqlMtbColr mtbColr, RunnableArgs<Integer> onSuccess, RunnableArgs<Exception> onError) {
        execute(() -> mMtbColrDao.insert(mtbColr),
                mtbColrId -> onSuccess.run(mtbColrId.intValue()),
                onError);
    }


    public void update(SqlMtbColr mtbColr, RunnableArgs<SqlMtbColr> onSuccess, RunnableArgs<Exception> onError) {
        execute(() -> mMtbColrDao.update(mtbColr),
                () -> onSuccess.run(mtbColr),
                onError);
    }

    public void delete(SqlMtbColr mtbColr, Runnable onSuccess, RunnableArgs<Exception> onError) {
        execute(() -> mMtbColrDao.delete(mtbColr),
                onSuccess,
                onError);
    }
}
