package com.bearya.kids

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.bearya.data.dao.AnalysisDao
import com.bearya.data.dao.ChapterDao
import com.bearya.data.dao.SectionDao
import com.bearya.data.entity.Analysis
import com.bearya.data.entity.Chapter
import com.bearya.data.entity.Section

@Database(entities = [
    Chapter::class,
    Section::class,
    Analysis::class
], version = 1, exportSchema = true)
abstract class AppDatabase : RoomDatabase() {

    abstract fun chapterDao(): ChapterDao
    abstract fun sectionDao(): SectionDao
    abstract fun analysisDao(): AnalysisDao

    companion object {

        private lateinit var mContext: Context

        val instance: AppDatabase by lazy {
            val room = Room.databaseBuilder(mContext, AppDatabase::class.java, "kids.db")
                    .createFromAsset("database/kids.db")
            if (BuildConfig.DEBUG) room.fallbackToDestructiveMigration()
            room.build()
        }

        fun init(context: Context) {
            this.mContext = context
        }

    }

}