package com.rong.io.live.bean;

import android.net.Uri;
import android.text.TextUtils;

import java.io.Serializable;

import io.rong.imlib.model.UserInfo;

/**
 * 通用用户信息
 */
public class User implements Serializable {
    private String userId;
    private String userName;
    private String portrait;
    private int type;
    private String authorization;
    private String imToken;
    private String phone;

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public int getType() {
        return type;
    }

    public String getAuthorization() {
        return authorization;
    }

    public String getImToken() {
        return imToken;
    }


    public String getUserId() {
        return userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    @Deprecated
    public String getPortrait() {
        return portrait;
    }

    public String getPortraitUrl() {
        return portrait;
    }

    public Uri getPortraitUri() {
        return Uri.parse(getPortraitUrl());
    }

    public void setPortrait(String portrait) {
        this.portrait = portrait;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        User user = (User) o;
        return TextUtils.isEmpty(userId) && userId.equals(user.userId);
    }

    public UserInfo toUserInfo() {
        return new UserInfo(userId, userName, getPortraitUri());
    }

    public static User fromUserInfo(UserInfo userInfo) {
        User user = new User();
        if (null != userInfo) {
            user.userId = userInfo.getUserId();
            user.userName = userInfo.getName();
            user.portrait = userInfo.getPortraitUri().toString();
        }
        return user;
    }
}
