package testcases

import (
	"github.com/pingcap/log"
	"go.uber.org/zap"

	dmmodel "github.com/pingcap/test-infra/caselib/pkg/model/dm"
	"github.com/pingcap/test-infra/caselib/pkg/spec"
	"github.com/pingcap/test-infra/caselib/pkg/steps"
)

var (
	cases = make(map[spec.CaseName]func() steps.Step)
	Path  = &dmmodel.Path{}
	Spec  = &spec.Specification{}
)

func GetTestCase() steps.Step {
	name := Spec.CaseSpec.Name
	if step, ok := cases[name]; ok {
		log.Info("find case success", zap.String("case type", string(name)))
		return step()
	}

	log.Error("invalid case type", zap.String("case type", string(name)))
	return nil
}

func AddTestCase(name spec.CaseName, fn func() steps.Step) bool {
	_, exists := cases[name]
	if exists {
		log.Panic("case already exists", zap.Stringer("name", name))
	}
	cases[name] = fn
	return true
}
