package com.a2i.forwarder.core

object AppParsers {
    data class Parsed(
        val titleOverride: String? = null,
        val groupKey: String? = null,
        val clickUrl: String? = null,
        val important: Boolean = false,
    )

    private val importantKeywords = listOf(
        "@我", "@all", "@所有人", "语音", "视频", "通话", "邀请你加入", "验证码", "验证代码", "来电",
    )

    private val clickUrls = mapOf(
        "com.tencent.mm" to "weixin://",
        "com.tencent.mobileqq" to "mqq://",
        "com.tencent.tim" to "mqq://",
        "org.telegram.messenger" to "tg://",
        "org.telegram.messenger.web" to "tg://",
        "org.telegram.plus" to "tg://",
    )

    fun parse(packageName: String, title: String, text: String): Parsed {
        val important = importantKeywords.any { text.contains(it) || title.contains(it) }
        val url = clickUrls[packageName]
            ?: return Parsed(important = important)
        val group = "$packageName:${title.ifBlank { "default" }}"
        return Parsed(
            titleOverride = title.takeIf { it.isNotBlank() },
            groupKey = group,
            clickUrl = url,
            important = important,
        )
    }
}
