package app.closer.notifications

import app.closer.core.navigation.AppRoute
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test

class PartnerNotificationTypeTest {

    @Test
    fun `remote type mapping covers all batch 6 types`() {
        assertNotNull(PartnerNotificationType.fromRemoteType("partner_answered"))
        assertNotNull(PartnerNotificationType.fromRemoteType("reveal_ready"))
        assertNotNull(PartnerNotificationType.fromRemoteType("partner_started_game"))
        assertNotNull(PartnerNotificationType.fromRemoteType("partner_completed_part"))
        assertNotNull(PartnerNotificationType.fromRemoteType("challenge_waiting"))
        assertNotNull(PartnerNotificationType.fromRemoteType("memory_capsule_unlocked"))
    }

    @Test
    fun `unknown remote types are rejected`() {
        assertNull(PartnerNotificationType.fromRemoteType("arbitrary_backend_title"))
        assertNull(PartnerNotificationType.fromRemoteType(""))
    }

    @Test
    fun `reveal ready falls back to history when question id missing`() {
        val route = PartnerNotificationType.REVEAL_READY.routeFor(PartnerNotificationPayload())

        assertEquals(AppRoute.ANSWER_HISTORY, route)
    }

    @Test
    fun `partner answered deep links to daily question`() {
        val route = PartnerNotificationType.PARTNER_ANSWERED.routeFor(PartnerNotificationPayload())
        assertEquals(AppRoute.DAILY_QUESTION, route)
    }

    @Test
    fun `game notifications deep link to play hub`() {
        assertEquals(AppRoute.PLAY, PartnerNotificationType.PARTNER_STARTED_GAME.routeFor(PartnerNotificationPayload()))
        assertEquals(AppRoute.PLAY, PartnerNotificationType.PARTNER_COMPLETED_PART.routeFor(PartnerNotificationPayload()))
    }

    @Test
    fun `challenge waiting deep links to challenges`() {
        val route = PartnerNotificationType.CHALLENGE_WAITING.routeFor(PartnerNotificationPayload())
        assertEquals(AppRoute.CONNECTION_CHALLENGES, route)
    }

    @Test
    fun `capsule unlocked deep links to memory lane`() {
        val route = PartnerNotificationType.CAPSULE_UNLOCKED.routeFor(PartnerNotificationPayload())
        assertEquals(AppRoute.MEMORY_LANE, route)
    }

    @Test
    fun `partner trigger types use the partner action channel`() {
        assertTrue(
            listOf(
                PartnerNotificationType.PARTNER_ANSWERED,
                PartnerNotificationType.REVEAL_READY,
                PartnerNotificationType.PARTNER_STARTED_GAME,
                PartnerNotificationType.PARTNER_COMPLETED_PART,
                PartnerNotificationType.CAPSULE_UNLOCKED
            ).all { it.channelId == NotificationChannelSetup.CHANNEL_PARTNER_ACTIONS || it.channelId == NotificationChannelSetup.CHANNEL_GAMES }
        )
    }

    @Test
    fun `reminder type uses reminders channel`() {
        assertEquals(
            NotificationChannelSetup.CHANNEL_REMINDERS,
            PartnerNotificationType.CHALLENGE_WAITING.channelId
        )
    }

    @Test
    fun `notification copy never includes placeholder or answer text`() {
        PartnerNotificationType.entries.forEach { type ->
            assertTrue("${type.name} title must not be blank", type.title.isNotBlank())
            assertTrue("${type.name} body must not be blank", type.body.isNotBlank())
            assertTrue(
                "${type.name} title must be static and safe",
                type.title !in listOf("{questionId}", "{answer}")
            )
            assertTrue(
                "${type.name} body must be static and safe",
                type.body !in listOf("{questionId}", "{answer}")
            )
        }
    }
}
