package com.jeesharp.business.modules.member.application.support;

import cn.hutool.core.util.StrUtil;

/**
 * 会员码展示与二维码内容组装辅助类。
 *
 * @author jeesharp
 * @since 2026-06-25
 */
public final class MemberCodeSupport {

    public static final String QRCODE_PREFIX = "MKM";

    private MemberCodeSupport() {
    }

    public static String buildQrcodeContent(String memberNo) {
        return QRCODE_PREFIX + "|" + StrUtil.trim(memberNo);
    }

    public static String formatDisplayNo(String memberNo) {
        if (StrUtil.isBlank(memberNo)) {
            return "";
        }
        String digits = memberNo.trim();
        if (digits.length() <= 4) {
            return digits;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < digits.length(); i += 4) {
            if (!sb.isEmpty()) {
                sb.append(' ');
            }
            sb.append(digits, i, Math.min(i + 4, digits.length()));
        }
        return sb.toString();
    }
}
