package com.adealink.weparty.module.gift.data

import com.adealink.frame.locale.language.data.Language
import com.adealink.weparty.App
import com.google.gson.annotations.GsonNullable
import com.google.gson.annotations.SerializedName

//data class GiftCategory(
//    @SerializedName("id") val id: String,
//    @SerializedName("name") val name: String,
//    @SerializedName("icon") val icon: String,
//    @SerializedName("gifts") val gifts: List<GiftInfo>,
//)

data class GiftInfo(
    @SerializedName("id") val id: String,
    @SerializedName("value") val price: Float, //礼物价值
    @SerializedName("resId") val resId: String, //资源ID

    @GsonNullable
    @SerializedName("resource") var resource: GiftResource? = null
)

fun GiftInfo?.areContentSame(other: GiftInfo?): Boolean {
    if (this == null || other == null) {
        return false
    }
    return id == other.id
            && price == other.price
            && resId == other.resId
}

data class GiftResource(
    @SerializedName("id") val id: String,
    @SerializedName("name") val name: String,
    @SerializedName("icon") val icon: String,
    @GsonNullable
    @SerializedName("names") val names: GiftNames?
) {
    fun getDisplayName(language: Language = App.instance.languageManager.getLanguage()): String? {
        return when (language) {
            Language.EN -> {
                names?.en?.ifEmpty { name } ?: name
            }

            Language.ZH -> {
                names?.zh?.ifEmpty { name } ?: name
            }

            else -> {
                names?.id?.ifEmpty { name } ?: name
            }
        }
    }
}

data class GiftNames(
    @GsonNullable
    @SerializedName("id") val id: String?,
    @GsonNullable
    @SerializedName("zh") val zh: String?,
    @GsonNullable
    @SerializedName("en") val en: String?,
)