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

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.all.pdfreader.pro.app.databinding.FragmentFavoriteBinding
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 BaseFrag : Fragment() {
    protected abstract val TAG: String
    protected val appStore by lazy { AppStore(requireActivity()) }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        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(requireActivity(), message)
    }

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