package com.nestedworld.nestedworld.models;

import android.support.annotation.Nullable;

import com.google.gson.annotations.Expose;
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 String 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() {
        return Select.from(Monster.class).where(Condition.prop("monsterid").eq(fkmonster)).first();
    }

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

@@ -126,16 +126,54 @@
 Expose;%0A
+import com.nestedworld.nestedworld.R;%0A
 import c
@@ -192,16 +192,16 @@
 Record;%0A
-
 import c
@@ -543,20 +543,18 @@
  public 
-Stri
+Lo
 ng level
@@ -856,22 +856,56 @@
         
-return
+if (infos == null) %7B%0A            infos =
  Select.
@@ -982,16 +982,48 @@
 irst();%0A
+        %7D%0A        return infos;%0A
     %7D%0A%0A 
@@ -1343,16 +1343,16 @@
 nster +%0A
-
         
@@ -1369,11 +1369,209 @@
 ';%0A    %7D
+%0A%0A    //Utils%0A    public int getColorResource() %7B%0A        Monster info = info();%0A        if (info == null) %7B%0A            return R.color.black;%0A        %7D%0A        return info.getColorResource();%0A    %7D
 %0A%7D%0A

update model / add getColorResource()