package schedulers

import (
	"context"
	"sort"

	"github.com/pingcap/test-infra/services/tps/pkg/common"
)

type Sorter struct {
}

func (s *Sorter) Name() string {
	return "Sorter"
}

func (s *Sorter) Filter(ctx context.Context, jobs []*common.ArgoJob) (result []*common.ArgoJob, err error) {
	// sort by case count
	sort.SliceStable(jobs, func(i, j int) bool {
		return len(jobs[i].Plan.Pipeline) > len(jobs[j].Plan.Pipeline)
	})
	return jobs, nil
}
