package com.ys.bdtp.adm.mvvm.model.db

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.ys.bdtp.adm.mvvm.model.db.dao.InfoDao
import com.ys.bdtp.adm.mvvm.model.db.dao.ProblemArchDao
import com.ys.bdtp.adm.mvvm.model.db.entity.dict.ContainerConfigEntity
import com.framework.mvvm.model.db.entity.task.PipeEntity
import com.ys.bdtp.adm.mvvm.model.db.converter.GsonConverter
import com.ys.bdtp.adm.mvvm.model.db.dao.ComponentDao
import com.ys.bdtp.adm.mvvm.model.db.dao.ConfigDao
import com.ys.bdtp.adm.mvvm.model.db.dao.ContainerConfigDao
import com.ys.bdtp.adm.mvvm.model.db.dao.EquipmentDao
import com.ys.bdtp.adm.mvvm.model.db.dao.FileDao
import com.ys.bdtp.adm.mvvm.model.db.dao.InfosConfigDao
import com.ys.bdtp.adm.mvvm.model.db.dao.JobSpaceDao
import com.ys.bdtp.adm.mvvm.model.db.dao.M2dEquipDao
import com.ys.bdtp.adm.mvvm.model.db.dao.MajorDao
import com.ys.bdtp.adm.mvvm.model.db.dao.ObjectDao
import com.ys.bdtp.adm.mvvm.model.db.dao.PipeConfigDao
import com.ys.bdtp.adm.mvvm.model.db.dao.PipeDao
import com.ys.bdtp.adm.mvvm.model.db.dao.ProblemEquipDao
import com.ys.bdtp.adm.mvvm.model.db.dao.ProjectDao
import com.ys.bdtp.adm.mvvm.model.db.dao.QrCodeDao
import com.ys.bdtp.adm.mvvm.model.db.dao.RelConfigDao
import com.ys.bdtp.adm.mvvm.model.db.dao.RelationDao
import com.ys.bdtp.adm.mvvm.model.db.dao.RelationDictDao
import com.ys.bdtp.adm.mvvm.model.db.dao.ServeAreaDao
import com.ys.bdtp.adm.mvvm.model.db.dao.SystemDao
import com.ys.bdtp.adm.mvvm.model.db.dao.UserDao
import com.ys.bdtp.adm.mvvm.model.db.entity.ProjectEntity
import com.ys.bdtp.adm.mvvm.model.db.entity.UserEntity
import com.ys.bdtp.adm.mvvm.model.db.entity.dict.ComponentEntity
import com.ys.bdtp.adm.mvvm.model.db.entity.dict.ConfigEntity
import com.ys.bdtp.adm.mvvm.model.db.entity.dict.EquipmentEntity
import com.ys.bdtp.adm.mvvm.model.db.entity.dict.InfoEntity
import com.ys.bdtp.adm.mvvm.model.db.entity.dict.InfosConfigEntity
import com.ys.bdtp.adm.mvvm.model.db.entity.dict.M2dEquipEntity
import com.ys.bdtp.adm.mvvm.model.db.entity.dict.MajorEntity
import com.ys.bdtp.adm.mvvm.model.db.entity.dict.PipeConfigEntity
import com.ys.bdtp.adm.mvvm.model.db.entity.dict.RelConfigEntity
import com.ys.bdtp.adm.mvvm.model.db.entity.dict.RelationDictEntity
import com.ys.bdtp.adm.mvvm.model.db.entity.dict.SystemEntity
import com.ys.bdtp.adm.mvvm.model.db.entity.task.FileEntity
import com.ys.bdtp.adm.mvvm.model.db.entity.task.JobSpaceEntity
import com.ys.bdtp.adm.mvvm.model.db.entity.task.ObjectEntity
import com.ys.bdtp.adm.mvvm.model.db.entity.task.ProblemArchEntity
import com.ys.bdtp.adm.mvvm.model.db.entity.task.ProblemEquipEntity
import com.ys.bdtp.adm.mvvm.model.db.entity.task.QrCodeEntity
import com.ys.bdtp.adm.mvvm.model.db.entity.task.RelationEntity
import com.ys.bdtp.adm.mvvm.model.db.entity.task.ServeAreaEntity


@Database(
    entities = [
        MajorEntity::class,
        SystemEntity::class,
        RelationDictEntity::class,
        EquipmentEntity::class,
        InfosConfigEntity::class,
        PipeConfigEntity::class,
        RelConfigEntity::class,
        M2dEquipEntity::class,
        ConfigEntity::class,
        FileEntity::class,
        JobSpaceEntity::class,
        QrCodeEntity::class,
        ObjectEntity::class,
        ProjectEntity::class,
        RelationEntity::class,
        ProblemArchEntity::class,
        ProblemEquipEntity::class,
        ComponentEntity::class,
        PipeEntity::class,
        ServeAreaEntity::class,
        ContainerConfigEntity::class,
        InfoEntity::class,
        UserEntity::class
    ], version = 1, exportSchema = true
)
@TypeConverters(GsonConverter::class)
abstract class AdmDatabase : RoomDatabase() {
    abstract fun configDao(): ConfigDao
    abstract fun equipmentDao(): EquipmentDao
    abstract fun fileDao(): FileDao
    abstract fun infosConfigDao(): InfosConfigDao
    abstract fun m2dEquipDao(): M2dEquipDao
    abstract fun majorDao(): MajorDao
    abstract fun objectDao(): ObjectDao
    abstract fun pipeConfigDao(): PipeConfigDao
    abstract fun problemArchDao(): ProblemArchDao
    abstract fun problemEquipDao(): ProblemEquipDao
    abstract fun projectDao(): ProjectDao
    abstract fun qrCodeDao(): QrCodeDao
    abstract fun relationDao(): RelationDao
    abstract fun relationDictDao(): RelationDictDao
    abstract fun relConfigDao(): RelConfigDao
    abstract fun jobSpaceDao(): JobSpaceDao
    abstract fun systemDao(): SystemDao
    abstract fun componentDao(): ComponentDao
    abstract fun pipeDao(): PipeDao
    abstract fun serveAreaDao(): ServeAreaDao
    abstract fun containerConfigDao(): ContainerConfigDao
    abstract fun infoDao(): InfoDao
    abstract fun userDao(): UserDao

    companion object {
        @Volatile
        private var instance: AdmDatabase? = null

        operator fun invoke(context: Context): AdmDatabase {
            return instance ?: synchronized(this) {
                instance ?: Room.databaseBuilder(
                    context,
                    AdmDatabase::class.java,
                    "adm_db"
                ).build().also { instance = it }
            }
        }
    }
}