package client

import "time"

func finalizeKEVReport(findings []KEVFinding) *KEVScanReport {
	r := &KEVScanReport{
		ScannedAt: time.Now().UTC().Format(time.RFC3339),
		Findings:  findings,
	}
	for _, f := range findings {
		switch f.Status {
		case "exposed":
			r.ExposedCount++
			if f.Severity == "critical" {
				r.CriticalCount++
			}
		case "likely":
			r.LikelyCount++
		}
	}
	r.RiskScore = kevRiskScore(r)
	return r
}

func kevRiskScore(r *KEVScanReport) int {
	if r == nil {
		return 0
	}
	score := r.CriticalCount*25 + r.ExposedCount*15 + r.LikelyCount*8
	if score > 100 {
		return 100
	}
	return score
}
