package com.design.zenspace.entity

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
@Database(entities = [Feature::class], version = 1, exportSchema = false)
abstract class AppDataBase:RoomDatabase() {
    abstract fun featureDao():FeatureDao
    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,"zenspace_database").fallbackToDestructiveMigration().build()
        }
    }
}