package pro.beam.api.resource.chat.events.data;

import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.Iterators;
import com.google.gson.annotations.SerializedName;
import pro.beam.api.resource.chat.AbstractChatEvent;

import java.util.List;

public class IncomingMessageData extends AbstractChatEvent.EventData {
    public int channel;
    public String id;
    public String user_name;
    public String user_id;
    public String user_role;
    public List<MessagePart> message;

    public String getMessage() {
        return Joiner.on(' ').join(Iterators.transform(this.message.iterator(), new Function<MessagePart, String>() {
            @Override public String apply(MessagePart part) {
                return part.type == MessagePart.Type.TEXT ? part.data: part.url;
            }
        }));
    }

    public static class MessagePart {
        public Type type;
        public String url;
        public String data;
        public String path;

        public static enum Type {
            @SerializedName("text") TEXT,
            @SerializedName("emoticon") EMOTICON,
            @SerializedName("link") LINK;
        }
    }
}

@@ -767,72 +767,296 @@
     
-return part.type == MessagePart.Type.TEXT ? part.data: part.url;
+switch(part.type) %7B%0A                    case EMOTICON:%0A                        return part.path;%0A                    case LINK:%0A                        return part.url;%0A                    case TEXT:%0A                    default:%0A                        return part.data;%0A                %7D
 %0A   
@@ -1400,17 +1400,17 @@
 k%22) LINK
-;
+,
 %0A       

Fix incorrect property access when chaining iterators in IncomingMessageData