diff --git a/scenarios/scenarios.go b/scenarios/scenarios.go index caf5d4aa..f4796223 100644 --- a/scenarios/scenarios.go +++ b/scenarios/scenarios.go @@ -4,6 +4,7 @@ import ( "embed" "errors" "log/slog" + "sort" "gopkg.in/yaml.v2" ) @@ -11,6 +12,14 @@ import ( //go:embed scenarios.yaml var config embed.FS +type Scenario struct { + ID string `yaml:"id"` + Name string `yaml:"name"` + Description string `yaml:"description"` + Category string `yaml:"category"` + Difficulty string `yaml:"difficulty"` +} + func List() ([]Scenario, error) { var scenarios []Scenario @@ -26,6 +35,20 @@ func List() ([]Scenario, error) { return nil, errors.Join(errors.New("failed to list scenarios"), err) } + sort.Slice(scenarios, func(i, j int) bool { + iDifficulty := scenarios[i].Difficulty + jDifficulty := scenarios[j].Difficulty + + switch iDifficulty { + case "Complex": + return jDifficulty != "Complex" + case "Medium": + return jDifficulty == "Easy" + default: + return false + } + }) + return scenarios, nil } @@ -45,11 +68,3 @@ func Find(scenarioID string) (Scenario, error) { return scenario, errors.New("unable to find scenario") } - -type Scenario struct { - ID string `yaml:"id"` - Name string `yaml:"name"` - Description string `yaml:"description"` - Category string `yaml:"category"` - Difficulty string `yaml:"difficulty"` -}