package swiss.qpq.gajumobile

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Test
import org.junit.runner.RunWith
import swiss.qpq.gajumobile.data.WalletRepository
import swiss.qpq.gajumobile.data.models.Account
import swiss.qpq.gajumobile.data.models.Wallet

@RunWith(AndroidJUnit4::class)
class WalletSecurityTest {

    @Test
    fun testWalletEncryptionAndPersistence() {
        val appContext = InstrumentationRegistry.getInstrumentation().targetContext
        val repository = WalletRepository(appContext)
        
        val testAccount = Account(
            id = "test_acc_1",
            label = "My Test Account",
            publicKey = "pub_key_base64",
            encryptedPrivateKey = "enc_priv_key_base64"
        )
        
        val testWallet = Wallet(
            id = "test_wallet_1",
            name = "Test Wallet",
            accounts = listOf(testAccount)
        )

        // 1. Save the wallet
        repository.saveWallet(testWallet)

        // 2. Load the wallet
        val loadedWallet = repository.loadWallet("test_wallet_1")

        // 3. Verify
        assertNotNull(loadedWallet)
        assertEquals(testWallet.id, loadedWallet?.id)
        assertEquals(testWallet.name, loadedWallet?.name)
        assertEquals(1, loadedWallet?.accounts?.size)
        assertEquals("My Test Account", loadedWallet?.accounts?.first()?.label)
    }
}
