package com.sheep.gamegroup.model.util;

import android.text.TextUtils;

import com.alibaba.fastjson.JSONObject;
import com.sheep.gamegroup.model.entity.Ext;
import com.sheep.gamegroup.model.entity.LoginEntity;
import com.sheep.gamegroup.model.entity.UserEntity;
import com.sheep.gamegroup.util.DeviceUtil;
import com.sheep.jiuyan.samllsheep.SheepApp;

public final class EntityUtils {

    private EntityUtils() {}


    public static Ext getExtInfo(String ext){
        Ext extInfo;
        try {
            extInfo = JSONObject.parseObject(ext, Ext.class);
        } catch (Exception e) {
            e.printStackTrace();
            extInfo = JSONObject.parseObject(JSONObject.toJSONString(ext), Ext.class);
        }
        return extInfo;
    }

    public static String getUserCode(Object object) {
        if(object instanceof LoginEntity){
            LoginEntity loginEty = (LoginEntity) object;
            if(loginEty.getUser()!= null && loginEty.getUser().isNewRegistUser() ){
                return getUserCode(loginEty.getUser());
            }
        } else if(object instanceof UserEntity){
            if(!TextUtils.isEmpty(((UserEntity) object).getInvitation_code()))
                return ((UserEntity) object).getInvitation_code();
        }
        return DeviceUtil.getDeviceId(SheepApp.getInstance());
    }
}
