package com.all.pdfreader.pro.app.ui.act

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat
import com.all.pdfreader.pro.app.room.repository.PdfRepository
import com.all.pdfreader.pro.app.sp.AppStore
import com.all.pdfreader.pro.app.util.ToastUtils

abstract class BaseActivity : AppCompatActivity() {

    protected abstract val TAG: String
    protected val appStore by lazy { AppStore(this) }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        WindowCompat.setDecorFitsSystemWindows(window, true)
        Log.d("ocean", "🚀 ${javaClass.simpleName} onCreate")
    }

    override fun onStart() {
        super.onStart()
        Log.d("ocean", "🔄 ${javaClass.simpleName} onStart")
    }

    override fun onResume() {
        super.onResume()
        Log.d("ocean", "📱 ${javaClass.simpleName} onResume")
    }

    override fun onPause() {
        super.onPause()
        Log.d("ocean", "⏸️ ${javaClass.simpleName} onPause")
    }

    override fun onStop() {
        super.onStop()
        Log.d("ocean", "🛑 ${javaClass.simpleName} onStop")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d("ocean", "💀 ${javaClass.simpleName} onDestroy")
    }

    protected fun logDebug(message: String) {
        Log.d("ocean", "$TAG: $message")
    }

    protected fun logError(message: String, throwable: Throwable? = null) {
        Log.e("ocean", "$TAG: $message", throwable)
    }

    protected fun logInfo(message: String) {
        Log.i("ocean", "$TAG: $message")
    }

    protected fun logWarning(message: String) {
        Log.w("ocean", "$TAG: $message")
    }

    protected fun showToast(message: String) {
        ToastUtils.show(this, message)
    }

    //获取数据库实例
    protected fun getRepository(): PdfRepository {
        return PdfRepository.getInstance()
    }
}