package com.yono.messeripos.database;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.DatabaseConfiguration;
import androidx.room.InvalidationTracker;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.sqlite.db.SupportSQLiteOpenHelper;

import com.yono.messeripos.daos.CartDaos;
import com.yono.messeripos.daos.PaymentPendingDaos;
import com.yono.messeripos.models.PaymentPending;
import com.yono.messeripos.models.ProductCartModels;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Database(entities = {ProductCartModels.class, PaymentPending.class}, version = 1, exportSchema = false)
public abstract class LocalDatabase extends RoomDatabase {

    public abstract CartDaos cartDaos();
    public abstract PaymentPendingDaos paymentPendingDaos();

    private static volatile LocalDatabase INSTANCE;
    private static final int NUMBER_OF_THREADS = 407;

    public static final ExecutorService databaseWriterExecutor =
            Executors.newFixedThreadPool(NUMBER_OF_THREADS);

    public static LocalDatabase geDatabase(Context context){
        if (INSTANCE == null){
            synchronized (LocalDatabase.class){
                if (INSTANCE == null){
                    INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                            LocalDatabase.class, "db_messer").build();
                }
            }
        }
        return INSTANCE;
    }


    @NonNull
    @Override
    protected SupportSQLiteOpenHelper createOpenHelper(DatabaseConfiguration config) {
        return null;
    }

    @NonNull
    @Override
    protected InvalidationTracker createInvalidationTracker() {
        return null;
    }

    @Override
    public void clearAllTables() {

    }


}
