package cn.muchinfo.rma.business.quote.models

import java.nio.ByteBuffer
import java.nio.ByteOrder

/**
 * 行情订阅请求包数据体模型类
 * @property accountID Int 账户编号，8 Byte
 * @property token String 登录令牌，64 Byte
 * @property count Int 4 Byte，有符号
 * @property quoteSubscriptGoodsInfo List<MoQuoteSubscriptGoodsInfo> 行情订阅请求包商品信息数组
 * @constructor
 */
class MoQuotaSubscriptReq(
    var accountID: Long = 0,
    var token: String = "",
    var count: Int = 0,
    var quoteSubscriptGoodsInfo: List<MoQuoteSubscriptGoodsInfo> = ArrayList<MoQuoteSubscriptGoodsInfo>()
) {
    /**
     * 获取订阅请求对象二进制流的方法
     * @return ByteArray 订阅请求对象二进制流
     */
    fun getData(): ByteArray {
        var data = byteArrayOf()

        // accountID
        data += ByteBuffer.allocate(8).order(ByteOrder.BIG_ENDIAN).putLong(accountID).array()
        // Token, 不足64 byte需要补足
        val tmp = token.toByteArray()
        data += tmp
        val size = 64 - tmp.size
        for (i in 1..size) {
            data += 0
        }
        // count
        data += ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN).putInt(count).array()
        // 订阅商品信息
        for (item in quoteSubscriptGoodsInfo) {
            data += item.getData()
        }

        return data
    }
}