package rollout

// ShadowResult summarizes a shadow/mirror run: how many mirrored requests
// produced a response that DIFFERED from the old path. Shadowing sends
// production-shaped traffic at the new path and discards/diffs the
// response — zero user risk, production-fidelity validation.
type ShadowResult struct {
	Total int
	Diffs int
}

// DiffRate is the fraction of mirrored requests whose new-path response
// differed from the old path.
func (r ShadowResult) DiffRate() float64 {
	if r.Total == 0 {
		return 0
	}
	return float64(r.Diffs) / float64(r.Total)
}

// Shadow runs `n` requests through both the old and new paths and counts
// responses that differ. The user is ALWAYS served by oldFn; newFn's
// output is only compared, never returned — so a bug in newFn cannot
// affect a user. This is the cheapest, safest pre-canary validation.
func Shadow(n int, oldFn, newFn func(i int) string) ShadowResult {
	res := ShadowResult{Total: n}
	for i := 0; i < n; i++ {
		if oldFn(i) != newFn(i) {
			res.Diffs++
		}
	}
	return res
}
