package id.ac.ubharajaya.sistemakademik

import android.graphics.Bitmap
import android.util.Base64
import org.json.JSONObject
import java.io.ByteArrayOutputStream

data class Absensi(
    val npm: String,
    val nama: String,
    val latitude: Double,
    val longitude: Double,
    val waktu: String,
    val foto: Bitmap
) {
    fun toJson(): JSONObject {
        val json = JSONObject()
        json.put("npm", npm)
        json.put("nama", nama)
        json.put("latitude", latitude)
        json.put("longitude", longitude)
        json.put("waktu", waktu)

        // Convert Bitmap to Base64
        val byteArrayOutputStream = ByteArrayOutputStream()
        foto.compress(Bitmap.CompressFormat.JPEG, 80, byteArrayOutputStream)
        val byteArray = byteArrayOutputStream.toByteArray()
        val encodedImage = Base64.encodeToString(byteArray, Base64.DEFAULT)
        json.put("foto", encodedImage)

        return json
    }
}