package com.github.nullptroma.wallenc.usecases

import com.github.nullptroma.wallenc.domain.datatypes.StorageEncryptionInfo
import com.github.nullptroma.wallenc.domain.interfaces.StorageSyncGroup
import com.github.nullptroma.wallenc.domain.interfaces.StorageSyncGroupEncryptionKind
import com.github.nullptroma.wallenc.usecases.fakes.FakeMetaInfo
import com.github.nullptroma.wallenc.usecases.fakes.FakeStorage
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import java.util.UUID

class StorageSyncEncryptionCompatTest {

    @Test
    fun storageWithoutEncInfoIsCompatible() {
        val storage = FakeStorage(uuid = UUID.randomUUID(), meta = FakeMetaInfo(encInfo = null))
        val group = StorageSyncGroup(
            id = "g1",
            storageUuids = setOf(storage.uuid),
            encryptionKind = StorageSyncGroupEncryptionKind.NONE,
        )
        assertTrue(isStorageCompatibleWithGroup(storage = storage, group = group))
    }

    @Test
    fun storageWithEncInfoIsIncompatible() {
        val storage = FakeStorage(
            uuid = UUID.randomUUID(),
            meta = FakeMetaInfo(
                encInfo = StorageEncryptionInfo(encryptedTestData = "x", pathIv = ByteArray(16)),
            ),
        )
        val group = StorageSyncGroup(
            id = "g1",
            storageUuids = setOf(storage.uuid),
            encryptionKind = StorageSyncGroupEncryptionKind.NONE,
        )
        assertFalse(isStorageCompatibleWithGroup(storage = storage, group = group))
    }
}
