package com.daya.live_teaching.im.message;

import android.os.Parcel;

import com.cooleshow.base.utils.LogUtils;
import com.daya.live_teaching.utils.log.SLog;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;

import io.rong.imlib.MessageTag;
import io.rong.imlib.model.MessageContent;

/**
 * 伴奏下载消息
 */
@MessageTag(value = "DY:examSongDownloadMessage", flag = MessageTag.NONE)
public class ExamSongDownloadMessage extends MessageContent {
    private final static String TAG = ExamSongDownloadMessage.class.getSimpleName();


    private String examSongName;
    private String examSongId;
    private String url;

    public ExamSongDownloadMessage(byte[] data) {
        String jsonStr = null;
        try {
            jsonStr = new String(data, "UTF-8");
            LogUtils.e(jsonStr);
        } catch (UnsupportedEncodingException e) {
            SLog.e(TAG, e.toString());
        }
        try {
            JSONObject jsonObject = new JSONObject(jsonStr);
            examSongName = jsonObject.optString("examSongName");
            examSongId = jsonObject.optString("examSongId");
            url = jsonObject.optString("url");
        } catch (JSONException e) {
            SLog.e(TAG, e.toString());
        }
    }

    public ExamSongDownloadMessage(Parcel parcel) {

        examSongName = parcel.readString();
        examSongId = parcel.readString();
        url = parcel.readString();
    }


    public String getExamSongName() {
        return examSongName;
    }

    public String getExamSongId() {
        return examSongId;
    }

    public String getUrl() {
        return url;
    }

    @Override
    public byte[] encode() {
        return new byte[0];
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {

        dest.writeString(examSongName);
        dest.writeString(examSongId);
        dest.writeString(url);
    }

    public static final Creator<ExamSongDownloadMessage> CREATOR = new Creator<ExamSongDownloadMessage>() {
        @Override
        public ExamSongDownloadMessage createFromParcel(Parcel source) {
            return new ExamSongDownloadMessage(source);
        }

        @Override
        public ExamSongDownloadMessage[] newArray(int size) {
            return new ExamSongDownloadMessage[size];
        }
    };
}
