package app.closer.notifications

import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.os.Build

/**
 * Creates the Android notification channels used by partner-triggered notifications.
 *
 * Channels are idempotent; calling [createChannels] multiple times is safe.
 */
class NotificationChannelSetup(private val context: Context) {

    companion object {
        const val CHANNEL_REMINDERS = "reminders"
        const val CHANNEL_PARTNER_ACTIONS = "partner_activity"
        const val CHANNEL_GAMES = "game_activity"

        @JvmStatic
        fun createChannels(context: Context) {
            NotificationChannelSetup(context).createChannels()
        }
    }

    fun createChannels() {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return

        val notificationManager =
            context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

        notificationManager.createNotificationChannels(
            listOf(
                NotificationChannel(
                    CHANNEL_PARTNER_ACTIONS,
                    "Partner activity",
                    NotificationManager.IMPORTANCE_HIGH
                ).apply {
                    description = "When your partner answers, starts a game, or unlocks something for you"
                },
                NotificationChannel(
                    CHANNEL_REMINDERS,
                    "Daily reminders",
                    NotificationManager.IMPORTANCE_DEFAULT
                ).apply {
                    description = "Gentle nudges for today's question and shared moments"
                },
                NotificationChannel(
                    CHANNEL_GAMES,
                    "Games",
                    NotificationManager.IMPORTANCE_HIGH
                ).apply {
                    description = "When your partner starts or completes a game round"
                }
            )
        )
    }
}
