2022-09-09 13:40:46 +00:00
|
|
|
package dev.inmo.plaguposter.common
|
2022-08-21 15:54:18 +00:00
|
|
|
|
2022-12-14 05:50:02 +00:00
|
|
|
import dev.inmo.tgbotapi.types.FullChatIdentifierSerializer
|
|
|
|
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
2022-09-04 07:27:35 +00:00
|
|
|
import kotlinx.serialization.SerialName
|
2022-08-21 15:54:18 +00:00
|
|
|
import kotlinx.serialization.Serializable
|
|
|
|
|
|
|
|
@Serializable
|
|
|
|
data class ChatConfig(
|
2022-09-04 07:27:35 +00:00
|
|
|
@SerialName("targetChat")
|
2022-12-14 05:50:02 +00:00
|
|
|
@Serializable(FullChatIdentifierSerializer::class)
|
2023-08-12 17:49:25 +00:00
|
|
|
val targetChatId: IdChatIdentifier? = null,
|
2022-09-04 07:27:35 +00:00
|
|
|
@SerialName("sourceChat")
|
2022-12-14 05:50:02 +00:00
|
|
|
@Serializable(FullChatIdentifierSerializer::class)
|
2023-12-10 18:19:18 +00:00
|
|
|
val sourceChatId: IdChatIdentifier?,
|
2022-09-04 07:27:35 +00:00
|
|
|
@SerialName("cacheChat")
|
2022-12-14 05:50:02 +00:00
|
|
|
@Serializable(FullChatIdentifierSerializer::class)
|
2023-08-12 17:49:25 +00:00
|
|
|
val cacheChatId: IdChatIdentifier,
|
|
|
|
@SerialName("targetChats")
|
|
|
|
val targetChatIds: List<@Serializable(FullChatIdentifierSerializer::class) IdChatIdentifier> = emptyList(),
|
2023-12-10 18:19:18 +00:00
|
|
|
@SerialName("sourceChats")
|
|
|
|
val sourceChatIds: List<@Serializable(FullChatIdentifierSerializer::class) IdChatIdentifier> = emptyList(),
|
2022-12-14 05:50:02 +00:00
|
|
|
) {
|
2023-08-12 17:49:25 +00:00
|
|
|
val allTargetChatIds by lazy {
|
2023-12-10 18:19:18 +00:00
|
|
|
(listOfNotNull(targetChatId) + targetChatIds).toSet()
|
|
|
|
}
|
|
|
|
val allSourceChatIds by lazy {
|
|
|
|
(listOfNotNull(sourceChatId) + sourceChatIds).toSet()
|
2023-08-12 17:49:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
init {
|
|
|
|
require(targetChatId != null || targetChatIds.isNotEmpty()) {
|
|
|
|
"One of fields, 'targetChat' or 'targetChats' should be presented"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-14 05:50:02 +00:00
|
|
|
fun check(chatId: IdChatIdentifier) = when (chatId) {
|
2023-12-10 18:19:18 +00:00
|
|
|
in allTargetChatIds,
|
|
|
|
in allSourceChatIds,
|
2022-12-14 05:50:02 +00:00
|
|
|
cacheChatId -> true
|
|
|
|
else -> false
|
|
|
|
}
|
|
|
|
}
|