package briefing import ( "time" "gitea.maximumdirect.net/eric/weatherreporter/internal/module" "gitea.maximumdirect.net/eric/weatherreporter/internal/report" "gitea.maximumdirect.net/eric/weatherreporter/internal/timeutil" "gitea.maximumdirect.net/eric/weatherreporter/internal/weatherdata" ) type MetadataModule struct { RunID string `json:"run_id"` ReportID report.ID `json:"report_id"` Variant string `json:"variant,omitempty"` PromptID string `json:"prompt_id"` GeneratedAt time.Time `json:"generated_at"` Units string `json:"units"` Timezone string `json:"timezone"` ValidPeriod timeutil.Period `json:"valid_period"` Location *LocationContext `json:"location,omitempty"` SourceWarnings []SourceWarningSummary `json:"source_warnings,omitempty"` Alerts *AlertDigestModule `json:"alerts,omitempty"` } type SourceWarningSummary struct { Source string `json:"source"` Code string `json:"code"` Severity string `json:"severity"` Message string `json:"message"` CompletenessImpact string `json:"completeness_impact,omitempty"` } func buildMetadataModule(ctx ModuleContext, _ any) (*module.Output, error) { metadata := ctx.Resolved.Metadata() value := MetadataModule{ RunID: metadata.RunID, ReportID: metadata.ReportID, Variant: variantForReport(metadata.ReportID), PromptID: metadata.PromptID, GeneratedAt: metadata.GeneratedAt, Units: ctx.Units, Timezone: ctx.Timezone, ValidPeriod: metadata.ValidPeriod, Location: copyLocation(ctx.Location), SourceWarnings: sourceWarningSummaries(ctx.Collected.SourceWarnings), Alerts: alertDigest(ctx.Collected, ctx.Derived.AlertOverlaps, ctx.Timezone), } return &module.Output{ID: module.Metadata, StanzaName: "metadata", Value: value}, nil } func sourceWarningSummaries(warnings []weatherdata.SourceWarning) []SourceWarningSummary { out := make([]SourceWarningSummary, 0, len(warnings)) for _, warning := range warnings { out = append(out, SourceWarningSummary{ Source: warning.Source, Code: warning.Code, Severity: warning.Severity, Message: warning.Message, CompletenessImpact: warning.CompletenessImpact, }) } return out }