Repository Public
1import Foundation23/// Localized label of an enum value of the contract: catalog key `enum.<type>.<raw value>`.4public func enumLabel(_ type: String, _ raw: String) -> String {5 Localization.shared.string("enum.\(type).\(raw)")6}78public extension API.Freshness {9 var label: String { enumLabel("freshness", rawValue) }10 var tone: StatusTone {11 switch self {12 case .fresh: .ok13 case .stale: .stale14 case .offline: .offline15 }16 }17}1819public extension API.Availability {20 var label: String { enumLabel("availability", rawValue) }21 var tone: StatusTone {22 switch self {23 case .available: .ok24 case .unavailable: .warning25 case .unsupported: .neutral26 case .permissionDenied: .warning27 case .stale: .stale28 case .offline: .offline29 }30 }31}3233public extension API.Severity {34 var label: String { enumLabel("severity", rawValue) }35 var tone: StatusTone {36 switch self {37 case .info: .info38 case .warning: .warning39 case .critical: .critical40 }41 }42 var rank: Int { self == .critical ? 2 : self == .warning ? 1 : 0 }43}4445public extension API.Criticality {46 var label: String { enumLabel("criticality", rawValue) }47 var tone: StatusTone {48 switch self {49 case .low: .neutral50 case .medium: .info51 case .high: .warning52 case .critical: .critical53 }54 }55 var rank: Int { [.low, .medium, .high, .critical].firstIndex(of: self) ?? 0 }56}5758public extension API.UserRole {59 var label: String { enumLabel("role", rawValue) }60}6162public extension API.NodeKind {63 var label: String { enumLabel("node_kind", rawValue) }64 var symbol: String {65 switch self {66 case .mac: "desktopcomputer"67 case .linux: "server.rack"68 case .nas: "externaldrive.connected.to.line.below"69 }70 }71}7273public extension API.ServiceState {74 var label: String { enumLabel("service_state", rawValue) }75 var tone: StatusTone {76 switch self {77 case .online: .ok78 case .stopped: .offline79 case .errored: .critical80 case .unknown: .neutral81 }82 }83}8485public extension API.InferenceHealth {86 var label: String { enumLabel("health", rawValue) }87 var tone: StatusTone {88 switch self {89 case .ok: .ok90 case .failing: .critical91 case .unknown: .neutral92 }93 }94}9596public extension API.ActionState {97 var label: String { enumLabel("action_state", rawValue) }98 var tone: StatusTone {99 switch self {100 case .pendingApproval: .warning101 case .queued, .dispatched: .info102 case .running: .info103 case .succeeded: .ok104 case .failed, .timedOut: .critical105 case .cancelled, .rejected, .expired: .offline106 }107 }108 var isTerminal: Bool {109 switch self {110 case .succeeded, .failed, .cancelled, .timedOut, .rejected, .expired: true111 default: false112 }113 }114}115116public extension API.JobState {117 var label: String { enumLabel("job_state", rawValue) }118 var tone: StatusTone {119 switch self {120 case .queued: .info121 case .running: .info122 case .succeeded: .ok123 case .failed, .timedOut: .critical124 case .cancelled: .offline125 }126 }127 var isTerminal: Bool { self != .queued && self != .running }128}129130public extension API.AlertState {131 var label: String { enumLabel("alert_state", rawValue) }132 var isOpen: Bool { self != .resolved }133}134135public extension API.Alert {136 /// Tone of the alert as a whole: severity while it fires, calmer once acknowledged or resolved.137 var tone: StatusTone {138 switch state {139 case .firing: severity.tone140 case .pending: .stale141 case .acknowledged: .info142 case .resolved: .ok143 }144 }145}146147public extension API.IncidentState {148 var label: String { enumLabel("incident_state", rawValue) }149 var tone: StatusTone {150 switch self {151 case .open: .critical152 case .mitigated: .warning153 case .resolved: .ok154 }155 }156}157158public extension API.AuditOutcome {159 var label: String { enumLabel("outcome", rawValue) }160 var tone: StatusTone {161 switch self {162 case .success: .ok163 case .denied: .warning164 case .failure: .critical165 }166 }167}168169public extension API.MaintenanceStatus {170 var label: String { enumLabel("maintenance_status", rawValue) }171 var tone: StatusTone {172 switch self {173 case .scheduled: .info174 case .inProgress: .maintenance175 case .completed: .ok176 case .cancelled: .offline177 }178 }179}180181public extension API.MaintenanceCategory {182 var label: String { enumLabel("maintenance_category", rawValue) }183 var symbol: String {184 switch self {185 case .planned: "calendar"186 case .emergency: "exclamationmark.triangle"187 case .update: "arrow.down.circle"188 case .hardware: "cpu"189 case .inspection: "magnifyingglass"190 }191 }192}193194public extension API.MaintenanceRecurrence {195 var label: String { enumLabel("recurrence", rawValue) }196}197198public extension API.InvitationStatus {199 var label: String { enumLabel("invitation_status", rawValue) }200 var tone: StatusTone {201 switch self {202 case .pending: .info203 case .exchanged: .warning204 case .completed: .ok205 case .expired, .revoked: .offline206 }207 }208}209210public extension API.InvitationPurpose {211 var label: String { enumLabel("invitation_purpose", rawValue) }212}213214public extension API.TimeRange {215 var label: String { enumLabel("range", rawValue) }216}217218public extension API.ActionTargetKind {219 var label: String { enumLabel("target_kind", rawValue) }220}221222public extension API.VolumeKind {223 var label: String { enumLabel("volume_kind", rawValue) }224}225226public extension API.ActivityKind {227 var label: String { enumLabel("activity_kind", rawValue) }228}229230public extension API.SearchResultKind {231 var label: String { enumLabel("search_kind", rawValue) }232 var symbol: String {233 switch self {234 case .node: "desktopcomputer"235 case .service: "gearshape.2"236 case .alert: "bell"237 case .action: "bolt"238 case .incident: "flame"239 case .job: "list.bullet.rectangle"240 case .inferenceServer: "brain"241 case .maintenanceWindow: "wrench.and.screwdriver"242 case .maintenanceNote: "note.text"243 }244 }245}246247public extension API.GrantEffect {248 var label: String { enumLabel("grant_effect", rawValue) }249}250251/// The enum label keys that must exist in the catalog (used by the completeness test).252public enum EnumLabelKeys {253 public static var all: [String] {254 func keys<E: CaseIterable & RawRepresentable>(_ type: String, _: E.Type) -> [String] where E.RawValue == String {255 E.allCases.map { "enum.\(type).\($0.rawValue)" }256 }257 return keys("freshness", API.Freshness.self) + keys("availability", API.Availability.self) + keys("severity", API.Severity.self)258 + keys("criticality", API.Criticality.self) + keys("role", API.UserRole.self) + keys("node_kind", API.NodeKind.self)259 + keys("service_state", API.ServiceState.self) + keys("health", API.InferenceHealth.self)260 + keys("action_state", API.ActionState.self) + keys("job_state", API.JobState.self) + keys("alert_state", API.AlertState.self)261 + keys("incident_state", API.IncidentState.self) + keys("outcome", API.AuditOutcome.self)262 + keys("maintenance_status", API.MaintenanceStatus.self) + keys("maintenance_category", API.MaintenanceCategory.self)263 + keys("recurrence", API.MaintenanceRecurrence.self) + keys("invitation_status", API.InvitationStatus.self)264 + keys("invitation_purpose", API.InvitationPurpose.self) + keys("range", API.TimeRange.self)265 + keys("target_kind", API.ActionTargetKind.self) + keys("volume_kind", API.VolumeKind.self)266 + keys("activity_kind", API.ActivityKind.self) + keys("search_kind", API.SearchResultKind.self)267 + keys("grant_effect", API.GrantEffect.self)268 }269}270