package com.nestedworld.nestedworld.network.socket.models.message.combat;

import com.nestedworld.nestedworld.models.Combat;
import com.nestedworld.nestedworld.network.socket.models.message.DefaultMessage;

import org.msgpack.value.Value;
import org.msgpack.value.ValueFactory;

import java.util.Map;

public class AvailableMessage implements DefaultMessage {

    String type;
    String id;
    String origin;
    Integer monsterId;
    String opponentName;

    @Override
    public void unSerialise(Map<Value, Value> message) {
        Combat combat = new Combat();

        if (message.containsKey(ValueFactory.newString("type"))) {
            type = combat.type = message.get(ValueFactory.newString("type")).asStringValue().asString();
        }
        if (message.containsKey(ValueFactory.newString("id"))) {
            id = combat.message_id = message.get(ValueFactory.newString("id")).asStringValue().asString();
        }
        if (message.containsKey(ValueFactory.newString("origin"))) {
            origin = combat.origin = message.get(ValueFactory.newString("origin")).asStringValue().asString();
        }
        if (message.containsKey(ValueFactory.newString("monsterId"))) {
            monsterId = combat.monsterId = message.get(ValueFactory.newString("monsterId")).asIntegerValue().asInt();
        }
        if (message.containsKey(ValueFactory.newString("user"))) {
            Map<Value, Value> userInfo = message.get(ValueFactory.newString("user")).asMapValue().map();
            opponentName = combat.opponent_pseudo = userInfo.get(ValueFactory.newString("pseudo")).asStringValue().asString();
        }
        combat.save();
    }
}

@@ -1177,25 +1177,26 @@
 ing(%22monster
-I
+_i
 d%22))) %7B%0A    
@@ -1277,17 +1277,18 @@
 %22monster
-I
+_i
 d%22)).asI

fix AvailableMessage parsing