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.model.PhotoUploadReceiptDto

class PhotoUploadReceiptVerifierTest {
    private val upload = PhotoUploadEntity(
        clientRequestId = "6f7a7d10-b7f7-41ab-8f5e-f1afc3e93736",
        routeId = "10",
        localPath = "/tmp/photo.jpg",
        source = "camera",
        takenAt = null,
        latitude = null,
        longitude = null,
        locationAccuracyMeters = null,
        mimeType = "image/jpeg",
        size = 1200,
        contentSha256 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
    )

    @Test
    fun confirmsOnlyMatchingReceipt() {
        assertTrue(
            PhotoUploadReceiptVerifier.matches(
                upload,
                PhotoUploadReceiptDto(
                    clientRequestId = upload.clientRequestId,
                    serverPhotoId = "55",
                    contentSha256 = upload.contentSha256.uppercase(),
                    storedAt = "2026-07-01T10:00:00+02:00",
                ),
            ),
        )
    }

    @Test
    fun rejectsDifferentRequestOrHash() {
        assertFalse(
            PhotoUploadReceiptVerifier.matches(
                upload,
                PhotoUploadReceiptDto(
                    clientRequestId = "other",
                    serverPhotoId = "55",
                    contentSha256 = upload.contentSha256,
                    storedAt = null,
                ),
            ),
        )

        assertFalse(
            PhotoUploadReceiptVerifier.matches(
                upload,
                PhotoUploadReceiptDto(
                    clientRequestId = upload.clientRequestId,
                    serverPhotoId = "55",
                    contentSha256 = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
                    storedAt = null,
                ),
            ),
        )
    }
}
