package com.huimv.employment.common.util;

import com.huimv.employment.common.exception.BizException;
import com.huimv.employment.common.exception.ErrorCode;

/**
 * 银行卡号校验与脱敏工具。
 */
public final class BankAccountUtils {

    private static final String BANK_ACCOUNT_PATTERN = "^\\d{16,19}$";

    private BankAccountUtils() {
    }

    public static void validate(String bankAccount) {
        if (bankAccount == null || !bankAccount.matches(BANK_ACCOUNT_PATTERN)) {
            throw new BizException(ErrorCode.BAD_REQUEST, "银行卡号格式不正确");
        }
    }

    /**
     * 示例：6222021234567890123 → 6222****0123
     */
    public static String mask(String bankAccount) {
        validate(bankAccount);
        return bankAccount.substring(0, 4) + "****" + bankAccount.substring(bankAccount.length() - 4);
    }
}
