package logutil

import (
	"crypto/sha256"
	"encoding/hex"
)

// FingerprintSHA256 returns a short hex fingerprint of the input.
// Truncate to first nBytes (e.g., 4..8) for display.
func FingerprintSHA256(b []byte, nBytes int) string {
	if nBytes <= 0 {
		nBytes = 4
	}
	sum := sha256.Sum256(b)
	full := hex.EncodeToString(sum[:])
	if nBytes*2 < len(full) {
		return full[:nBytes*2]
	}
	return full
}

// PreviewString returns a safe preview of s, max characters with ellipsis.
func PreviewString(s string, max int) string {
	if max <= 0 {
		max = 24
	}
	runes := []rune(s)
	if len(runes) <= max {
		return s
	}
	return string(runes[:max-3]) + "..."
}


