package dev.zxq5.chatapp.android.api.model

import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

@Serializable(with = TotpStatus.TotpStatusSerializer::class)
enum class TotpStatus {
    ENABLED, DISABLED;
    val isEnabled: Boolean get() = this == ENABLED


    companion object TotpStatusSerializer : KSerializer<TotpStatus> {
        override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("TotpStatus", PrimitiveKind.STRING)
        override fun serialize(encoder: Encoder, value: TotpStatus) = encoder.encodeString(value.name.lowercase())
        override fun deserialize(decoder: Decoder): TotpStatus =
            TotpStatus.valueOf(decoder.decodeString().uppercase())
    }
}

