// Path: app/src/main/java/com/raffler/app/utils/Util.java
// public static Date getDateFromData(String key, Map<String, Object> data){
//     Date date = new Date();
//     String strDate = null;
//     long timeSince1970 = System.currentTimeMillis();
//     try{
//         timeSince1970 = (long) data.get(key);
//         date = new Date(timeSince1970);
//     }catch (Exception e){
//         e.printStackTrace();
//     }
// 
//     if (date == null) date = new Date();
// 
//     return date;
// }
// 
// Path: app/src/main/java/com/raffler/app/utils/Util.java
// public static int getIntFromData(String key, Map<String, Object> data){
//     Integer value = 0;
//     try{
//         String strValue = data.get(key).toString();
//         value = Integer.parseInt(strValue);
//     }catch (Exception e){
//         e.printStackTrace();
//     }
//     if(value == null) value = 0;
//     return value;
// }
// 
// Path: app/src/main/java/com/raffler/app/utils/Util.java
// public static Map<String, Object> getMapDataFromData(String key, Map<String, Object> data){
//     Map<String, Object> value = new HashMap<>();
//     try{
//         value = (Map<String, Object>) data.get(key);
//     }catch (Exception e){
//         e.printStackTrace();
//     }
//     if (value == null) value = new HashMap<>();
//     return  value;
// }
// 
// Path: app/src/main/java/com/raffler/app/utils/Util.java
// public static String getStringFromData(String key, Map<String, Object> data){
//     String value = "?";
//     try{
//         value = (String) data.get(key);
//     }catch (Exception e){
//         e.printStackTrace();
//     }
//     return  value;
// }


import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import static com.raffler.app.models.UserAction.IDLE;
import static com.raffler.app.models.UserStatus.OFFLINE;
import static com.raffler.app.utils.Util.getDateFromData;
import static com.raffler.app.utils.Util.getIntFromData;
import static com.raffler.app.utils.Util.getMapDataFromData;
import static com.raffler.app.utils.Util.getStringFromData;
package com.raffler.app.models;



/**
 * Created by Ghost on 15/8/2017.
 */

public class User {

    private String idx, name, photo, phone, bio, pushToken;
    private UserStatus userStatus = OFFLINE;
    private UserAction userAction = IDLE;
    private Date lastOnlinedAt, lastUpdatedAt;
    private Map<String,Object> chats = new HashMap<>();
    private Map<String,Object> lastseens = new HashMap<>();
    private Map<String,Object> raffles = new HashMap<>();
    private int raffle_point = 0;

    public User(Map<String, Object> data){
        updateData(data);
    }

    public void updateData(Map<String, Object> data){
        this.idx = getStringFromData("uid", data);
        this.name = getStringFromData("name", data);
        this.photo = getStringFromData("photo", data);
        this.phone = getStringFromData("phone", data);
        this.bio = getStringFromData("bio", data);
        this.pushToken = getStringFromData("pushToken", data);
        this.userStatus = UserStatus.values()[getIntFromData("userStatus", data)];
        this.userAction = UserAction.values()[getIntFromData("userAction", data)];
        this.lastOnlinedAt = getDateFromData("lastOnlinedAt", data);
        this.lastUpdatedAt = getDateFromData("lastUpdatedAt", data);
        this.chats = getMapDataFromData("chats", data);
        this.lastseens = getMapDataFromData("lastSeen", data);
// Path: app/src/main/java/com/raffler/app/utils/Util.java
// public static Date getDateFromData(String key, Map<String, Object> data){
//     Date date = new Date();
//     String strDate = null;
//     long timeSince1970 = System.currentTimeMillis();
//     try{
//         timeSince1970 = (long) data.get(key);
//         date = new Date(timeSince1970);
//     }catch (Exception e){
//         e.printStackTrace();
//     }
// 
//     if (date == null) date = new Date();
// 
//     return date;
// }
// 
// Path: app/src/main/java/com/raffler/app/utils/Util.java
// public static int getIntFromData(String key, Map<String, Object> data){
//     Integer value = 0;
//     try{
//         String strValue = data.get(key).toString();
//         value = Integer.parseInt(strValue);
//     }catch (Exception e){
//         e.printStackTrace();
//     }
//     if(value == null) value = 0;
//     return value;
// }
// 
// Path: app/src/main/java/com/raffler/app/utils/Util.java
// public static Map<String, Object> getMapDataFromData(String key, Map<String, Object> data){
//     Map<String, Object> value = new HashMap<>();
//     try{
//         value = (Map<String, Object>) data.get(key);
//     }catch (Exception e){
//         e.printStackTrace();
//     }
//     if (value == null) value = new HashMap<>();
//     return  value;
// }
// 
// Path: app/src/main/java/com/raffler/app/utils/Util.java
// public static String getStringFromData(String key, Map<String, Object> data){
//     String value = "?";
//     try{
//         value = (String) data.get(key);
//     }catch (Exception e){
//         e.printStackTrace();
//     }
//     return  value;
// }


// Path: app/src/main/java/com/raffler/app/models/User.java
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import static com.raffler.app.models.UserAction.IDLE;
import static com.raffler.app.models.UserStatus.OFFLINE;
import static com.raffler.app.utils.Util.getDateFromData;
import static com.raffler.app.utils.Util.getIntFromData;
import static com.raffler.app.utils.Util.getMapDataFromData;
import static com.raffler.app.utils.Util.getStringFromData;

package com.raffler.app.models;



/**
 * Created by Ghost on 15/8/2017.
 */

public class User {

    private String idx, name, photo, phone, bio, pushToken;
    private UserStatus userStatus = OFFLINE;
    private UserAction userAction = IDLE;
    private Date lastOnlinedAt, lastUpdatedAt;
    private Map<String,Object> chats = new HashMap<>();
    private Map<String,Object> lastseens = new HashMap<>();
    private Map<String,Object> raffles = new HashMap<>();
    private int raffle_point = 0;

    public User(Map<String, Object> data){
        updateData(data);
    }

    public void updateData(Map<String, Object> data){
        this.idx = getStringFromData("uid", data);
        this.name = getStringFromData("name", data);
        this.photo = getStringFromData("photo", data);
        this.phone = getStringFromData("phone", data);
        this.bio = getStringFromData("bio", data);
        this.pushToken = getStringFromData("pushToken", data);
        this.userStatus = UserStatus.values()[getIntFromData("userStatus", data)];
        this.userAction = UserAction.values()[getIntFromData("userAction", data)];
        this.lastOnlinedAt = getDateFromData("lastOnlinedAt", data);
        this.lastUpdatedAt = getDateFromData("lastUpdatedAt", data);
        this.chats = getMapDataFromData("chats", data);
        this.lastseens = getMapDataFromData("lastSeen", data);
        this.raffles = getMapDataFromData("raffles", data);