package com.nestedworld.nestedworld.models;

import android.support.annotation.Nullable;

import com.google.gson.annotations.Expose;
import com.nestedworld.nestedworld.R;
import com.orm.SugarRecord;
import com.orm.query.Condition;
import com.orm.query.Select;

/**
 * Simple model for :
 * - mapping a json response with Gson anotation
 * - mapping a sql table with SugarORM
 * /!\ Keep the default constructor empty (see sugarOrm doc)
 */
public class UserMonster extends SugarRecord {

    @Expose
    public Monster infos;

    @Expose
    public Long level;

    @Expose
    public String surname;

    @Expose
    public String experience;

    //Empty constructor for SugarRecord
    public UserMonster() {
        //Keep empty
    }

    public Long fkmonster;//key for Monster<->UserMonster relationship

    @Nullable
    public Monster info() {
        if (infos == null) {
            infos = Select.from(Monster.class).where(Condition.prop("monsterid").eq(fkmonster)).first();
        }
        return infos;
    }

    //Generated
    @Override
    public String toString() {
        return "UserMonster{" +
                "infos=" + infos +
                ", level='" + level + '\'' +
                ", surname='" + surname + '\'' +
                ", experience='" + experience + '\'' +
                ", fkMonster=" + fkmonster +
                '}';
    }

    //Utils
    public int getColorResource() {
        Monster info = info();
        if (info == null) {
            return R.color.black;
        }
        return info.getColorResource();
    }
}

@@ -126,16 +126,67 @@
 Expose;%0A
+import com.google.gson.annotations.SerializedName;%0A
 import c
@@ -215,16 +215,16 @@
 orld.R;%0A
-
 import c
@@ -243,16 +243,43 @@
 Record;%0A
+import com.orm.dsl.Unique;%0A
 import c
@@ -559,16 +559,165 @@
 cord %7B%0A%0A
+    @Expose%0A    @SerializedName(%22id%22)%0A    @Unique%0A    public Long user_monster_id;// the sql table will be called usermonsterid (see sugarOrm doc)%0A%0A%0A
     @Exp
@@ -1358,16 +1358,73 @@
        %22
+user_monster_id=%22 + user_monster_id +%0A                %22, 
 infos=%22 
@@ -1458,17 +1458,16 @@
 , level=
-'
 %22 + leve
@@ -1469,23 +1469,16 @@
  level +
- '%5C'' +
 %0A       
@@ -1595,17 +1595,17 @@
    %22, fk
-M
+m
 onster=%22

update userMonsters model