package com.ywt.alipaympapi.core.utils;

import com.ywt.alipaympapi.models.Constants;
import com.ywt.alipaympapi.models.enums.TerminalEnum;

/**
 * @author Walker
 * Created on 2022/9/14
 */
public final class BizUtil {
    /**
     * 根据当前终端获取所在医院 id
     *
     * @return 医院 id
     */
    public static int getCurrentHospitalId() {
        switch (TerminalEnum.valueOf(ContextHelper.getCurrentTerminalWrapped())) {
            case NFYYBYFY_ALIPAY_MP:
            case NFYYBYFY_WXAPP:
                return Constants.HOSPITAL_ID_NFYYBYFY;
            default:
                return 0;
        }
    }


    /**
     * 字符串脱敏，指定保留前后 resBit 位明文显示，剩余字符串以`*`号显示。若字符串长度小于等于 2*resBit，则全部明文显示
     *
     * @param s 待处理字符串
     * @return 处理后的字符串
     */
    public static String masked(String s, int resBit) {
        if (s == null) return "";
        if (s.length() <= 2 * resBit) return s;
        int maskedBitLen = s.length() - 2 * resBit;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < maskedBitLen; i++) {
            sb.append("*");
        }
        return s.substring(0, resBit) + sb.toString() + s.substring(s.length() - resBit);
    }

    public static String masked(String s) {
        return masked(s, 3);
    }
}
