import Foundation

enum AppInfo {
    static let name = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String ?? "KDChat"
    static let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "–"
    static let build = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "–"
    static let distribution = AppDistribution.current
    static let testFlightURL: URL? = nil // TODO: set when TestFlight is configured
}

enum AppDistribution: String {
    case development = "Development"
    case simulator = "Simulator"
    case testFlight = "TestFlight"
    case appStore = "App Store"
    case adHoc = "Ad Hoc"

    static var current: AppDistribution {
        #if targetEnvironment(simulator)
        return .simulator
        #else
        #if DEBUG
        return .development
        #else
        if let receiptURL = Bundle.main.appStoreReceiptURL,
           receiptURL.lastPathComponent == "sandboxReceipt" {
            return .testFlight
        }
        if Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") != nil {
            return .adHoc
        }
        return .appStore
        #endif
        #endif
    }
}
