package aggregate

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

func AggPrevSampleText() Aggregator {
	return &PrevSampleText{}
}

type PrevSampleText struct {
	value string
}

func (a *PrevSampleText) Add(record *load.StmtRecord) {
	if a.value == "" {
		a.value = record.PrevSQL
	}
}

func (a *PrevSampleText) Merge(agg Aggregator) {
	if agg, ok := agg.(*PrevSampleText); ok {
		if a.value == "" {
			a.value = agg.value
		}
	}
}

func (a *PrevSampleText) Output(model *api.Model) {
	model.PrevSampleText = a.value
}
