// // NotificationModel.swift // PrivadoVPN // // Created by Juraldinio on 4/13/21. // Copyright © 2021 Privado LLC. All rights reserved. // import Foundation struct NotificationModel { let username: String let slug: String? let subject: String let body: String let created: Date? let sentDate: Date let expires: Date? let actions: [String] let isVpnActive: Bool let urlPath: String? let trafficTotalMb: UInt let trafficLeftMb: UInt let localIp: String? } extension NotificationModel { init(with notification: PrivadoNotification) { let trafficTotalMb: UInt let trafficLeftMb: UInt if let customer = notification.payload.customer { trafficTotalMb = customer.trafficTotal trafficLeftMb = customer.trafficLeft } else { trafficTotalMb = 0 trafficLeftMb = 0 } self.init( username: notification.payload.username, slug: notification.payload.slug, subject: notification.payload.subject ?? "", body: notification.payload.body, created: DateFormatter.iso8601Full.date(from: notification.payload.created), sentDate: DateFormatter.iso8601Full.date(from: notification.payload.sentDate) ?? Date(), expires: DateFormatter.iso8601Full.date(from: notification.payload.expires), actions: notification.payload.actions ?? [], isVpnActive: notification.payload.customer?.isVPNActive ?? false, urlPath: notification.payload.customer?.loginUrl, trafficTotalMb: trafficTotalMb, trafficLeftMb: trafficLeftMb, localIp: notification.payload.customer?.localIp ) } init(username: String, subject: String, body: String, sentDate: Date) { self.init( username: username, slug: "", subject: subject, body: body, created: nil, sentDate: sentDate, expires: nil, actions: [], isVpnActive: false, urlPath: nil, trafficTotalMb: 0, trafficLeftMb: 0, localIp: nil ) } } extension NotificationModel: Equatable { }