package pl.firmatpp.kierowca.data.upload

import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import pl.firmatpp.kierowca.data.ApiError
import pl.firmatpp.kierowca.data.ApiErrorKind

class PhotoUploadFailureDetailsTest {
    @Test
    fun describesServerFailureWithStatusCodeBackendCodeAndResponseBody() {
        val details = PhotoUploadFailureDetails.fromApiError(
            ApiError(
                kind = ApiErrorKind.Server,
                message = "Storage timeout",
                retryable = true,
                code = "PHOTO_STORAGE_FAILED",
                statusCode = 503,
                responseBody = """{"code":"PHOTO_STORAGE_FAILED","message":"Storage timeout"}""",
            ),
        )

        assertTrue(details.contains("Typ: błąd serwera"))
        assertTrue(details.contains("HTTP: 503"))
        assertTrue(details.contains("Kod: PHOTO_STORAGE_FAILED"))
        assertTrue(details.contains("Odpowiedź serwera:"))
        assertTrue(details.contains("Storage timeout"))
    }

    @Test
    fun describesNetworkFailureWithoutHttpStatus() {
        val details = PhotoUploadFailureDetails.fromApiError(
            ApiError(
                kind = ApiErrorKind.Network,
                message = "Nie udało się połączyć z serwerem.",
                retryable = true,
            ),
        )

        assertTrue(details.contains("Typ: błąd komunikacji"))
        assertTrue(details.contains("Nie udało się połączyć z serwerem."))
        assertFalse(details.contains("HTTP:"))
    }
}
