import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.apps.sketchmaster.data.Base
import com.apps.sketchmaster.data.BaseDao
import com.apps.sketchmaster.data.Customize
import com.apps.sketchmaster.data.CustomizeDao


@Database(entities = [Base::class, Customize::class], version = 2, exportSchema = false)
abstract class AppDataBase : RoomDatabase() {
    abstract fun baseDao(): BaseDao
    abstract fun customizeDao(): CustomizeDao

    companion object {
        @Volatile
        private var INSTANCE: AppDataBase? = null
        fun getDatabase(context: Context): AppDataBase {
            return INSTANCE ?: synchronized(this) {
                INSTANCE ?: createDatabase(context).also { INSTANCE = it }
            }
        }

        private fun createDatabase(context: Context): AppDataBase {
            return Room.databaseBuilder(
                context.applicationContext,
                AppDataBase::class.java,
                "master_database"
            ).fallbackToDestructiveMigration().build()
        }
    }
}
