diff --git a/Adapty/Classes/CustomStringConvertible.swift b/Adapty/Classes/CustomStringConvertible.swift new file mode 100644 index 00000000..b54d9edc --- /dev/null +++ b/Adapty/Classes/CustomStringConvertible.swift @@ -0,0 +1,234 @@ +// +// CustomStringConvertible.swift +// Adapty +// +// Created by Ilya Laryionau on 10/5/20. +// Copyright © 2020 Adapty. All rights reserved. +// + +// MARK: - PaywallModel + +extension PaywallModel { + public override var description: String { + let keysAndValues: [String: Any?] = [ + "developerId": developerId, + "variationId": variationId, + "revision": revision, + "isPromo": isPromo, + "products": products, + "visualPaywall": visualPaywall, + "customPayload": customPayload + ] + + return keysAndValues + .compactMapValues { $0 } + .map { "\($0.key): \($0.value)" } + .joined(separator: ", ") + } +} + +// MARK: - ProductModel + +extension ProductModel { + public override var description: String { + let keysAndValues: [String: Any?] = [ + "vendorProductId": vendorProductId, + "introductoryOfferEligibility": introductoryOfferEligibility, + "promotionalOfferEligibility": promotionalOfferEligibility, + "promotionalOfferId": promotionalOfferId, + "localizedDescription": localizedDescription, + "localizedTitle": localizedTitle, + "price": price, + "currencyCode": currencyCode, + "currencySymbol": currencySymbol, + "regionCode": regionCode, + "subscriptionPeriod": subscriptionPeriod, + "introductoryDiscount": introductoryDiscount, + "subscriptionGroupIdentifier": subscriptionGroupIdentifier, + "discounts": discounts, + "localizedPrice": localizedPrice, + "localizedSubscriptionPeriod": localizedSubscriptionPeriod + ] + + return keysAndValues + .compactMapValues { $0 } + .map { "\($0.key): \($0.value)" } + .joined(separator: ", ") + } +} + +extension ProductModel.PeriodUnit: CustomStringConvertible { + public var description: String { + switch self { + case .day: + return "day" + case .week: + return "week" + case .month: + return "month" + case .year: + return "year" + case .unknown: + return "unknown" + } + } +} + +extension ProductSubscriptionPeriodModel { + public override var description: String { + let keysAndValues: [String: Any?] = [ + "unit": unit, + "numberOfUnits": numberOfUnits + ] + + return keysAndValues + .compactMapValues { $0 } + .map { "\($0.key): \($0.value)" } + .joined(separator: ", ") + } +} + +extension ProductDiscountModel { + public override var description: String { + let keysAndValues: [String: Any?] = [ + "price": price, + "identifier": identifier, + "subscriptionPeriod": subscriptionPeriod, + "numberOfPeriods": numberOfPeriods, + "paymentMode": paymentMode, + "localizedPrice": localizedPrice, + "localizedSubscriptionPeriod": localizedSubscriptionPeriod, + "localizedNumberOfPeriods": localizedNumberOfPeriods + ] + + return keysAndValues + .compactMapValues { $0 } + .map { "\($0.key): \($0.value)" } + .joined(separator: ", ") + } +} + +extension ProductDiscountModel.PaymentMode: CustomStringConvertible { + public var description: String { + switch self { + case .payAsYouGo: + return "payAsYouGo" + case .payUpFront: + return "payUpFront" + case .freeTrial: + return "freeTrial" + case .unknown: + return "unknown" + } + } +} + +// MARK: - PromoModel + +extension PromoModel { + public override var description: String { + let keysAndValues: [String: Any?] = [ + "promoType": promoType, + "variationId": variationId, + "expiresAt": expiresAt, + "paywall": paywall + ] + + return keysAndValues + .compactMapValues { $0 } + .map { "\($0.key): \($0.value)" } + .joined(separator: ", ") + } +} + +// MARK: - PurchaserInfoModel + +extension PurchaserInfoModel { + public override var description: String { + let keysAndValues: [String: Any?] = [ + "paidAccessLevels": paidAccessLevels, + "subscriptions": subscriptions, + "nonSubscriptions": nonSubscriptions + ] + + return keysAndValues + .compactMapValues { $0 } + .map { "\($0.key): \($0.value)" } + .joined(separator: ", ") + } +} + +extension PaidAccessLevelsInfoModel { + public override var description: String { + let keysAndValues: [String: Any?] = [ + "id": id, + "isActive": isActive, + "vendorProductId": vendorProductId, + "store": store, + "activatedAt": activatedAt, + "renewedAt": renewedAt, + "expiresAt": expiresAt, + "isLifetime": isLifetime, + "activeIntroductoryOfferType": activeIntroductoryOfferType, + "activePromotionalOfferType": activePromotionalOfferType, + "willRenew": willRenew, + "isInGracePeriod": isInGracePeriod, + "unsubscribedAt": unsubscribedAt, + "billingIssueDetectedAt": billingIssueDetectedAt + ] + + return keysAndValues + .compactMapValues { $0 } + .map { "\($0.key): \($0.value)" } + .joined(separator: ", ") + } +} + +extension SubscriptionsInfoModel { + public override var description: String { + let keysAndValues: [String: Any?] = [ + "isActive": isActive, + "vendorProductId": vendorProductId, + "store": store, + "activatedAt": activatedAt, + "renewedAt": renewedAt, + "expiresAt": expiresAt, + "startsAt": startsAt, + "isLifetime": isLifetime, + "activeIntroductoryOfferType": activeIntroductoryOfferType, + "activePromotionalOfferType": activePromotionalOfferType, + "willRenew": willRenew, + "isInGracePeriod": isInGracePeriod, + "unsubscribedAt": unsubscribedAt, + "billingIssueDetectedAt": billingIssueDetectedAt, + "isSandbox": isSandbox, + "vendorTransactionId": vendorTransactionId, + "vendorOriginalTransactionId": vendorOriginalTransactionId + ] + + return keysAndValues + .compactMapValues { $0 } + .map { "\($0.key): \($0.value)" } + .joined(separator: ", ") + } +} + +extension NonSubscriptionsInfoModel { + public override var description: String { + let keysAndValues: [String: Any?] = [ + "purchaseId": purchaseId, + "vendorProductId": vendorProductId, + "store": store, + "purchasedAt": purchasedAt, + "isOneTime": isOneTime, + "isSandbox": isSandbox, + "vendorTransactionId": vendorTransactionId, + "vendorOriginalTransactionId": vendorOriginalTransactionId + ] + + return keysAndValues + .compactMapValues { $0 } + .map { "\($0.key): \($0.value)" } + .joined(separator: ", ") + } +}