package mail

import (
	"strings"
	"unicode"
)

const (
	maxIdempotencyKeyLen = 128
	minIdempotencyKeyLen = 8
)

func normalizeIdempotencyKey(raw string) (string, bool) {
	key := strings.TrimSpace(raw)
	if key == "" {
		return "", true
	}
	if len(key) < minIdempotencyKeyLen || len(key) > maxIdempotencyKeyLen {
		return "", false
	}
	for _, r := range key {
		if unicode.IsLetter(r) || unicode.IsDigit(r) || r == '-' || r == '_' {
			continue
		}
		return "", false
	}
	return key, true
}
