SauceNaoAPI/src/commonMain/kotlin/dev/inmo/saucenaoapi/additional/header/AccountInfo.kt

56 lines
1.4 KiB
Kotlin
Raw Normal View History

2020-12-02 08:39:54 +00:00
package dev.inmo.saucenaoapi.additional.header
2019-05-16 11:04:58 +00:00
2020-12-02 08:39:54 +00:00
import dev.inmo.saucenaoapi.additional.*
import dev.inmo.saucenaoapi.models.Header
2019-05-16 11:04:58 +00:00
val Header.shortLimitStatus: LimitStatus
get() = LimitStatus(
2019-08-19 08:13:43 +00:00
shortRemaining,
shortLimit
2019-05-16 11:04:58 +00:00
)
val Header.longLimitStatus: LimitStatus
get() = LimitStatus(
2019-08-19 08:13:43 +00:00
longRemaining,
longLimit
2019-05-16 11:04:58 +00:00
)
val Header.limits
get() = Limits(shortLimitStatus, longLimitStatus)
val Header.accountInfo
get() = AccountInfo(
accountType ?: defaultAccountType,
userId,
limits
)
data class LimitStatus(
val remain: Int = Int.MAX_VALUE,
val limit: Int = Int.MAX_VALUE
) : Comparable<LimitStatus> {
override fun compareTo(other: LimitStatus): Int = when {
limit == other.limit && remain == other.remain -> 0
else -> remain.compareTo(other.remain)
}
}
2019-05-16 11:04:58 +00:00
data class Limits(
val short: LimitStatus = LimitStatus(),
val long: LimitStatus = LimitStatus()
) : Comparable<Limits> {
override fun compareTo(other: Limits): Int = when {
long == other.long && short == other.short -> 0
else -> short.remain.compareTo(other.short.remain)
}
}
2019-05-16 11:04:58 +00:00
data class AccountInfo(
val accountType: AccountType = defaultAccountType,
val userId: UserId? = null,
val limits: Limits = Limits()
) : Comparable<AccountInfo> {
override fun compareTo(other: AccountInfo): Int = limits.compareTo(other.limits)
}