package com.img.rabbit.provider.utils

import android.content.Context
import android.content.pm.PackageManager
import com.img.rabbit.R
import okhttp3.internal.platform.ContextAwarePlatform
import okhttp3.internal.platform.Platform

object HeadParamUtils {
    var applicationContext: Context?
        get() = (Platform.get() as? ContextAwarePlatform)?.applicationContext
        set(value) {
            (Platform.get() as? ContextAwarePlatform)?.applicationContext = value
        }

    fun getAppVersionName(): String? {
        return try {
            val pm = applicationContext?.packageManager
            val pi = applicationContext?.packageName?.let { pm?.getPackageInfo(it, 0) }
            pi?.versionName
        } catch (e: PackageManager.NameNotFoundException) {
            e.printStackTrace()
            null
        }
    }
    fun getAppName(): String? {
        return applicationContext?.resources?.getString(R.string.app_name)
    }

    fun buildVersionNo(): Int? {
        return try {
            val pm = applicationContext?.packageManager
            val pi = applicationContext?.packageName?.let { pm?.getPackageInfo(it, 0) }
            pi?.versionCode
        } catch (e: PackageManager.NameNotFoundException) {
            e.printStackTrace()
            null
        }
    }
}