package pl.firmatpp.kierowca.data

import okio.Buffer
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Test

class PhotoUploadMetadataTest {
    @Test
    fun convertsPresentCameraMetadataToMultipartTextParts() {
        val parts = PhotoUploadMetadata(
            takenAt = "2026-06-30T07:38:12Z",
            latitude = 50.0619474,
            longitude = 19.9368564,
            locationAccuracyMeters = 8.5,
        ).toMultipartTextParts()

        assertEquals("2026-06-30T07:38:12Z", parts.getValue("takenAt").readUtf8())
        assertEquals("50.0619474", parts.getValue("latitude").readUtf8())
        assertEquals("19.9368564", parts.getValue("longitude").readUtf8())
        assertEquals("8.5", parts.getValue("locationAccuracyMeters").readUtf8())
    }

    @Test
    fun skipsLocationPartsWhenMetadataIsEmpty() {
        val parts = PhotoUploadMetadata().toMultipartTextParts()

        assertFalse(parts.containsKey("latitude"))
        assertFalse(parts.containsKey("longitude"))
        assertFalse(parts.containsKey("locationAccuracyMeters"))
    }

    private fun okhttp3.RequestBody.readUtf8(): String {
        val buffer = Buffer()
        writeTo(buffer)
        return buffer.readUtf8()
    }
}
