package org.cnodejs.android.md.model.entity;

import android.support.annotation.NonNull;

import com.google.gson.annotations.SerializedName;

import org.joda.time.DateTime;

public class Message {

    public enum Type {
        reply,
        at
    }

    private String id;

    private Type type;

    @SerializedName("has_read")
    private boolean read;

    private Author author;

    private TopicSimple topic; // 这里不含Author字段，注意

    private Reply reply; // 这里不含Author字段，注意

    @SerializedName("create_at")
    private DateTime createAt; // TODO 这个字段目前不存在，需要服务端补全

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @NonNull
    public Type getType() {
        return type == null ? Type.reply : type; // 保证返回不为空
    }

    public void setType(Type type) {
        this.type = type;
    }

    public boolean isRead() {
        return read;
    }

    public void setRead(boolean read) {
        this.read = read;
    }

    public Author getAuthor() {
        return author;
    }

    public void setAuthor(Author author) {
        this.author = author;
    }

    public TopicSimple getTopic() {
        return topic;
    }

    public void setTopic(TopicSimple topic) {
        this.topic = topic;
    }

    public Reply getReply() {
        return reply;
    }

    public void setReply(Reply reply) {
        this.reply = reply;
    }

    public DateTime getCreateAt() { // TODO 这里做兼容处理
        //return createAt;
        if (createAt != null) {
            return createAt;
        } else if (getReply() != null && getReply().getCreateAt() != null) {
            return getReply().getCreateAt();
        } else {
            return getTopic().getLastReplyAt();
        }
    }

    public void setCreateAt(DateTime createAt) {
        this.createAt = createAt;
    }

}

@@ -545,34 +545,8 @@
 eAt;
- // TODO %E8%BF%99%E4%B8%AA%E5%AD%97%E6%AE%B5%E7%9B%AE%E5%89%8D%E4%B8%8D%E5%AD%98%E5%9C%A8%EF%BC%8C%E9%9C%80%E8%A6%81%E6%9C%8D%E5%8A%A1%E7%AB%AF%E8%A1%A5%E5%85%A8
 %0A%0A  
@@ -1431,24 +1431,8 @@
 () %7B
- // TODO %E8%BF%99%E9%87%8C%E5%81%9A%E5%85%BC%E5%AE%B9%E5%A4%84%E7%90%86
 %0A   
@@ -1436,18 +1436,16 @@
         
-//
 return c
@@ -1457,266 +1457,8 @@
 At;%0A
-        if (createAt != null) %7B%0A            return createAt;%0A        %7D else if (getReply() != null && getReply().getCreateAt() != null) %7B%0A            return getReply().getCreateAt();%0A        %7D else %7B%0A            return getTopic().getLastReplyAt();%0A        %7D%0A
     

修复Message结构中create_at字段的兼容问题