package com.rong.io.live.helper;

import android.text.TextUtils;

import com.rong.io.live.message.RCChatJoinRoomMessage;
import com.rong.io.live.message.RCOnSnappingUpMessage;

import io.rong.imlib.model.MessageContent;
import io.rong.imlib.model.UserInfo;

/**
 * Author by pq, Date on 2022/6/20.
 */
public class LiveMemberHelper {
    public static final int MAX_COUNT_UNIT =10000;
    public static String getMessageName(MessageContent messageContent) {
        String name = "";
        UserInfo userInfo = messageContent.getUserInfo();
        if (userInfo != null) {
            name = userInfo.getName();
        }
        if (TextUtils.isEmpty(name)) {
            if (messageContent instanceof RCChatJoinRoomMessage) {
                RCChatJoinRoomMessage joinRoomMessage = (RCChatJoinRoomMessage) messageContent;
                name = joinRoomMessage.getUserName();
            }
            if (messageContent instanceof RCOnSnappingUpMessage) {
                RCOnSnappingUpMessage onSnappingUpMessage = (RCOnSnappingUpMessage) messageContent;
                name = onSnappingUpMessage.getUserName();
            }
        }
        if (TextUtils.isEmpty(name)) {
            name = "用户";
        }
        return name;
    }

    public static String getMemberCountText(int memberCount) {
        try {
            if (memberCount >= MAX_COUNT_UNIT) {
                int result = memberCount / MAX_COUNT_UNIT;
                return result + "万+";
            }
            return String.valueOf(memberCount);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return String.valueOf(memberCount);
    }

    public static String getMemberCountText(String memberCount) {
        try {
            int count = Integer.parseInt(memberCount);
            if (count >= MAX_COUNT_UNIT) {
                int result = count / MAX_COUNT_UNIT;
                return result + "万+";
            }
            return memberCount;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return memberCount;
    }

    /**
     * 获取点赞数
     *
     * @param count
     * @return
     */
    public static String getStarsCountText(int count) {
        try {
            if (count >= MAX_COUNT_UNIT) {
                int result = count / MAX_COUNT_UNIT;
                return result + "万+";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return String.valueOf(count);
    }
}
