package core

// GoldenDiff compares two byte slices and returns a similarity score in [0,1].
// similarity = matchedBytes / max(len(actual), len(golden)).
// matched = similarity >= (1.0 - threshold).
// threshold=0.0 requires exact match; threshold=0.05 tolerates up to 5% divergence.
// Returns similarity=1.0 and matched=true when both slices are empty.
func GoldenDiff(actual, golden []byte, threshold float64) (matched bool, similarity float64) {
	maxLen := len(actual)
	if len(golden) > maxLen {
		maxLen = len(golden)
	}
	if maxLen == 0 {
		return true, 1.0
	}

	minLen := len(actual)
	if len(golden) < minLen {
		minLen = len(golden)
	}

	var matchedBytes int
	for i := 0; i < minLen; i++ {
		if actual[i] == golden[i] {
			matchedBytes++
		}
	}

	similarity = float64(matchedBytes) / float64(maxLen)
	matched = similarity >= (1.0 - threshold)
	return matched, similarity
}
