Files
attendi/Apps/Attendi/Models/AppNotification.swift
T

74 lines
2.1 KiB
Swift

import Foundation
/// An in-app notification reporting an event of a speech model asset download.
struct AppNotification: Equatable, Identifiable {
// MARK: Properties
/// The unique identifier of the notification.
let id: UUID
/// The download event the notification reports.
let event: Event
/// The localized name of the locale whose speech model the event is about.
let localeName: String
// MARK: Initializers
/// Creates a notification for a given download event and locale name.
///
/// - Parameters:
/// - id: The unique identifier of the notification. Defaults to a newly generated identifier.
/// - event: The download event the notification reports.
/// - localeName: The localized name of the locale whose speech model the event is about.
init(
id: UUID = .init(),
event: Event,
localeName: String
) {
self.id = id
self.event = event
self.localeName = localeName
}
}
// MARK: - Enumerations
extension AppNotification {
/// The download event the notification reports.
enum Event: Sendable {
/// The download was cancelled before it finished.
case cancelled
/// The download failed.
case failed
/// The download started.
case started
}
}
// MARK: - Properties
extension AppNotification {
/// The system symbol of the icon matching the notification's event.
var imageSymbol: String {
switch event {
case .cancelled: "xmark.circle"
case .failed: "exclamationmark.triangle"
case .started: "arrow.down.circle"
}
}
/// The localized message of the notification, naming the locale of the speech model, from the app's string catalog.
var textMessage: LocalizedStringResource {
switch event {
case .cancelled: .viewRecordingNotificationDownloadCancelled(localeName)
case .failed: .viewRecordingNotificationDownloadFailed(localeName)
case .started: .viewRecordingNotificationDownloadStarted(localeName)
}
}
}