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

import java.util.List;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.modules.architecture.domain.AppMedicationIncompatibilityGroupRow;

/**
 * 移动端用药工具 — 多配伍组禁配信息展示文案。
 */
public final class AppMedicationIncompatibilityDisplaySupport
{
    private AppMedicationIncompatibilityDisplaySupport()
    {
    }

    /**
     * 将多条禁配标准格式化为：{@code 药A,药B（结果1）；药C（结果2）}。
     */
    public static String formatGroupsForDisplay(List<AppMedicationIncompatibilityGroupRow> groups)
    {
        if (groups == null || groups.isEmpty())
        {
            return null;
        }
        StringBuilder sb = new StringBuilder();
        for (AppMedicationIncompatibilityGroupRow group : groups)
        {
            if (group == null || StringUtils.isEmpty(group.getCompanionsCsv()))
            {
                continue;
            }
            if (sb.length() > 0)
            {
                sb.append('；');
            }
            sb.append(group.getCompanionsCsv().trim());
            if (StringUtils.isNotEmpty(group.getCompatResult()))
            {
                sb.append('（').append(group.getCompatResult().trim()).append('）');
            }
        }
        return sb.length() > 0 ? sb.toString() : null;
    }
}
