package filter

import (
	pfilter "gitlab.alibaba-inc.com/pai_biz_arch/pairec/filter"
	"errors"
	"gitlab.alibaba-inc.com/pai_biz_arch/pairec/module"
)

// remove duplicate item
type DurationFilter struct {
}

func NewDurationFilter() *DurationFilter {
	filter := DurationFilter{}

	return &filter
}
func (f *DurationFilter) Filter(filterData *pfilter.FilterData) error {
	if _, ok := filterData.Data.([]*module.Item); !ok {
		return errors.New("filter data type error")

	}
	return f.doFilter(filterData)
}

func (f *DurationFilter) doFilter(filterData *pfilter.FilterData) error {
	items := filterData.Data.([]*module.Item)
	newItems := make([]*module.Item, 0)
	for _, item := range items{
		if item.Properties["total_time"].(int) > 120 {
			newItems = append(newItems, item)
		}
	}

	filterData.Data = newItems
	return nil
}
func (f *DurationFilter) MatchTag(tag string) bool {
	// default filter, so filter all tag
	return true
}
