package com.yutou.biliapi.bean.websocket.live;

import com.alibaba.fastjson2.JSONObject;
import com.yutou.common.utils.Log;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;

/**
 * 连续弹幕消息
 * <a href="https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/live/message_stream.md#%E8%BF%9E%E7%BB%AD%E5%BC%B9%E5%B9%95%E6%B6%88%E6%81%AF">连续弹幕消息</a>
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class WSDmInteraction extends WSData{
    public final static int TYPE_ZAN=106;//点赞
    public final static int TYPE_SHARE=105;//分享
    public final static int TYPE_DANMU=102;//弹幕
    private ComboData combo;
    private int type;

    public static void main(String[] args) {
        JSONObject json=JSONObject.parseObject("{\"cmd\":\"DM_INTERACTION\",\"data\":{\"data\":\"{\\\"fade_duration\\\":10000,\\\"cnt\\\":5,\\\"card_appear_interval\\\":0,\\\"suffix_text\\\":\\\"人正在点赞\\\",\\\"reset_cnt\\\":1,\\\"display_flag\\\":1}\",\"dmscore\":36,\"id\":53793047788032,\"status\":4,\"type\":106}}");
        WSDmInteraction wsDmInteraction=new WSDmInteraction(json);
        Log.i(wsDmInteraction);
    }
    public WSDmInteraction(JSONObject json) {
        super(json);
        JSONObject data=json.getJSONObject("data");
        JSONObject comboJson=JSONObject.parseObject(data.getString("data"));
        combo=JSONObject.parseObject(data.getString("data"), ComboData.class);
        type=data.getIntValue("type");
        if(type==106){
            combo.setContent(comboJson.getString("suffix_text"));
        }
    }

    @Data
    public static class ComboData implements Serializable {
        String content;
        String guide;
        int cnt;
    }

    @Override
    public String toString() {
        return "WSDmInteraction{" +
                "combo=" + combo +
                ", cmd='" + cmd + '\'' +
                ", jsonSrc='" + jsonSrc + '\'' +
                ", ws_timer=" + ws_timer +
                '}';
    }
}
