package com.casic.br.base

import android.app.Application
import com.casic.br.greendao.DaoMaster
import com.casic.br.greendao.DaoSession
import com.pengxh.kt.lite.utils.SaveKeyValues
import com.tuya.smart.home.sdk.TuyaHomeSdk
import kotlin.properties.Delegates


class BaseApplication : Application() {

    private val kTag = "BaseApplication"

    companion object {
        private var instance: BaseApplication by Delegates.notNull()

        fun obtainInstance() = instance

        private lateinit var daoSession: DaoSession
    }

    override fun onCreate() {
        super.onCreate()
        instance = this
        SaveKeyValues.initSharedPreferences(this)
        TuyaHomeSdk.init(this)
        TuyaHomeSdk.setDebugMode(true)
        val devOpenHelper = DaoMaster.DevOpenHelper(this, "SmartKitchen.db", null)
        val daoMaster = DaoMaster(devOpenHelper.writableDatabase)
        daoSession = daoMaster.newSession()
    }

    fun obtainDaoSession(): DaoSession {
        return daoSession
    }
}