package com.remax.visualnovel.entity.response

import android.os.Parcelable
import androidx.annotation.DrawableRes
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize

/**
 * Created by HJW on 2025/7/18
 */
@Parcelize
data class AIDict(
    val roleDictList: List<AIDictItem>,
    val characterDictList: List<AIDictItem>,
    val imageStyleDictList: List<AIDictItem>,
    val timbreDictList: List<AIVoice>,
) : Parcelable {

    fun setInitSelect(character: Character?) {
        val imageStyleCode = character?.aiUserExt?.imageStyleCode
        val findImageStyle = imageStyleDictList.find { character -> character.code == imageStyleCode }
        (findImageStyle ?: imageStyleDictList.firstOrNull())?.select = true

        val roleCode = character?.roleCode
        if (roleCode == null) {
            roleDictList.firstOrNull()?.childDictList?.firstOrNull()?.select = true
        } else {
            roleDictList.forEach { roleChild ->
                roleChild.childDictList?.forEach { role ->
                    role.select = role.code == roleCode
                }
            }
        }

        val characterCode = character?.characterCode
        val findCharacter = characterDictList.find { character -> character.code == characterCode }
        (findCharacter ?: characterDictList.firstOrNull())?.select = true

        val tagCode = character?.tagCode
        if (tagCode == null) {
            characterDictList.firstOrNull()?.childDictList?.firstOrNull()?.select = true
        } else {
            characterDictList.forEach { characterChild ->
                characterChild.childDictList?.forEach { tag ->
                    tag.select = tag.code == tagCode
                }
            }
        }
    }
}

@Parcelize
data class AIDictItem(
    val code: String,
    val name: String,
    val url: String?,
    val prompt: String?,
    val childDictList: List<AIDictItem>?,
    var select: Boolean = false
) : Parcelable {
    @IgnoredOnParcel
    @DrawableRes
    var filterIcon: Int? = null

    @IgnoredOnParcel
    @DrawableRes
    var selectBackgroundRes: Int? = null
}
