Files

91 lines
5.5 KiB
Swift

//
// ApplicationSettings.swift
//
//
// Created by Juraldinio on 8/28/22.
//
import Foundation
fileprivate enum ApplicationSettingsKeys {
// TODO: - Need remove after 1.4.0 version
static let ignoreDeviceSatusKeyOld = "Settings.device_ignore"
static let ignoreCreateAccountSatusKeyOld = "Status.createAccount_ignore"
static let isNetworkLogEnabledKeyOld = "Settings.network_copy"
static let isDeviceTokenCopyEnabledKeyOld = "Settings.device_token_copy_enable"
static let apiEnvironmentKeyOld = "Settings.api_environment"
static let apiPaycashEnvironmentKeyOld = "Settings.api_paycash_environment"
static let deviceDescriptionKeyOld = "Settings.device_id"
static let deviceTokenKeyOld = "Settings.device_token"
/// Ignore device status on register flow
static let ignoreDeviceSatusKey = "Settings.application.device_ignore"
/// Ignore create account status on register flow
static let ignoreCreateAccountSatusKey = "Status.application.createAccount_ignore"
/// log all network activity
static let isNetworkLogEnabledKey = "Settings.application.network_copy"
/// Copy device token to Settings fields
static let isDeviceTokenCopyEnabledKey = "Settings.application.device_token_copy_enable"
/// Field in Settings for device description
static let deviceDescriptionKey = "Settings.application.device_id"
/// Field in Settings for device token
static let deviceTokenKey = "Settings.application.device_token"
static let apiUsernameEnvironmentKey = "Settings.application.environment.usernames"
static let apiBackendEnvironmentKey = "Settings.application.environment.backend"
static let otherEnvironmentKey = "Settings.application.environment.other"
static let smartEnvironmentKey = "Settings.application.environment.smart"
/// Field in Settings for Firebase token lifetime
static let firebaseTokenLifetimeKey = "Settings.application.firebase.token.lifetime"
}
public enum ApplicationSettings {
public static var ignoreDeviceSatus: Bool { UserDefaults.standard.bool(forKey: ApplicationSettingsKeys.ignoreDeviceSatusKey) }
public static var ignoreCreateAccountSatus: Bool { UserDefaults.standard.bool(forKey: ApplicationSettingsKeys.ignoreCreateAccountSatusKey) }
public static var isNetworkLogEnabled: Bool { UserDefaults.standard.bool(forKey: ApplicationSettingsKeys.isNetworkLogEnabledKey) }
public static var isDeviceTokenCopyEnabled: Bool { UserDefaults.standard.bool(forKey: ApplicationSettingsKeys.isDeviceTokenCopyEnabledKey) }
public static func device(description: String) { UserDefaults.standard.set(description, forKey: ApplicationSettingsKeys.deviceDescriptionKey) }
public static func device(token: String) { UserDefaults.standard.set(token, forKey: ApplicationSettingsKeys.deviceTokenKey) }
public static var apiUsernameEnvironment: String? { UserDefaults.standard.string(forKey: ApplicationSettingsKeys.apiUsernameEnvironmentKey) }
public static var apiBackendEnvironment: String? { UserDefaults.standard.string(forKey: ApplicationSettingsKeys.apiBackendEnvironmentKey) }
public static var otherEnvironment: String? { UserDefaults.standard.string(forKey: ApplicationSettingsKeys.otherEnvironmentKey) }
public static var smartsEnvironment: String? { UserDefaults.standard.string(forKey: ApplicationSettingsKeys.smartEnvironmentKey) }
public static var firebaseTokenLifetime: Int? { UserDefaults.standard.integer(forKey: ApplicationSettingsKeys.firebaseTokenLifetimeKey) }
public static func clearApiEnvironment() {
UserDefaults.standard.removeObject(forKey: ApplicationSettingsKeys.ignoreDeviceSatusKey)
UserDefaults.standard.removeObject(forKey: ApplicationSettingsKeys.ignoreCreateAccountSatusKey)
UserDefaults.standard.removeObject(forKey: ApplicationSettingsKeys.isNetworkLogEnabledKey)
UserDefaults.standard.removeObject(forKey: ApplicationSettingsKeys.isDeviceTokenCopyEnabledKey)
UserDefaults.standard.removeObject(forKey: ApplicationSettingsKeys.deviceDescriptionKey)
UserDefaults.standard.removeObject(forKey: ApplicationSettingsKeys.deviceTokenKey)
UserDefaults.standard.removeObject(forKey: ApplicationSettingsKeys.apiUsernameEnvironmentKey)
UserDefaults.standard.removeObject(forKey: ApplicationSettingsKeys.apiBackendEnvironmentKey)
UserDefaults.standard.removeObject(forKey: ApplicationSettingsKeys.otherEnvironmentKey)
UserDefaults.standard.removeObject(forKey: ApplicationSettingsKeys.smartEnvironmentKey)
UserDefaults.standard.removeObject(forKey: ApplicationSettingsKeys.firebaseTokenLifetimeKey)
// TODO: - Need remove after 1.4.0 version
UserDefaults.standard.removeObject(forKey: ApplicationSettingsKeys.ignoreDeviceSatusKeyOld)
UserDefaults.standard.removeObject(forKey: ApplicationSettingsKeys.ignoreCreateAccountSatusKeyOld)
UserDefaults.standard.removeObject(forKey: ApplicationSettingsKeys.isNetworkLogEnabledKeyOld)
UserDefaults.standard.removeObject(forKey: ApplicationSettingsKeys.isDeviceTokenCopyEnabledKeyOld)
UserDefaults.standard.removeObject(forKey: ApplicationSettingsKeys.apiEnvironmentKeyOld)
UserDefaults.standard.removeObject(forKey: ApplicationSettingsKeys.apiPaycashEnvironmentKeyOld)
UserDefaults.standard.removeObject(forKey: ApplicationSettingsKeys.deviceDescriptionKeyOld)
UserDefaults.standard.removeObject(forKey: ApplicationSettingsKeys.deviceTokenKeyOld)
}
}