package monetix

import "strings"

// MaskPAN redacts a primary account number by keeping the first 6 and last 4 digits.
func MaskPAN(pan string) string {
	p := strings.TrimSpace(pan)
	if len(p) <= 4 {
		return strings.Repeat("*", len(p))
	}

	if len(p) <= 10 {
		return p[:2] + strings.Repeat("*", len(p)-4) + p[len(p)-2:]
	}

	maskLen := len(p) - 10
	if maskLen < 0 {
		maskLen = 0
	}
	return p[:6] + strings.Repeat("*", maskLen) + p[len(p)-4:]
}
