package com.ruoyi.web.modules.diagnosis.support;

import com.ruoyi.common.utils.StringUtils;

/**
 * 会话列表最后一条消息摘要。
 */
public final class ConsultMessagePreview
{
    private ConsultMessagePreview()
    {
    }

    public static String build(Integer msgType, String content)
    {
        if (msgType == null)
        {
            return "";
        }
        if (msgType == ConsultSessionRules.MSG_TYPE_IMAGE)
        {
            return ConsultSessionRules.PREVIEW_IMAGE;
        }
        if (msgType == ConsultSessionRules.MSG_TYPE_VIDEO)
        {
            return ConsultSessionRules.PREVIEW_VIDEO;
        }
        if (msgType == ConsultSessionRules.MSG_TYPE_VOICE)
        {
            return ConsultSessionRules.PREVIEW_VOICE;
        }
        String text = StringUtils.trim(content);
        if (StringUtils.isEmpty(text))
        {
            return "";
        }
        if (text.length() <= ConsultSessionRules.PREVIEW_MAX_LEN)
        {
            return text;
        }
        return text.substring(0, ConsultSessionRules.PREVIEW_MAX_LEN);
    }
}
