package com.xyzshell.andinfo.libs

import android.content.Context
import android.os.Build
// import androidx.security.state.SecurityStateManagerCompat
import java.util.Date

class BuildInfo(private val context: Context) {

    // private val securityStateManager = SecurityStateManagerCompat(context)
    // private val globalSecurityState = securityStateManager.getGlobalSecurityState()

    val fingerprint: String
        get() = Build.FINGERPRINT

    val tags: String
        get() = Build.TAGS

    val type: String
        get() = Build.TYPE

    val buildDate: Date
        get() = Date(Build.TIME)

    val host: String
        get() = Build.HOST

    val user: String
        get() = Build.USER

    val id: String
        get() = Build.ID

    val display: String
        get() = Build.DISPLAY

    val versionRelease: String
        get() = Build.VERSION.RELEASE

    val versionCodename: String
        get() = Build.VERSION.CODENAME

    val versionSdkInt: Int
        get() = Build.VERSION.SDK_INT

    val versionPreviewSdkInt: Int
        get() = Build.VERSION.PREVIEW_SDK_INT

    val securityPatch: String
        get() = Build.VERSION.SECURITY_PATCH

    val baseOs: String
        get() = Build.VERSION.BASE_OS

    val incremental: String
        get() = Build.VERSION.INCREMENTAL

    val releaseOrCodename: String?
        get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) Build.VERSION.RELEASE_OR_CODENAME else null

    val mediaPerformanceClass: Int
        get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) Build.VERSION.MEDIA_PERFORMANCE_CLASS else 0

    val releaseOrPreviewDisplay: String?
        get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) Build.VERSION.RELEASE_OR_PREVIEW_DISPLAY else null

    val jvmName: String?
        get() = System.getProperty("java.vm.name")

    val jvmVendor: String?
        get() = System.getProperty("java.vm.vendor")

    val jvmVersion: String?
        get() = System.getProperty("java.vm.version")

    val jvmClassVersion: String?
        get() = System.getProperty("java.class.version")

    val jvmSpecificationName: String?
        get() = System.getProperty("java.specification.name")

    val jvmSpecificationVendor: String?
        get() = System.getProperty("java.specification.vendor")

    val jvmSpecificationVersion: String?
        get() = System.getProperty("java.specification.version")

    val vendorSecurityPatchLevel: String?
        get() = null // globalSecurityState.getString(SecurityStateManagerCompat.KEY_VENDOR_SPL)

    val kernelVersion: String?
        get() = null // globalSecurityState.getString(SecurityStateManagerCompat.KEY_KERNEL_VERSION)

    val kernelCompleteVersion: String?
        get() = System.getProperty("os.version")

    val bootloaderVersion: String
        get() = Build.BOOTLOADER

    val radioVersion: String?
        get() = Build.getRadioVersion()

    val fingerprintedPartitions: List<PartitionInfo>
        get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            Build.getFingerprintedPartitions().map { PartitionInfo(it.name, it.fingerprint) }
        } else {
            emptyList()
        }

    data class PartitionInfo(val name: String, val fingerprint: String)
}
