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.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.*
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.BasicConfigEntity
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.*


@Database(
    entities = [
        MajorEntity::class,
        SystemEntity::class,
        RelationDictEntity::class,
        EquipmentEntity::class,
        InfosConfigEntity::class,
        PipeConfigEntity::class,
        RelConfigEntity::class,
        M2dEquipEntity::class,
        BasicConfigEntity::class,
        FileEntity::class,
        JobSpaceEntity::class,
        QrCodeEntity::class,
        ObjectEntity::class,
        ProjectEntity::class,
        RelationEntity::class,
        ProblemEntity::class,
        ComponentEntity::class,
        PipeEntity::class,
        ServeAreaEntity::class,
        ContainerConfigEntity::class,
        InfoEntity::class,
        UserEntity::class,
        CustomInfoEntity::class,
        CadEntity::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 problemDao(): ProblemDao
    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
    abstract fun cadDao(): CadDao
    abstract fun customInfoDao(): CustomInfoDao

    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 }
            }
        }
    }
}