{-# LANGUAGE OverloadedLists #-}
module LaunchDarkly.Server.Details where
import Data.Aeson.Types (Value(..), ToJSON, toJSON)
import Data.Text (Text)
import GHC.Exts (fromList)
import GHC.Natural (Natural)
import GHC.Generics (Generic)
data EvaluationDetail value = EvaluationDetail
{ forall value. EvaluationDetail value -> value
value :: !value
, forall value. EvaluationDetail value -> Maybe Integer
variationIndex :: !(Maybe Integer)
, forall value. EvaluationDetail value -> EvaluationReason
reason :: !EvaluationReason
} deriving (forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall value x.
Rep (EvaluationDetail value) x -> EvaluationDetail value
forall value x.
EvaluationDetail value -> Rep (EvaluationDetail value) x
$cto :: forall value x.
Rep (EvaluationDetail value) x -> EvaluationDetail value
$cfrom :: forall value x.
EvaluationDetail value -> Rep (EvaluationDetail value) x
Generic, EvaluationDetail value -> EvaluationDetail value -> Bool
forall value.
Eq value =>
EvaluationDetail value -> EvaluationDetail value -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EvaluationDetail value -> EvaluationDetail value -> Bool
$c/= :: forall value.
Eq value =>
EvaluationDetail value -> EvaluationDetail value -> Bool
== :: EvaluationDetail value -> EvaluationDetail value -> Bool
$c== :: forall value.
Eq value =>
EvaluationDetail value -> EvaluationDetail value -> Bool
Eq, Int -> EvaluationDetail value -> ShowS
forall value. Show value => Int -> EvaluationDetail value -> ShowS
forall value. Show value => [EvaluationDetail value] -> ShowS
forall value. Show value => EvaluationDetail value -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EvaluationDetail value] -> ShowS
$cshowList :: forall value. Show value => [EvaluationDetail value] -> ShowS
show :: EvaluationDetail value -> String
$cshow :: forall value. Show value => EvaluationDetail value -> String
showsPrec :: Int -> EvaluationDetail value -> ShowS
$cshowsPrec :: forall value. Show value => Int -> EvaluationDetail value -> ShowS
Show)
instance ToJSON a => ToJSON (EvaluationDetail a) where
toJSON :: EvaluationDetail a -> Value
toJSON = forall a. ToJSON a => a -> Value
toJSON
data EvaluationReason
= EvaluationReasonOff
| EvaluationReasonTargetMatch
| EvaluationReasonRuleMatch
{ EvaluationReason -> Natural
ruleIndex :: !Natural
, EvaluationReason -> Text
ruleId :: !Text
, EvaluationReason -> Bool
inExperiment :: !Bool
}
| EvaluationReasonPrerequisiteFailed
{ EvaluationReason -> Text
prerequisiteKey :: !Text
}
| EvaluationReasonFallthrough
{ inExperiment :: !Bool
}
| EvaluationReasonError
{ EvaluationReason -> EvalErrorKind
errorKind :: !EvalErrorKind
}
deriving (forall x. Rep EvaluationReason x -> EvaluationReason
forall x. EvaluationReason -> Rep EvaluationReason x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EvaluationReason x -> EvaluationReason
$cfrom :: forall x. EvaluationReason -> Rep EvaluationReason x
Generic, EvaluationReason -> EvaluationReason -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EvaluationReason -> EvaluationReason -> Bool
$c/= :: EvaluationReason -> EvaluationReason -> Bool
== :: EvaluationReason -> EvaluationReason -> Bool
$c== :: EvaluationReason -> EvaluationReason -> Bool
Eq, Int -> EvaluationReason -> ShowS
[EvaluationReason] -> ShowS
EvaluationReason -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EvaluationReason] -> ShowS
$cshowList :: [EvaluationReason] -> ShowS
show :: EvaluationReason -> String
$cshow :: EvaluationReason -> String
showsPrec :: Int -> EvaluationReason -> ShowS
$cshowsPrec :: Int -> EvaluationReason -> ShowS
Show)
instance ToJSON EvaluationReason where
toJSON :: EvaluationReason -> Value
toJSON EvaluationReason
x = case EvaluationReason
x of
EvaluationReason
EvaluationReasonOff ->
Object -> Value
Object forall a b. (a -> b) -> a -> b
$ forall l. IsList l => [Item l] -> l
fromList [(Key
"kind", Value
"OFF")]
EvaluationReason
EvaluationReasonTargetMatch ->
Object -> Value
Object forall a b. (a -> b) -> a -> b
$ forall l. IsList l => [Item l] -> l
fromList [(Key
"kind", Value
"TARGET_MATCH")]
(EvaluationReasonRuleMatch Natural
ruleIndex Text
ruleId Bool
True) ->
Object -> Value
Object forall a b. (a -> b) -> a -> b
$ forall l. IsList l => [Item l] -> l
fromList [(Key
"kind", Value
"RULE_MATCH"), (Key
"ruleIndex", forall a. ToJSON a => a -> Value
toJSON Natural
ruleIndex), (Key
"ruleId", forall a. ToJSON a => a -> Value
toJSON Text
ruleId), (Key
"inExperiment", forall a. ToJSON a => a -> Value
toJSON Bool
True)]
(EvaluationReasonRuleMatch Natural
ruleIndex Text
ruleId Bool
False) ->
Object -> Value
Object forall a b. (a -> b) -> a -> b
$ forall l. IsList l => [Item l] -> l
fromList [(Key
"kind", Value
"RULE_MATCH"), (Key
"ruleIndex", forall a. ToJSON a => a -> Value
toJSON Natural
ruleIndex), (Key
"ruleId", forall a. ToJSON a => a -> Value
toJSON Text
ruleId)]
(EvaluationReasonPrerequisiteFailed Text
prerequisiteKey) ->
Object -> Value
Object forall a b. (a -> b) -> a -> b
$ forall l. IsList l => [Item l] -> l
fromList [(Key
"kind", Value
"PREREQUISITE_FAILED"), (Key
"prerequisiteKey", forall a. ToJSON a => a -> Value
toJSON Text
prerequisiteKey)]
EvaluationReasonFallthrough Bool
True ->
Object -> Value
Object forall a b. (a -> b) -> a -> b
$ forall l. IsList l => [Item l] -> l
fromList [(Key
"kind", Value
"FALLTHROUGH"), (Key
"inExperiment", forall a. ToJSON a => a -> Value
toJSON Bool
True)]
EvaluationReasonFallthrough Bool
False ->
Object -> Value
Object forall a b. (a -> b) -> a -> b
$ forall l. IsList l => [Item l] -> l
fromList [(Key
"kind", Value
"FALLTHROUGH")]
(EvaluationReasonError EvalErrorKind
errorKind) ->
Object -> Value
Object forall a b. (a -> b) -> a -> b
$ forall l. IsList l => [Item l] -> l
fromList [(Key
"kind", Value
"ERROR"), (Key
"errorKind", forall a. ToJSON a => a -> Value
toJSON EvalErrorKind
errorKind)]
isInExperiment :: EvaluationReason -> Bool
isInExperiment :: EvaluationReason -> Bool
isInExperiment EvaluationReason
reason = case EvaluationReason
reason of
EvaluationReasonRuleMatch Natural
_ Text
_ Bool
inExperiment -> Bool
inExperiment
EvaluationReasonFallthrough Bool
inExperiment -> Bool
inExperiment
EvaluationReason
_ -> Bool
False
data EvalErrorKind
= EvalErrorKindMalformedFlag
| EvalErrorFlagNotFound
| EvalErrorWrongType
| EvalErrorClientNotReady
| EvalErrorExternalStore !Text
deriving (forall x. Rep EvalErrorKind x -> EvalErrorKind
forall x. EvalErrorKind -> Rep EvalErrorKind x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EvalErrorKind x -> EvalErrorKind
$cfrom :: forall x. EvalErrorKind -> Rep EvalErrorKind x
Generic, EvalErrorKind -> EvalErrorKind -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EvalErrorKind -> EvalErrorKind -> Bool
$c/= :: EvalErrorKind -> EvalErrorKind -> Bool
== :: EvalErrorKind -> EvalErrorKind -> Bool
$c== :: EvalErrorKind -> EvalErrorKind -> Bool
Eq, Int -> EvalErrorKind -> ShowS
[EvalErrorKind] -> ShowS
EvalErrorKind -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EvalErrorKind] -> ShowS
$cshowList :: [EvalErrorKind] -> ShowS
show :: EvalErrorKind -> String
$cshow :: EvalErrorKind -> String
showsPrec :: Int -> EvalErrorKind -> ShowS
$cshowsPrec :: Int -> EvalErrorKind -> ShowS
Show)
instance ToJSON EvalErrorKind where
toJSON :: EvalErrorKind -> Value
toJSON EvalErrorKind
x = Text -> Value
String forall a b. (a -> b) -> a -> b
$ case EvalErrorKind
x of
EvalErrorKind
EvalErrorKindMalformedFlag -> Text
"MALFORMED_FLAG"
EvalErrorKind
EvalErrorFlagNotFound -> Text
"FLAG_NOT_FOUND"
EvalErrorKind
EvalErrorWrongType -> Text
"WRONG_TYPE"
EvalErrorKind
EvalErrorClientNotReady -> Text
"CLIENT_NOT_READY"
EvalErrorExternalStore Text
_ -> Text
"EXTERNAL_STORE_ERROR"