package aggregate

import (
	"github.com/pingcap-inc/clinic/pkg/ngm/statements/api"
	"github.com/pingcap-inc/clinic/pkg/ngm/statements/load"
)

func AggMaxRuv2() Aggregator {
	return &MaxRuv2{}
}

type MaxRuv2 struct {
	max float64
}

var _ Aggregator = (*MaxRuv2)(nil)

func (a *MaxRuv2) Add(record *load.StmtRecord) {
	if a.max < record.MaxRuv2 {
		a.max = record.MaxRuv2
	}
}

func (a *MaxRuv2) Merge(agg Aggregator) {
	if agg, ok := agg.(*MaxRuv2); ok {
		if a.max < agg.max {
			a.max = agg.max
		}
	}
}

func (a *MaxRuv2) Output(model *api.Model) {
	model.MaxRuv2 = a.max
}
