package com.module.database.room

import android.content.Context
import android.database.Cursor
import android.util.Log
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.sqlite.db.SupportSQLiteDatabase
import com.module.database.BuildConfig
import com.module.database.room.dao.BillDao
import com.module.database.room.dao.LocalOrderDao
import com.module.database.room.dao.WarringDao
import com.module.database.room.entity.BillBean
import com.module.database.room.entity.LocalOrderBean
import com.module.database.room.entity.WarringBean


@Database(
    entities = [BillBean::class, WarringBean::class, LocalOrderBean::class],
    version = 1
)
abstract class SZDatabase : RoomDatabase() {

    abstract fun getBillDao(): BillDao

    abstract fun getWarringDao(): WarringDao

    abstract fun getLocalOrderDao(): LocalOrderDao

    companion object {
        @Volatile
        private var INSTANCE: SZDatabase? = null

        fun getDatabase(context: Context): SZDatabase {
            val tempInstance = INSTANCE
            if (tempInstance != null) {
                return tempInstance
            }
            synchronized(this) {
                val instance = Room.databaseBuilder(
                    context.applicationContext,
                    SZDatabase::class.java,
                    "sz_database"
                ).build()
                INSTANCE = instance
                return instance
            }
        }
    }
}