package com.codechecker.common;

/**
 * 企微 Markdown v1 公共样式（类变更 / API 变更通知共用）。
 */
public final class MarkdownStyles {
    private MarkdownStyles() {
    }

    public static String colorInfo(String text) {
        return "<font color=\"info\">" + text + "</font>";
    }

    public static String colorComment(String text) {
        return "<font color=\"comment\">" + safe(text) + "</font>";
    }

    public static String colorWarning(String text) {
        return "<font color=\"warning\">" + text + "</font>";
    }

    public static String quoteKvBold(String key, String value) {
        return "> **" + key + ":  " + value + "**";
    }

    public static String quoteKv(String key, String value) {
        return "> " + key + ":  " + value;
    }

    public static String quoteLine(String content) {
        return "> " + content;
    }

    public static String inlineCode(String text) {
        return "`" + text.replace("`", "'") + "`";
    }

    /** 类型展示：泛型尖括号不转义 */
    public static String formatTypeChange(String detail) {
        int arrow = detail.indexOf(" → ");
        if (arrow < 0) {
            return colorWarning(detail);
        }
        String oldType = detail.substring(0, arrow).trim();
        String newType = detail.substring(arrow + 3).trim();
        return colorWarning(oldType) + " → " + colorInfo(newType);
    }

    public static String formatSingleType(String type, boolean isNew) {
        if (type == null || type.isBlank()) {
            return "";
        }
        return isNew ? colorInfo(type) : colorWarning(type);
    }

    public static String safe(String text) {
        if (text == null) {
            return "";
        }
        return text.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
    }
}
