64 lines
2.2 KiB
Swift
64 lines
2.2 KiB
Swift
// SPDX-FileCopyrightText: 2026 Kaede Akino
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
import Foundation
|
|
import TermindDomain
|
|
|
|
/// Data-only contract for RevenueCat's remote visibility rules and localized text.
|
|
public nonisolated struct ProPaywallState {
|
|
public let hasProAccess: Bool
|
|
public let canManageSubscription: Bool
|
|
public let isFamilyShared: Bool
|
|
public let expiresAt: Date?
|
|
/// Protocol values consumed by the dashboard, never displayed as app copy.
|
|
public let state: String
|
|
|
|
public init(status: EntitlementStatus) {
|
|
hasProAccess = status.hasProAccess
|
|
switch status {
|
|
case .subscription(let subscription):
|
|
canManageSubscription = subscription.ownership == .purchased
|
|
isFamilyShared = subscription.ownership == .familyShared
|
|
expiresAt = subscription.expiresAt
|
|
switch subscription.phase {
|
|
case .introductoryTrial: state = "trial"
|
|
case .subscribed:
|
|
switch subscription.willAutoRenew {
|
|
case true: state = "renewing"
|
|
case false: state = "ending"
|
|
case nil: state = "active"
|
|
}
|
|
case .gracePeriod: state = "grace"
|
|
case .billingRetry: state = "retry"
|
|
case .expired: state = "expired"
|
|
case .revoked: state = "revoked"
|
|
}
|
|
case .purchased(let ownership):
|
|
canManageSubscription = false
|
|
isFamilyShared = ownership == .familyShared
|
|
expiresAt = nil
|
|
state = "lifetime"
|
|
case .loading:
|
|
canManageSubscription = false
|
|
isFamilyShared = false
|
|
expiresAt = nil
|
|
state = "loading"
|
|
case .free:
|
|
canManageSubscription = false
|
|
isFamilyShared = false
|
|
expiresAt = nil
|
|
state = "free"
|
|
case .verificationFailed:
|
|
canManageSubscription = false
|
|
isFamilyShared = false
|
|
expiresAt = nil
|
|
state = "unverified"
|
|
case .unrestrictedForTesting:
|
|
canManageSubscription = false
|
|
isFamilyShared = false
|
|
expiresAt = nil
|
|
state = "development"
|
|
}
|
|
}
|
|
}
|