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.DispatchSheetUploadReceiptDto

class DispatchSheetUploadReceiptVerifierTest {
    private val upload = DispatchSheetUploadEntity(
        clientRequestId = "6f7a7d10-b7f7-41ab-8f5e-f1afc3e93736",
        workDate = "2026-07-03",
        replacePhotoId = "12",
        localPath = "/tmp/dispatch-sheet.jpg",
        source = "camera",
        takenAt = null,
        latitude = null,
        longitude = null,
        locationAccuracyMeters = null,
        mimeType = "image/jpeg",
        size = 1200,
        contentSha256 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
    )

    @Test
    fun confirmsOnlyMatchingReceipt() {
        assertTrue(
            DispatchSheetUploadReceiptVerifier.matches(
                upload,
                DispatchSheetUploadReceiptDto(
                    clientRequestId = upload.clientRequestId,
                    serverPhotoId = "55",
                    contentSha256 = upload.contentSha256.uppercase(),
                    storedAt = "2026-07-03T17:02:00+02:00",
                ),
            ),
        )
    }

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

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