package com.foxx.androidcast.ota;

/*********************************************************************
 * OtaManifestTest.java
 * Created at: Wed 20 May 2026 14:31:55 +0200
 * Updated at: Wed 20 May 2026 15:17:13 +0200 by Anton Afanasyeu <a.afanasieff@gmail.com>
 * Commit: 5d8e82d2e60a21fff3138d2a394ee4e8b4c6dcb8
 * class OtaManifestTest
 * Contributors:
 *    - Anton Afanasyeu <a.afanasieff@gmail.com> (2 commits, 56 lines)
 *    - Cursor Agent (project assistant)
 * Digest: SHA256	947b22f2fbf6de295f87d5a7d7a3ab16cc04ad70528981f3e459a1738a54f0c7
**********************************************************************/
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class OtaManifestTest {
    @Test
    public void effectiveVersionCode_prefersTriple() {
        OtaManifest m = new OtaManifest(0, 1, 5, 999, "0.1.5",
                "https://example.com/x.otapkg", "", "", 0L, false, "");
        assertEquals(105, m.effectiveVersionCode());
        assertEquals("0.1.5", m.displayVersion());
        assertTrue(m.isValid());
    }

    @Test
    public void effectiveVersionCode_legacyVersionCode() {
        OtaManifest m = new OtaManifest(-1, -1, -1, 42, "legacy",
                "https://example.com/x.apk", "", "abc", 0L, false, "");
        assertEquals(42, m.effectiveVersionCode());
        assertTrue(m.isValid());
    }

    @Test
    public void isValid_requiresDownloadTargetAndVersion() {
        assertFalse(new OtaManifest(0, 0, 0, 0, "", "", "", "", 0L, false, "").isValid());
        assertTrue(new OtaManifest(0, 0, 1, 0, "", "https://x/a.apk", "", "", 0L, false, "")
                .isValid());
        OtaManifest bundleOnly = new OtaManifest(0, 1, 0, 0, "0.1.0", "", "", "abc", 0L,
                false, "", "https://x/bundle.otabundle.zip", "def", 99L);
        assertTrue(bundleOnly.isValid());
        assertTrue(bundleOnly.hasHttpBundle());
        assertEquals(99L, bundleOnly.downloadSizeBytes());
    }

    @Test
    public void bundleFields_roundTripInConstructor() {
        OtaManifest m = new OtaManifest(0, 1, 2, 0, "0.1.2",
                "https://h/a.otapkg", "", "dead", 50L, false, "",
                "https://h/a.otabundle.zip", "BEEF", 1000L);
        assertEquals("https://h/a.otabundle.zip", m.bundleUrl);
        assertEquals("beef", m.bundleSha256Hex);
        assertEquals(1000L, m.bundleSizeBytes);
        assertEquals(1000L, m.downloadSizeBytes());
    }
}
