2020-12-02 08:39:54 +00:00
|
|
|
package dev.inmo.saucenaoapi.models
|
2019-02-20 04:06:04 +00:00
|
|
|
|
2020-12-02 08:39:54 +00:00
|
|
|
import dev.inmo.saucenaoapi.defaultSauceNaoParser
|
2019-03-21 04:25:23 +00:00
|
|
|
import kotlinx.serialization.*
|
2020-08-22 17:00:07 +00:00
|
|
|
import kotlinx.serialization.builtins.serializer
|
|
|
|
import kotlinx.serialization.descriptors.SerialDescriptor
|
|
|
|
import kotlinx.serialization.encoding.Decoder
|
|
|
|
import kotlinx.serialization.encoding.Encoder
|
2020-08-29 13:09:54 +00:00
|
|
|
import kotlinx.serialization.json.JsonObject
|
|
|
|
import kotlinx.serialization.json.jsonObject
|
2019-02-20 04:06:04 +00:00
|
|
|
|
|
|
|
@Serializable
|
|
|
|
data class Header(
|
|
|
|
@SerialName("status")
|
2019-05-16 11:04:58 +00:00
|
|
|
val status: Int? = null,
|
2019-02-20 04:06:04 +00:00
|
|
|
@SerialName("results_requested")
|
2019-05-16 11:04:58 +00:00
|
|
|
val resultsRequested: Int? = null,
|
2019-03-21 04:25:23 +00:00
|
|
|
@Serializable(IndexesSerializer::class)
|
2019-02-20 04:06:04 +00:00
|
|
|
@SerialName("index")
|
2019-05-16 11:04:58 +00:00
|
|
|
val indexes: List<HeaderIndex?> = emptyList(),
|
2019-02-20 04:06:04 +00:00
|
|
|
@SerialName("search_depth")
|
2019-05-16 11:04:58 +00:00
|
|
|
val searchDepth: Int? = null,
|
2019-02-20 04:06:04 +00:00
|
|
|
@SerialName("minimum_similarity")
|
2019-05-16 11:04:58 +00:00
|
|
|
val minSimilarity: Float? = null,
|
|
|
|
@SerialName("results_returned")
|
|
|
|
val resultsCount: Int? = null,
|
2019-02-20 04:06:04 +00:00
|
|
|
@SerialName("query_image_display")
|
2019-05-16 11:04:58 +00:00
|
|
|
val queryImageDisplay: String? = null, // something like "userdata/uuid.png",
|
2019-02-20 04:06:04 +00:00
|
|
|
@SerialName("query_image")
|
2019-05-16 11:04:58 +00:00
|
|
|
val queryImage: String? = null, // something like "uuid.jpg"
|
2019-05-16 09:28:50 +00:00
|
|
|
@SerialName("short_remaining")
|
2019-08-19 08:13:43 +00:00
|
|
|
val shortRemaining: Int = Int.MAX_VALUE,
|
2019-05-16 09:28:50 +00:00
|
|
|
@SerialName("long_remaining")
|
2019-08-19 08:13:43 +00:00
|
|
|
val longRemaining: Int = Int.MAX_VALUE,
|
2019-05-16 09:28:50 +00:00
|
|
|
@SerialName("short_limit")
|
2019-08-19 08:13:43 +00:00
|
|
|
val shortLimit: Int = Int.MAX_VALUE,
|
2019-05-16 09:28:50 +00:00
|
|
|
@SerialName("long_limit")
|
2019-08-19 08:13:43 +00:00
|
|
|
val longLimit: Int = Int.MAX_VALUE,
|
2019-05-07 02:09:46 +00:00
|
|
|
@SerialName("account_type")
|
2019-05-16 11:04:58 +00:00
|
|
|
val accountType: Int? = null,
|
2019-04-22 01:54:42 +00:00
|
|
|
@SerialName("user_id")
|
|
|
|
val userId: Int? = null
|
2019-02-20 04:06:04 +00:00
|
|
|
)
|
2019-03-21 04:25:23 +00:00
|
|
|
|
2019-12-12 18:47:52 +00:00
|
|
|
internal object IndexesSerializer : KSerializer<List<HeaderIndex?>> {
|
2020-08-22 17:00:07 +00:00
|
|
|
override val descriptor: SerialDescriptor = String.serializer().descriptor
|
2019-03-21 04:25:23 +00:00
|
|
|
|
|
|
|
override fun deserialize(decoder: Decoder): List<HeaderIndex?> {
|
2020-08-22 17:00:07 +00:00
|
|
|
val json = JsonObject.serializer().deserialize(decoder)
|
2019-03-21 04:25:23 +00:00
|
|
|
val parsed = json.keys.mapNotNull { it.toIntOrNull() }.sorted().mapNotNull {
|
2020-08-22 17:00:07 +00:00
|
|
|
val jsonObject = json[it.toString()] ?.jsonObject ?: return@mapNotNull null
|
|
|
|
val index = defaultSauceNaoParser.decodeFromString(
|
|
|
|
HeaderIndex.serializer(),
|
|
|
|
defaultSauceNaoParser.encodeToString(JsonObject.serializer(), jsonObject)
|
|
|
|
)
|
2019-03-21 04:25:23 +00:00
|
|
|
it to index
|
|
|
|
}.toMap()
|
2020-08-22 17:00:07 +00:00
|
|
|
return Array<HeaderIndex?>(parsed.keys.maxOrNull() ?: 0) {
|
2019-03-21 04:25:23 +00:00
|
|
|
parsed[it]
|
|
|
|
}.toList()
|
|
|
|
}
|
|
|
|
|
2020-08-22 17:00:07 +00:00
|
|
|
override fun serialize(encoder: Encoder, value: List<HeaderIndex?>) {
|
2019-03-21 04:25:23 +00:00
|
|
|
TODO()
|
|
|
|
}
|
|
|
|
}
|