package ted import "strings" type valuedAmount struct { value float64 currency string } // aggregateSameCurrencyAmounts sums values only when every non-empty currency matches. // Lots with an empty currency are included; conflicting currencies yield zero. func aggregateSameCurrencyAmounts(amounts []valuedAmount) (total float64, currency string) { var refCurrency string for _, item := range amounts { if item.value <= 0 { continue } c := strings.TrimSpace(item.currency) if c == "" { continue } if refCurrency == "" { refCurrency = c continue } if c != refCurrency { return 0, "" } } for _, item := range amounts { if item.value <= 0 { continue } total += item.value } if total <= 0 { return 0, "" } return total, refCurrency }