Skip to content
Snippets Groups Projects
MessengerGetNotificationReports.swift 948 B
Newer Older
import XXClient
import XCTestDynamicOverlay

Dariusz Rybicki's avatar
Dariusz Rybicki committed
public struct MessengerGetNotificationReports {
  public enum Error: Swift.Error, Equatable {
    case serviceListMissing
  }

  public var run: (String) throws -> [NotificationReport]
  public func callAsFunction(notificationCSV: String) throws -> [NotificationReport] {
    try run(notificationCSV)
  }
}

Dariusz Rybicki's avatar
Dariusz Rybicki committed
extension MessengerGetNotificationReports {
  public static func live(_ env: MessengerEnvironment) -> MessengerGetNotificationReports {
    MessengerGetNotificationReports { notificationCSV in
      guard let serviceList = env.serviceList() else {
        throw Error.serviceListMissing
      }
      return try env.getNotificationsReport(
        notificationCSV: notificationCSV,
        services: serviceList
      )
    }
  }
}

Dariusz Rybicki's avatar
Dariusz Rybicki committed
extension MessengerGetNotificationReports {
  public static let unimplemented = MessengerGetNotificationReports(
    run: XCTUnimplemented("\(Self.self)")
  )
}