package com.foxx.androidcast;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import com.foxx.androidcast.remoteaccess.RemoteAccessMode;
import com.foxx.androidcast.remoteaccess.RemoteAccessStatusStore;

import org.junit.Test;

public class CastTrayContentTest {

    @Test
    public void prodIdle_showsTapToOpen() {
        CastTrayContent.Body body = CastTrayContent.build(
                "Tap to open",
                "Cast active",
                "Waiting for Wi‑Fi",
                "adb connect %1$s",
                "Polling BE (%1$s)",
                "Connected",
                "Session %1$s",
                false,
                false,
                "",
                RemoteAccessMode.DISABLED,
                null);
        assertEquals("Tap to open", body.summary);
        assertEquals("Tap to open", body.bigText);
    }

    @Test
    public void casting_overridesDevLines() {
        CastTrayContent.Body body = CastTrayContent.build(
                "Tap to open",
                "Cast active",
                "Waiting",
                "adb %1$s",
                "Poll %1$s",
                "Connected",
                "Session %1$s",
                true,
                true,
                "192.168.1.1:5555",
                RemoteAccessMode.RSSH,
                snapshot(RemoteAccessStatusStore.STATE_WAIT, ""));
        assertEquals("Cast active", body.summary);
    }

    @Test
    public void devMode_combinesRaAndAdbLines() {
        RemoteAccessStatusStore.Snapshot snap =
                snapshot(RemoteAccessStatusStore.STATE_WAIT, "");
        CastTrayContent.Body body = CastTrayContent.build(
                "Tap to open",
                "Cast active",
                "Waiting for Wi‑Fi",
                "adb connect %1$s",
                "Polling BE (%1$s)",
                "Connected",
                "Session %1$s",
                false,
                true,
                "10.0.0.5:5555",
                RemoteAccessMode.RSSH,
                snap);
        assertEquals("Polling BE (RSSH)", body.summary);
        assertTrue(body.bigText.contains("Polling BE (RSSH)"));
        assertTrue(body.bigText.contains("adb connect 10.0.0.5:5555"));
    }

    @Test
    public void remoteAccess_connectedSession_appendsRsshTag() {
        RemoteAccessStatusStore.Snapshot snap =
                snapshot(RemoteAccessStatusStore.STATE_SUCCESS, "abc-123");
        String line = CastTrayContent.remoteAccessLine(
                "Polling BE (%1$s)",
                "Connected",
                "Connected · session %1$s",
                RemoteAccessMode.RSSH,
                snap);
        assertEquals("Connected · session abc-123 (RSSH)", line);
    }

    private static RemoteAccessStatusStore.Snapshot snapshot(String state, String sessionId) {
        return new RemoteAccessStatusStore.Snapshot(
                "rssh", state, "", "", "", "", sessionId, 0L);
    }
}
