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:musicScoreDownloadMessage", flag = MessageTag.NONE)
public class MusicScoreDownloadMessage extends MessageContent {
    private final static String TAG = MusicScoreDownloadMessage.class.getSimpleName();

    private String id;
    private String examSongId;
    private String mp3Url;
    private String url;

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

    public MusicScoreDownloadMessage(Parcel parcel) {
        id = parcel.readString();
        examSongId = parcel.readString();
        mp3Url = parcel.readString();
        url = parcel.readString();
    }

    public String getId() {
        return id;
    }

    public String getExamSongId() {
        return examSongId;
    }

    public String getMp3Url() {
        return mp3Url;
    }

    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(id);
        dest.writeString(examSongId);
        dest.writeString(mp3Url);
        dest.writeString(url);

    }

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

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