Add report registry and valid periods
This commit is contained in:
88
internal/report/registry.go
Normal file
88
internal/report/registry.go
Normal file
@@ -0,0 +1,88 @@
|
||||
package report
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Registry struct {
|
||||
definitions map[ID]Definition
|
||||
}
|
||||
|
||||
func DefaultRegistry() Registry {
|
||||
definitions := []Definition{
|
||||
{
|
||||
ID: DailyToday,
|
||||
Name: "Daily Report",
|
||||
PromptID: "weather.daily_report",
|
||||
ComparisonStrategy: CompareSameValidDate,
|
||||
DefaultOutputName: "daily.md",
|
||||
Morning: true,
|
||||
resolve: resolveDailyToday,
|
||||
},
|
||||
{
|
||||
ID: DailyTomorrow,
|
||||
Name: "Tomorrow Planning Brief",
|
||||
PromptID: "weather.daily_report",
|
||||
ComparisonStrategy: CompareSameValidDate,
|
||||
DefaultOutputName: "tomorrow.md",
|
||||
Evening: true,
|
||||
resolve: resolveDailyTomorrow,
|
||||
},
|
||||
{
|
||||
ID: ThreeDay,
|
||||
Name: "3-Day Outlook",
|
||||
PromptID: "weather.three_day_outlook",
|
||||
ComparisonStrategy: CompareSameValidDate,
|
||||
DefaultOutputName: "three_day.md",
|
||||
Morning: true,
|
||||
resolve: resolveThreeDay,
|
||||
},
|
||||
{
|
||||
ID: Weekend,
|
||||
Name: "Weekend Outlook",
|
||||
PromptID: "weather.weekend_outlook",
|
||||
ComparisonStrategy: CompareWeekendWindow,
|
||||
DefaultOutputName: "weekend.md",
|
||||
Morning: true,
|
||||
resolve: resolveWeekend,
|
||||
},
|
||||
{
|
||||
ID: Storm,
|
||||
Name: "Storm Report",
|
||||
PromptID: "weather.storm_report",
|
||||
ComparisonStrategy: CompareExplicitWindow,
|
||||
DefaultOutputName: "storm.md",
|
||||
resolve: resolveStorm,
|
||||
},
|
||||
}
|
||||
registry := Registry{definitions: map[ID]Definition{}}
|
||||
for _, definition := range definitions {
|
||||
registry.definitions[definition.ID] = definition
|
||||
}
|
||||
return registry
|
||||
}
|
||||
|
||||
func (r Registry) Lookup(id ID) (Definition, error) {
|
||||
definition, ok := r.definitions[id]
|
||||
if !ok {
|
||||
return Definition{}, fmt.Errorf("unknown report %q", id)
|
||||
}
|
||||
return definition, nil
|
||||
}
|
||||
|
||||
func (r Registry) MustLookup(id ID) Definition {
|
||||
definition, err := r.Lookup(id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return definition
|
||||
}
|
||||
|
||||
func (r Registry) All() []Definition {
|
||||
ids := []ID{DailyToday, DailyTomorrow, ThreeDay, Weekend, Storm}
|
||||
out := make([]Definition, 0, len(ids))
|
||||
for _, id := range ids {
|
||||
if definition, ok := r.definitions[id]; ok {
|
||||
out = append(out, definition)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in New Issue
Block a user