Schema docs now publish verified label maps for four upstream integer enums (RequestType, IssueStatus, NotificationAgent, NotificationType). Input side accepts only string labels and rejects `*_code` integer fields via `additionalProperties:false`; unknown labels fail with `INVALID_ARGUMENT`. Read side emits both string `*_label` and raw `*_code` integer for prov
72 lines
2.8 KiB
Go
72 lines
2.8 KiB
Go
// Package translate maps agent-facing enum labels to upstream Ombi
|
|
// integer constants. All maps are bidirectional.
|
|
package translate
|
|
|
|
import "fmt"
|
|
|
|
var requestTypeToWire = map[string]int{"movie": 1, "tv": 0, "album": 2}
|
|
var requestTypeFromWire = map[int]string{0: "tv", 1: "movie", 2: "album"}
|
|
|
|
var issueStatusToWire = map[string]int{
|
|
"pending": 0, "in_progress": 1, "resolved": 2, "closed": 3,
|
|
}
|
|
var issueStatusFromWire = map[int]string{
|
|
0: "pending", 1: "in_progress", 2: "resolved", 3: "closed",
|
|
}
|
|
|
|
var notificationAgentToWire = map[string]int{
|
|
"email": 0, "discord": 1, "pushbullet": 2, "pushover": 3,
|
|
"telegram": 4, "slack": 5, "mattermost": 6, "mobile": 7,
|
|
"gotify": 8, "webhook": 9, "whatsapp": 10, "ntfy": 11,
|
|
}
|
|
var notificationAgentFromWire = map[int]string{
|
|
0: "email", 1: "discord", 2: "pushbullet", 3: "pushover",
|
|
4: "telegram", 5: "slack", 6: "mattermost", 7: "mobile",
|
|
8: "gotify", 9: "webhook", 10: "whatsapp", 11: "ntfy",
|
|
}
|
|
|
|
var notificationTypeToWire = map[string]int{
|
|
"new_request": 0, "issue": 1, "request_available": 2,
|
|
"request_approved": 3, "admin_note": 4, "test": 5,
|
|
"request_declined": 6, "item_added_to_fault_queue": 7,
|
|
"welcome_email": 8, "issue_resolved": 9, "issue_comment": 10,
|
|
"newsletter": 11, "partially_available": 12,
|
|
"plex_watchlist_token_expired": 13, "request_deleted": 14,
|
|
"issue_in_progress": 15, "issue_deleted": 16,
|
|
}
|
|
var notificationTypeFromWire = map[int]string{
|
|
0: "new_request", 1: "issue", 2: "request_available",
|
|
3: "request_approved", 4: "admin_note", 5: "test",
|
|
6: "request_declined", 7: "item_added_to_fault_queue",
|
|
8: "welcome_email", 9: "issue_resolved", 10: "issue_comment",
|
|
11: "newsletter", 12: "partially_available",
|
|
13: "plex_watchlist_token_expired", 14: "request_deleted",
|
|
15: "issue_in_progress", 16: "issue_deleted",
|
|
}
|
|
|
|
// ErrUnknownLabel is returned for an out-of-enum agent label.
|
|
var ErrUnknownLabel = fmt.Errorf("unknown enum label")
|
|
|
|
func RequestTypeToWire(s string) (int, error) { return lookup(requestTypeToWire, s) }
|
|
func IssueStatusToWire(s string) (int, error) { return lookup(issueStatusToWire, s) }
|
|
func AgentToWire(s string) (int, error) { return lookup(notificationAgentToWire, s) }
|
|
func NotifTypeToWire(s string) (int, error) { return lookup(notificationTypeToWire, s) }
|
|
|
|
func RequestTypeFromWire(i int) (string, bool) { return lookupRev(requestTypeFromWire, i) }
|
|
func IssueStatusFromWire(i int) (string, bool) { return lookupRev(issueStatusFromWire, i) }
|
|
func AgentFromWire(i int) (string, bool) { return lookupRev(notificationAgentFromWire, i) }
|
|
func NotifTypeFromWire(i int) (string, bool) { return lookupRev(notificationTypeFromWire, i) }
|
|
|
|
func lookup(m map[string]int, s string) (int, error) {
|
|
v, ok := m[s]
|
|
if !ok {
|
|
return 0, fmt.Errorf("%w: %q", ErrUnknownLabel, s)
|
|
}
|
|
return v, nil
|
|
}
|
|
|
|
func lookupRev(m map[int]string, i int) (string, bool) {
|
|
s, ok := m[i]
|
|
return s, ok
|
|
}
|