package com.jordanbot.autoride.utils

import android.content.Context
import android.provider.Settings

import android.content.pm.PackageManager
import java.security.MessageDigest

object DeviceUtils {
    /**
     * Returns a unique fingerprint for the device based on Android ID.
     */
    fun getDeviceFingerprint(context: Context): String {
        return Settings.Secure.getString(context.contentResolver, Settings.Secure.ANDROID_ID) ?: "UNKNOWN_DEVICE"
    }

    /**
     * Returns the SHA-256 signature of the installed app.
     */
    fun getAppSignatureSHA256(context: Context): String {
        try {
            val packageInfo = context.packageManager.getPackageInfo(
                context.packageName,
                PackageManager.GET_SIGNATURES
            )
            for (signature in packageInfo.signatures) {
                val md = MessageDigest.getInstance("SHA-256")
                md.update(signature.toByteArray())
                val digest = md.digest()
                return digest.joinToString("") { "%02x".format(it) }
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }
        return ""
    }
}
