-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move BKTEvaluationDetails to a new file
- Loading branch information
1 parent
7a0907e
commit 6e761ac
Showing
2 changed files
with
62 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import Foundation | ||
|
||
public struct BKTEvaluationDetails<T:Equatable>: Equatable { | ||
public let featureId: String | ||
public let featureVersion: Int | ||
public let userId: String | ||
public let variationId: String | ||
public let variationName: String | ||
public let variationValue: T | ||
public let reason: Reason | ||
|
||
public enum Reason: String, Codable, Hashable { | ||
case target = "TARGET" | ||
case rule = "RULE" | ||
case `default` = "DEFAULT" | ||
case client = "CLIENT" | ||
case offVariation = "OFF_VARIATION" | ||
case prerequisite = "PREREQUISITE" | ||
|
||
public static func fromString(value: String) -> Reason { | ||
return Reason(rawValue: value) ?? .client | ||
} | ||
} | ||
|
||
public static func == (lhs: BKTEvaluationDetails<T>, rhs: BKTEvaluationDetails<T>) -> Bool { | ||
return lhs.featureId == rhs.featureId && | ||
lhs.featureVersion == rhs.featureVersion && | ||
lhs.userId == rhs.userId && | ||
lhs.variationId == rhs.variationId && | ||
lhs.variationName == rhs.variationName && | ||
lhs.reason == rhs.reason && | ||
lhs.variationValue == rhs.variationValue | ||
} | ||
|
||
static func newDefaultInstance(featureId: String, userId: String, defaultValue: T) -> BKTEvaluationDetails<T> { | ||
return BKTEvaluationDetails( | ||
featureId: featureId, | ||
featureVersion: 0, | ||
userId: userId, | ||
variationId: "", | ||
variationName: "", | ||
variationValue: defaultValue, | ||
reason: .client | ||
) | ||
} | ||
|
||
public init(featureId: String, | ||
featureVersion: Int, | ||
userId: String, | ||
variationId: String, | ||
variationName: String, | ||
variationValue: T, | ||
reason: Reason) { | ||
self.featureId = featureId | ||
self.featureVersion = featureVersion | ||
self.userId = userId | ||
self.variationId = variationId | ||
self.variationName = variationName | ||
self.variationValue = variationValue | ||
self.reason = reason | ||
} | ||
} |