package cn.yyxx.eyuangame.core.entity.bean.init

import cn.yyxx.support.JsonUtils
import org.json.JSONObject

/**
 * @author #Suyghur.
 * Created on 2021/06/19
 */
class FloatCfg {

    var switch = 0
    var floatIconUrl = ""
    lateinit var memberCfg: FeatureCfg
    lateinit var gifCfg: FeatureCfg
    lateinit var gmCfg: FeatureCfg
    lateinit var chargeCfg: FeatureCfg
    lateinit var inviteCfg: FeatureCfg

    override fun toString(): String {
        return "FloatCfg(switch=$switch, floatIconUrl='$floatIconUrl', memberCfg=$memberCfg, gifCfg=$gifCfg, gmCfg=$gmCfg, chargeCfg=$chargeCfg, inviteCfg=$inviteCfg)"
    }

    companion object {

        fun toBean(floatCfg: JSONObject): FloatCfg {
            val bean = FloatCfg()
            bean.memberCfg = FeatureCfg()
            bean.gifCfg = FeatureCfg()
            bean.gmCfg = FeatureCfg()
            bean.chargeCfg = FeatureCfg()
            bean.inviteCfg = FeatureCfg()
            if (JsonUtils.hasJsonKey(floatCfg, "cfg_s")) {
                bean.switch = floatCfg.getInt("cfg_s")
            }

            if (JsonUtils.hasJsonKey(floatCfg, "float_icon_line")) {
                bean.floatIconUrl = floatCfg.getString("float_icon_line")
            }

            if (JsonUtils.hasJsonKey(floatCfg, "member_cfg")) {
                bean.memberCfg = FeatureCfg.toBean(floatCfg.getJSONObject("member_cfg"))
            }

            if (JsonUtils.hasJsonKey(floatCfg, "gif_cfg")) {
                bean.gifCfg = FeatureCfg.toBean(floatCfg.getJSONObject("gif_cfg"))
            }

            if (JsonUtils.hasJsonKey(floatCfg, "gm_cfg")) {
                bean.gmCfg = FeatureCfg.toBean(floatCfg.getJSONObject("gm_cfg"))
            }

            if (JsonUtils.hasJsonKey(floatCfg, "charge_cfg")) {
                bean.chargeCfg = FeatureCfg.toBean(floatCfg.getJSONObject("charge_cfg"))
            }

            if (JsonUtils.hasJsonKey(floatCfg, "invite_cfg")) {
                bean.inviteCfg = FeatureCfg.toBean(floatCfg.getJSONObject("invite_cfg"))
            }

            return bean
        }
    }


    class FeatureCfg {
        var switch = 0
        var iconUrl = ""
        var url = ""

        override fun toString(): String {
            return "FeatureCfg(switch=$switch, iconUrl='$iconUrl', url='$url')"
        }

        companion object {
            fun toBean(cfg: JSONObject): FeatureCfg {
                val bean = FeatureCfg()
                if (JsonUtils.hasJsonKey(cfg, "cfg_s")) {
                    bean.switch = cfg.getInt("cfg_s")
                }

                if (JsonUtils.hasJsonKey(cfg, "icon_line")) {
                    bean.iconUrl = cfg.getString("icon_line")
                }

                if (JsonUtils.hasJsonKey(cfg, "line")) {
                    bean.url = cfg.getString("line")
                }
                return bean
            }
        }

    }

}