package net.taehui.twilight.awilight

import net.taehui.twilight.JSON

class AwilightSite(
    val siteID: String,
    val isNetSite: Boolean,
    var noteID: String,
    var noteIDs: Array<String>? = null
) {
    var isSiteHand = false
    var avatarConfigure = 0
    var siteSituation = 0
    var isNetAllowed = false

    fun setAvatarConfigure(isSiteHand: Boolean, avatarConfigure: Int) {
        this.isSiteHand = isSiteHand
        this.avatarConfigure = avatarConfigure
    }

    fun setSIteSituation(siteSituation: Int) {
        this.siteSituation = siteSituation
    }

    fun setNetAllowed(data: Array<JSON.TwilightCallSiteAvatar.TwilightCallSiteAvatarItem>, avatarID: String) {
        val availableAvatars = data.filter { it.avatarID != avatarID && !it.avatarID.startsWith("@") }
        isNetAllowed =
            if (isSiteHand) availableAvatars.isNotEmpty() && availableAvatars.all { it.avatarConfigure == AVATAR_CONFIGURE_LEVYING } else avatarConfigure == AVATAR_CONFIGURE_DEFAULT
    }

    fun setSiteNetData(twilightCallSiteNet: JSON.TwilightCallSiteNet) {
        noteIDs = twilightCallSiteNet.noteIDs
        noteID = twilightCallSiteNet.noteID
    }

    companion object {
        const val AVATAR_CONFIGURE_DEFAULT = 0
        const val AVATAR_CONFIGURE_LEVYING = 2
        const val SITE_SITUATION_DEFAULT = 0
    }
}