package aicare.net.cn.sdk.ailinksdkdemoandroid.modules.smart_cycling_table

import aicare.net.cn.sdk.ailinksdkdemoandroid.utils.L
import com.pinwang.ailinkblesdk.modules.smart_cycling_table.SatelliteBean

/**
 * 卫星豆(合计)
 * @author xing
 * @date 2025/03/08
 * @constructor 创建[SatelliteAllBean]
 */
class SatelliteAllBean {

    var type = ""
    var size = 0
    var list: MutableList<SatelliteBean> = mutableListOf()

    fun parseStr(msgs: Array<String>) {
        type = msgs[0].substring(1)
        size = msgs[3].toInt()
        val group = msgs.size - 5
        val start = 4

        //group从4开始,步进是4
        for (i in 0 until group step 4) {
            val index = i + start
            val newArray = if (index + 4 < msgs.size) {
                msgs.sliceArray(index until index + 4)
            } else {
                emptyArray() // 如果 startIndex 超出范围，返回空数组
            }
            if (newArray.isEmpty()) {
                continue
            }
            val bean = SatelliteBean().also {
                it.init(newArray)
            }
            L.i("卫星信息:$bean")
            list.add(bean)
        }
    }


    fun checkData(): Boolean {
        return list.size >= size
    }

    //复制对象
    fun copy(): SatelliteAllBean {
        return SatelliteAllBean().also {
            it.type = this.type
            it.size = this.size
            it.list = this.list.map { it.copy() }.toMutableList()
        }
    }

}