package pl.firmatpp.kierowca.data

import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody

data class PhotoUploadMetadata(
    val takenAt: String? = null,
    val latitude: Double? = null,
    val longitude: Double? = null,
    val locationAccuracyMeters: Double? = null,
)

fun PhotoUploadMetadata.toMultipartTextParts(): Map<String, RequestBody> = buildMap {
    takenAt?.let { put("takenAt", it.toPlainTextBody()) }
    latitude?.let { put("latitude", it.toString().toPlainTextBody()) }
    longitude?.let { put("longitude", it.toString().toPlainTextBody()) }
    locationAccuracyMeters?.let { put("locationAccuracyMeters", it.toString().toPlainTextBody()) }
}

private fun String.toPlainTextBody(): RequestBody = toRequestBody("text/plain".toMediaTypeOrNull())
