//
//  TSPurchaseEnum.swift
//  TSLiveWallpaper
//
//  Created by 100Years on 2025/6/10.
//


public enum PremiumPeriod: String, CaseIterable {
    case none           = ""
    case week           = "Week"
    case month          = "Monthly"
    case year           = "Yearly"
    case lifetime       = "Lifetime"
    
    /// 对应vip类型，可以免费使用次数
    var freeNumber: Int {
        switch self {
        case .week:
            return 30
        case .month:
            return 30
        case .year:
            return 60
        case .none:
            return 0
        default:
            return 30
        }
    }
    
    var saveString: String {
        switch self {
        case .none:
            return kPercentlocalized(90)
        default:
            return kPercentlocalized(90)
        }
    }
    
    /*
    1. 一年（非闰年）
    ​365 天​ = 365 × 24 × 60 × 60 × 1000 = ​31,536,000,000 毫秒
    （若闰年 366 天 = 31,622,400,000 毫秒）
    ​2. 一个月（平均）
    ​30.44 天​（按 365 天/12 个月计算）≈ 30.44 × 24 × 60 × 60 × 1000 ≈ ​2,629,746,000 毫秒
    （实际月份天数不同，如 28/30/31 天需单独计算）
    ​3. 一周
    ​7 天​ = 7 × 24 × 60 × 60 × 1000 = ​604,800,000 毫秒
    */
    var milliseconds:Int {
        switch self {
        case .year:
            return  365 * 24 * 60 * 60 * 1000
        case .month:
            return 30 * 24 * 60 * 60 * 1000
        case .week:
            return 7 * 24 * 60 * 60 * 1000
        default:
            return 0
        }
    }
}

public struct PurchaseProduct {
    public let productId: String
    public let period: PremiumPeriod
    
    public init(productId: String, period: PremiumPeriod) {
        self.productId = productId
        self.period = period
    }
}

public enum PremiumRequestState {
    case none
    
    case loading
    case loadSuccess
    case loadFail
    
    case paying
    case paySuccess
    case payFail
    
    case restoreing
    case restoreSuccess
    case restoreFail
    
    case verifying
    case verifySuccess
    case verifyFail
}


public extension Notification.Name {
    static let kPurchasePrepared = Self.init("kPurchaseProductPrepared")
    static let kPurchaseDidChanged = Self.init("kPurchaseDidChanged")
    static let kVipFreeNumChanged = Notification.Name("kVipFreeNumChanged")   //Vip免费次数发生变化
    
}




