module LaunchDarkly.Server.Features where

import Control.Lens                  (element, (^?))
import Control.Monad                 (mzero)
import Data.Aeson                    (FromJSON(..), ToJSON(..), Value(..), withObject, (.:), (.:?), object, (.=), (.!=))
import Data.Maybe                    (fromMaybe)
import Data.Text                     (Text)
import Data.HashSet                  (HashSet)
import Data.Generics.Product         (getField)
import GHC.Natural                   (Natural)
import GHC.Generics                  (Generic)

import LaunchDarkly.Server.Operators (Op)
import LaunchDarkly.Server.Details (EvaluationReason (..))
import qualified LaunchDarkly.Server.Details as D

data Target = Target
    { Target -> [Text]
values    :: ![Text]
    , Target -> Integer
variation :: !Integer
    } deriving ((forall x. Target -> Rep Target x)
-> (forall x. Rep Target x -> Target) -> Generic Target
forall x. Rep Target x -> Target
forall x. Target -> Rep Target x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Target x -> Target
$cfrom :: forall x. Target -> Rep Target x
Generic, Value -> Parser [Target]
Value -> Parser Target
(Value -> Parser Target)
-> (Value -> Parser [Target]) -> FromJSON Target
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [Target]
$cparseJSONList :: Value -> Parser [Target]
parseJSON :: Value -> Parser Target
$cparseJSON :: Value -> Parser Target
FromJSON, [Target] -> Encoding
[Target] -> Value
Target -> Encoding
Target -> Value
(Target -> Value)
-> (Target -> Encoding)
-> ([Target] -> Value)
-> ([Target] -> Encoding)
-> ToJSON Target
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [Target] -> Encoding
$ctoEncodingList :: [Target] -> Encoding
toJSONList :: [Target] -> Value
$ctoJSONList :: [Target] -> Value
toEncoding :: Target -> Encoding
$ctoEncoding :: Target -> Encoding
toJSON :: Target -> Value
$ctoJSON :: Target -> Value
ToJSON, Int -> Target -> ShowS
[Target] -> ShowS
Target -> String
(Int -> Target -> ShowS)
-> (Target -> String) -> ([Target] -> ShowS) -> Show Target
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Target] -> ShowS
$cshowList :: [Target] -> ShowS
show :: Target -> String
$cshow :: Target -> String
showsPrec :: Int -> Target -> ShowS
$cshowsPrec :: Int -> Target -> ShowS
Show, Target -> Target -> Bool
(Target -> Target -> Bool)
-> (Target -> Target -> Bool) -> Eq Target
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Target -> Target -> Bool
$c/= :: Target -> Target -> Bool
== :: Target -> Target -> Bool
$c== :: Target -> Target -> Bool
Eq)

data Rule = Rule
    { Rule -> Text
id                 :: !Text
    , Rule -> [Clause]
clauses            :: ![Clause]
    , Rule -> VariationOrRollout
variationOrRollout :: !VariationOrRollout
    , Rule -> Bool
trackEvents        :: !Bool
    } deriving ((forall x. Rule -> Rep Rule x)
-> (forall x. Rep Rule x -> Rule) -> Generic Rule
forall x. Rep Rule x -> Rule
forall x. Rule -> Rep Rule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Rule x -> Rule
$cfrom :: forall x. Rule -> Rep Rule x
Generic, Int -> Rule -> ShowS
[Rule] -> ShowS
Rule -> String
(Int -> Rule -> ShowS)
-> (Rule -> String) -> ([Rule] -> ShowS) -> Show Rule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Rule] -> ShowS
$cshowList :: [Rule] -> ShowS
show :: Rule -> String
$cshow :: Rule -> String
showsPrec :: Int -> Rule -> ShowS
$cshowsPrec :: Int -> Rule -> ShowS
Show, Rule -> Rule -> Bool
(Rule -> Rule -> Bool) -> (Rule -> Rule -> Bool) -> Eq Rule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Rule -> Rule -> Bool
$c/= :: Rule -> Rule -> Bool
== :: Rule -> Rule -> Bool
$c== :: Rule -> Rule -> Bool
Eq)

instance FromJSON Rule where
    parseJSON :: Value -> Parser Rule
parseJSON = String -> (Object -> Parser Rule) -> Value -> Parser Rule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Rule" ((Object -> Parser Rule) -> Value -> Parser Rule)
-> (Object -> Parser Rule) -> Value -> Parser Rule
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Text
id          <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.:  Key
"id"
        [Clause]
clauses     <- Object
o Object -> Key -> Parser [Clause]
forall a. FromJSON a => Object -> Key -> Parser a
.:  Key
"clauses"
        Maybe Integer
variation   <- Object
o Object -> Key -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"variation"
        Maybe Rollout
rollout     <- Object
o Object -> Key -> Parser (Maybe Rollout)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"rollout"
        Bool
trackEvents <- Object
o Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
.:  Key
"trackEvents"
        Rule -> Parser Rule
forall (f :: * -> *) a. Applicative f => a -> f a
pure Rule :: Text -> [Clause] -> VariationOrRollout -> Bool -> Rule
Rule
            { $sel:id:Rule :: Text
id                 = Text
id
            , $sel:clauses:Rule :: [Clause]
clauses            = [Clause]
clauses
            , $sel:variationOrRollout:Rule :: VariationOrRollout
variationOrRollout = VariationOrRollout :: Maybe Integer -> Maybe Rollout -> VariationOrRollout
VariationOrRollout
                { $sel:variation:VariationOrRollout :: Maybe Integer
variation = Maybe Integer
variation
                , $sel:rollout:VariationOrRollout :: Maybe Rollout
rollout   = Maybe Rollout
rollout
                }
            , $sel:trackEvents:Rule :: Bool
trackEvents        = Bool
trackEvents
            }

instance ToJSON Rule where
    toJSON :: Rule -> Value
toJSON Rule
rule = [Pair] -> Value
object
        [ Key
"id"          Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Rule -> Text
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"id" Rule
rule
        , Key
"clauses"     Key -> [Clause] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Rule -> [Clause]
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"clauses" Rule
rule
        , Key
"trackEvents" Key -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Rule -> Bool
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"trackEvents" Rule
rule
        , Key
"variation"   Key -> Maybe Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= VariationOrRollout -> Maybe Integer
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"variation" (Rule -> VariationOrRollout
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"variationOrRollout" Rule
rule)
        , Key
"rollout"     Key -> Maybe Rollout -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= VariationOrRollout -> Maybe Rollout
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"rollout" (Rule -> VariationOrRollout
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"variationOrRollout" Rule
rule)
        ]

data WeightedVariation = WeightedVariation
    { WeightedVariation -> Integer
variation :: !Integer
    , WeightedVariation -> Float
weight    :: !Float
    , WeightedVariation -> Bool
untracked :: !Bool
    } deriving ((forall x. WeightedVariation -> Rep WeightedVariation x)
-> (forall x. Rep WeightedVariation x -> WeightedVariation)
-> Generic WeightedVariation
forall x. Rep WeightedVariation x -> WeightedVariation
forall x. WeightedVariation -> Rep WeightedVariation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep WeightedVariation x -> WeightedVariation
$cfrom :: forall x. WeightedVariation -> Rep WeightedVariation x
Generic, [WeightedVariation] -> Encoding
[WeightedVariation] -> Value
WeightedVariation -> Encoding
WeightedVariation -> Value
(WeightedVariation -> Value)
-> (WeightedVariation -> Encoding)
-> ([WeightedVariation] -> Value)
-> ([WeightedVariation] -> Encoding)
-> ToJSON WeightedVariation
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [WeightedVariation] -> Encoding
$ctoEncodingList :: [WeightedVariation] -> Encoding
toJSONList :: [WeightedVariation] -> Value
$ctoJSONList :: [WeightedVariation] -> Value
toEncoding :: WeightedVariation -> Encoding
$ctoEncoding :: WeightedVariation -> Encoding
toJSON :: WeightedVariation -> Value
$ctoJSON :: WeightedVariation -> Value
ToJSON, Int -> WeightedVariation -> ShowS
[WeightedVariation] -> ShowS
WeightedVariation -> String
(Int -> WeightedVariation -> ShowS)
-> (WeightedVariation -> String)
-> ([WeightedVariation] -> ShowS)
-> Show WeightedVariation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WeightedVariation] -> ShowS
$cshowList :: [WeightedVariation] -> ShowS
show :: WeightedVariation -> String
$cshow :: WeightedVariation -> String
showsPrec :: Int -> WeightedVariation -> ShowS
$cshowsPrec :: Int -> WeightedVariation -> ShowS
Show, WeightedVariation -> WeightedVariation -> Bool
(WeightedVariation -> WeightedVariation -> Bool)
-> (WeightedVariation -> WeightedVariation -> Bool)
-> Eq WeightedVariation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WeightedVariation -> WeightedVariation -> Bool
$c/= :: WeightedVariation -> WeightedVariation -> Bool
== :: WeightedVariation -> WeightedVariation -> Bool
$c== :: WeightedVariation -> WeightedVariation -> Bool
Eq)

instance FromJSON WeightedVariation where
    parseJSON :: Value -> Parser WeightedVariation
parseJSON = String
-> (Object -> Parser WeightedVariation)
-> Value
-> Parser WeightedVariation
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"WeightedVariation" ((Object -> Parser WeightedVariation)
 -> Value -> Parser WeightedVariation)
-> (Object -> Parser WeightedVariation)
-> Value
-> Parser WeightedVariation
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Integer
variation <- Object
o Object -> Key -> Parser Integer
forall a. FromJSON a => Object -> Key -> Parser a
.:  Key
"variation"
        Float
weight    <- Object
o Object -> Key -> Parser Float
forall a. FromJSON a => Object -> Key -> Parser a
.:  Key
"weight"
        Bool
untracked <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"untracked" Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
False
        WeightedVariation -> Parser WeightedVariation
forall (f :: * -> *) a. Applicative f => a -> f a
pure WeightedVariation :: Integer -> Float -> Bool -> WeightedVariation
WeightedVariation { Bool
Float
Integer
untracked :: Bool
weight :: Float
variation :: Integer
$sel:untracked:WeightedVariation :: Bool
$sel:weight:WeightedVariation :: Float
$sel:variation:WeightedVariation :: Integer
.. }

data RolloutKind = RolloutKindExperiment | RolloutKindRollout
    deriving (RolloutKind -> RolloutKind -> Bool
(RolloutKind -> RolloutKind -> Bool)
-> (RolloutKind -> RolloutKind -> Bool) -> Eq RolloutKind
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RolloutKind -> RolloutKind -> Bool
$c/= :: RolloutKind -> RolloutKind -> Bool
== :: RolloutKind -> RolloutKind -> Bool
$c== :: RolloutKind -> RolloutKind -> Bool
Eq, Int -> RolloutKind -> ShowS
[RolloutKind] -> ShowS
RolloutKind -> String
(Int -> RolloutKind -> ShowS)
-> (RolloutKind -> String)
-> ([RolloutKind] -> ShowS)
-> Show RolloutKind
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RolloutKind] -> ShowS
$cshowList :: [RolloutKind] -> ShowS
show :: RolloutKind -> String
$cshow :: RolloutKind -> String
showsPrec :: Int -> RolloutKind -> ShowS
$cshowsPrec :: Int -> RolloutKind -> ShowS
Show)

instance ToJSON RolloutKind where
    toJSON :: RolloutKind -> Value
toJSON RolloutKind
x = Text -> Value
String (Text -> Value) -> Text -> Value
forall a b. (a -> b) -> a -> b
$ case RolloutKind
x of
        RolloutKind
RolloutKindExperiment -> Text
"experiment"
        RolloutKind
RolloutKindRollout    -> Text
"rollout"

instance FromJSON RolloutKind where
    parseJSON :: Value -> Parser RolloutKind
parseJSON Value
x = case Value
x of
        (String Text
"experiment") -> RolloutKind -> Parser RolloutKind
forall (f :: * -> *) a. Applicative f => a -> f a
pure RolloutKind
RolloutKindExperiment
        (String Text
"rollout")    -> RolloutKind -> Parser RolloutKind
forall (f :: * -> *) a. Applicative f => a -> f a
pure RolloutKind
RolloutKindRollout
        Value
_                     -> Parser RolloutKind
forall (m :: * -> *) a. MonadPlus m => m a
mzero

data Rollout = Rollout
    { Rollout -> [WeightedVariation]
variations :: ![WeightedVariation]
    , Rollout -> Maybe Text
bucketBy   :: !(Maybe Text)
    , Rollout -> RolloutKind
kind       :: !RolloutKind
    , Rollout -> Maybe Int
seed       :: !(Maybe Int)
    } deriving ((forall x. Rollout -> Rep Rollout x)
-> (forall x. Rep Rollout x -> Rollout) -> Generic Rollout
forall x. Rep Rollout x -> Rollout
forall x. Rollout -> Rep Rollout x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Rollout x -> Rollout
$cfrom :: forall x. Rollout -> Rep Rollout x
Generic, [Rollout] -> Encoding
[Rollout] -> Value
Rollout -> Encoding
Rollout -> Value
(Rollout -> Value)
-> (Rollout -> Encoding)
-> ([Rollout] -> Value)
-> ([Rollout] -> Encoding)
-> ToJSON Rollout
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [Rollout] -> Encoding
$ctoEncodingList :: [Rollout] -> Encoding
toJSONList :: [Rollout] -> Value
$ctoJSONList :: [Rollout] -> Value
toEncoding :: Rollout -> Encoding
$ctoEncoding :: Rollout -> Encoding
toJSON :: Rollout -> Value
$ctoJSON :: Rollout -> Value
ToJSON, Int -> Rollout -> ShowS
[Rollout] -> ShowS
Rollout -> String
(Int -> Rollout -> ShowS)
-> (Rollout -> String) -> ([Rollout] -> ShowS) -> Show Rollout
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Rollout] -> ShowS
$cshowList :: [Rollout] -> ShowS
show :: Rollout -> String
$cshow :: Rollout -> String
showsPrec :: Int -> Rollout -> ShowS
$cshowsPrec :: Int -> Rollout -> ShowS
Show, Rollout -> Rollout -> Bool
(Rollout -> Rollout -> Bool)
-> (Rollout -> Rollout -> Bool) -> Eq Rollout
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Rollout -> Rollout -> Bool
$c/= :: Rollout -> Rollout -> Bool
== :: Rollout -> Rollout -> Bool
$c== :: Rollout -> Rollout -> Bool
Eq)

instance FromJSON Rollout where
    parseJSON :: Value -> Parser Rollout
parseJSON = String -> (Object -> Parser Rollout) -> Value -> Parser Rollout
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"rollout" ((Object -> Parser Rollout) -> Value -> Parser Rollout)
-> (Object -> Parser Rollout) -> Value -> Parser Rollout
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        [WeightedVariation]
variations <- Object
o Object -> Key -> Parser [WeightedVariation]
forall a. FromJSON a => Object -> Key -> Parser a
.:  Key
"variations"
        Maybe Text
bucketBy   <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"bucketBy"
        RolloutKind
kind       <- Object
o Object -> Key -> Parser (Maybe RolloutKind)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"kind" Parser (Maybe RolloutKind) -> RolloutKind -> Parser RolloutKind
forall a. Parser (Maybe a) -> a -> Parser a
.!= RolloutKind
RolloutKindRollout
        Maybe Int
seed       <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"seed"
        Rollout -> Parser Rollout
forall (f :: * -> *) a. Applicative f => a -> f a
pure Rollout :: [WeightedVariation]
-> Maybe Text -> RolloutKind -> Maybe Int -> Rollout
Rollout { [WeightedVariation]
Maybe Int
Maybe Text
RolloutKind
seed :: Maybe Int
kind :: RolloutKind
bucketBy :: Maybe Text
variations :: [WeightedVariation]
$sel:seed:Rollout :: Maybe Int
$sel:kind:Rollout :: RolloutKind
$sel:bucketBy:Rollout :: Maybe Text
$sel:variations:Rollout :: [WeightedVariation]
.. }

data VariationOrRollout = VariationOrRollout
    { VariationOrRollout -> Maybe Integer
variation :: !(Maybe Integer)
    , VariationOrRollout -> Maybe Rollout
rollout   :: !(Maybe Rollout)
    } deriving ((forall x. VariationOrRollout -> Rep VariationOrRollout x)
-> (forall x. Rep VariationOrRollout x -> VariationOrRollout)
-> Generic VariationOrRollout
forall x. Rep VariationOrRollout x -> VariationOrRollout
forall x. VariationOrRollout -> Rep VariationOrRollout x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep VariationOrRollout x -> VariationOrRollout
$cfrom :: forall x. VariationOrRollout -> Rep VariationOrRollout x
Generic, Value -> Parser [VariationOrRollout]
Value -> Parser VariationOrRollout
(Value -> Parser VariationOrRollout)
-> (Value -> Parser [VariationOrRollout])
-> FromJSON VariationOrRollout
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [VariationOrRollout]
$cparseJSONList :: Value -> Parser [VariationOrRollout]
parseJSON :: Value -> Parser VariationOrRollout
$cparseJSON :: Value -> Parser VariationOrRollout
FromJSON, [VariationOrRollout] -> Encoding
[VariationOrRollout] -> Value
VariationOrRollout -> Encoding
VariationOrRollout -> Value
(VariationOrRollout -> Value)
-> (VariationOrRollout -> Encoding)
-> ([VariationOrRollout] -> Value)
-> ([VariationOrRollout] -> Encoding)
-> ToJSON VariationOrRollout
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [VariationOrRollout] -> Encoding
$ctoEncodingList :: [VariationOrRollout] -> Encoding
toJSONList :: [VariationOrRollout] -> Value
$ctoJSONList :: [VariationOrRollout] -> Value
toEncoding :: VariationOrRollout -> Encoding
$ctoEncoding :: VariationOrRollout -> Encoding
toJSON :: VariationOrRollout -> Value
$ctoJSON :: VariationOrRollout -> Value
ToJSON, Int -> VariationOrRollout -> ShowS
[VariationOrRollout] -> ShowS
VariationOrRollout -> String
(Int -> VariationOrRollout -> ShowS)
-> (VariationOrRollout -> String)
-> ([VariationOrRollout] -> ShowS)
-> Show VariationOrRollout
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VariationOrRollout] -> ShowS
$cshowList :: [VariationOrRollout] -> ShowS
show :: VariationOrRollout -> String
$cshow :: VariationOrRollout -> String
showsPrec :: Int -> VariationOrRollout -> ShowS
$cshowsPrec :: Int -> VariationOrRollout -> ShowS
Show, VariationOrRollout -> VariationOrRollout -> Bool
(VariationOrRollout -> VariationOrRollout -> Bool)
-> (VariationOrRollout -> VariationOrRollout -> Bool)
-> Eq VariationOrRollout
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VariationOrRollout -> VariationOrRollout -> Bool
$c/= :: VariationOrRollout -> VariationOrRollout -> Bool
== :: VariationOrRollout -> VariationOrRollout -> Bool
$c== :: VariationOrRollout -> VariationOrRollout -> Bool
Eq)

data ClientSideAvailability = ClientSideAvailability
    { ClientSideAvailability -> Bool
usingEnvironmentId     :: !Bool
    , ClientSideAvailability -> Bool
usingMobileKey         :: !Bool
    , ClientSideAvailability -> Bool
explicit               :: !Bool
    } deriving ((forall x. ClientSideAvailability -> Rep ClientSideAvailability x)
-> (forall x.
    Rep ClientSideAvailability x -> ClientSideAvailability)
-> Generic ClientSideAvailability
forall x. Rep ClientSideAvailability x -> ClientSideAvailability
forall x. ClientSideAvailability -> Rep ClientSideAvailability x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ClientSideAvailability x -> ClientSideAvailability
$cfrom :: forall x. ClientSideAvailability -> Rep ClientSideAvailability x
Generic, Int -> ClientSideAvailability -> ShowS
[ClientSideAvailability] -> ShowS
ClientSideAvailability -> String
(Int -> ClientSideAvailability -> ShowS)
-> (ClientSideAvailability -> String)
-> ([ClientSideAvailability] -> ShowS)
-> Show ClientSideAvailability
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ClientSideAvailability] -> ShowS
$cshowList :: [ClientSideAvailability] -> ShowS
show :: ClientSideAvailability -> String
$cshow :: ClientSideAvailability -> String
showsPrec :: Int -> ClientSideAvailability -> ShowS
$cshowsPrec :: Int -> ClientSideAvailability -> ShowS
Show, ClientSideAvailability -> ClientSideAvailability -> Bool
(ClientSideAvailability -> ClientSideAvailability -> Bool)
-> (ClientSideAvailability -> ClientSideAvailability -> Bool)
-> Eq ClientSideAvailability
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ClientSideAvailability -> ClientSideAvailability -> Bool
$c/= :: ClientSideAvailability -> ClientSideAvailability -> Bool
== :: ClientSideAvailability -> ClientSideAvailability -> Bool
$c== :: ClientSideAvailability -> ClientSideAvailability -> Bool
Eq)

instance FromJSON ClientSideAvailability where
    parseJSON :: Value -> Parser ClientSideAvailability
parseJSON = String
-> (Object -> Parser ClientSideAvailability)
-> Value
-> Parser ClientSideAvailability
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ClientSideAvailability" ((Object -> Parser ClientSideAvailability)
 -> Value -> Parser ClientSideAvailability)
-> (Object -> Parser ClientSideAvailability)
-> Value
-> Parser ClientSideAvailability
forall a b. (a -> b) -> a -> b
$ \Object
obj -> Bool -> Bool -> Bool -> ClientSideAvailability
ClientSideAvailability
        (Bool -> Bool -> Bool -> ClientSideAvailability)
-> Parser Bool -> Parser (Bool -> Bool -> ClientSideAvailability)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"usingEnvironmentId"
        Parser (Bool -> Bool -> ClientSideAvailability)
-> Parser Bool -> Parser (Bool -> ClientSideAvailability)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"usingMobileKey"
        Parser (Bool -> ClientSideAvailability)
-> Parser Bool -> Parser ClientSideAvailability
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Bool -> Parser Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
True

instance ToJSON ClientSideAvailability where
    toJSON :: ClientSideAvailability -> Value
toJSON (ClientSideAvailability Bool
env Bool
mob Bool
_) =
        [Pair] -> Value
object [ Key
"usingEnvironmentId" Key -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Bool
env, Key
"usingMobileKey" Key -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Bool
mob ]

data Flag = Flag
    { Flag -> Text
key                    :: !Text
    , Flag -> Natural
version                :: !Natural
    , Flag -> Bool
on                     :: !Bool
    , Flag -> Bool
trackEvents            :: !Bool
    , Flag -> Bool
trackEventsFallthrough :: !Bool
    , Flag -> Bool
deleted                :: !Bool
    , Flag -> [Prerequisite]
prerequisites          :: ![Prerequisite]
    , Flag -> Text
salt                   :: !Text
    , Flag -> [Target]
targets                :: ![Target]
    , Flag -> [Rule]
rules                  :: ![Rule]
    , Flag -> VariationOrRollout
fallthrough            :: !VariationOrRollout
    , Flag -> Maybe Integer
offVariation           :: !(Maybe Integer)
    , Flag -> [Value]
variations             :: ![Value]
    , Flag -> Maybe Natural
debugEventsUntilDate   :: !(Maybe Natural)
    , Flag -> ClientSideAvailability
clientSideAvailability :: !ClientSideAvailability
    } deriving ((forall x. Flag -> Rep Flag x)
-> (forall x. Rep Flag x -> Flag) -> Generic Flag
forall x. Rep Flag x -> Flag
forall x. Flag -> Rep Flag x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Flag x -> Flag
$cfrom :: forall x. Flag -> Rep Flag x
Generic, Int -> Flag -> ShowS
[Flag] -> ShowS
Flag -> String
(Int -> Flag -> ShowS)
-> (Flag -> String) -> ([Flag] -> ShowS) -> Show Flag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Flag] -> ShowS
$cshowList :: [Flag] -> ShowS
show :: Flag -> String
$cshow :: Flag -> String
showsPrec :: Int -> Flag -> ShowS
$cshowsPrec :: Int -> Flag -> ShowS
Show, Flag -> Flag -> Bool
(Flag -> Flag -> Bool) -> (Flag -> Flag -> Bool) -> Eq Flag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Flag -> Flag -> Bool
$c/= :: Flag -> Flag -> Bool
== :: Flag -> Flag -> Bool
$c== :: Flag -> Flag -> Bool
Eq)

instance ToJSON Flag where
    toJSON :: Flag -> Value
toJSON Flag
flag = [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
        [ Key
"key" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Flag -> Text
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"key" Flag
flag
        , Key
"version" Key -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Flag -> Natural
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"version" Flag
flag
        , Key
"on" Key -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Flag -> Bool
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"on" Flag
flag
        , Key
"trackEvents" Key -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Flag -> Bool
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"trackEvents" Flag
flag
        , Key
"trackEventsFallthrough" Key -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Flag -> Bool
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"trackEventsFallthrough" Flag
flag
        , Key
"deleted" Key -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Flag -> Bool
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"deleted" Flag
flag
        , Key
"prerequisites" Key -> [Prerequisite] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Flag -> [Prerequisite]
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"prerequisites" Flag
flag
        , Key
"salt" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Flag -> Text
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"salt" Flag
flag
        , Key
"targets" Key -> [Target] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Flag -> [Target]
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"targets" Flag
flag
        , Key
"rules" Key -> [Rule] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Flag -> [Rule]
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"rules" Flag
flag
        , Key
"fallthrough" Key -> VariationOrRollout -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Flag -> VariationOrRollout
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"fallthrough" Flag
flag
        , Key
"offVariation" Key -> Maybe Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Flag -> Maybe Integer
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"offVariation" Flag
flag
        , Key
"variations" Key -> [Value] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Flag -> [Value]
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"variations" Flag
flag
        , Key
"debugEventsUntilDate" Key -> Maybe Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Flag -> Maybe Natural
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"debugEventsUntilDate" Flag
flag
        , Key
"clientSide" Key -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= (forall a s. HasField' "usingEnvironmentId" s a => s -> a
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"usingEnvironmentId" (ClientSideAvailability -> Bool) -> ClientSideAvailability -> Bool
forall a b. (a -> b) -> a -> b
$ Flag -> ClientSideAvailability
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"clientSideAvailability" Flag
flag)
        ] [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> case forall a s. HasField' "explicit" s a => s -> a
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"explicit" (ClientSideAvailability -> Bool) -> ClientSideAvailability -> Bool
forall a b. (a -> b) -> a -> b
$ Flag -> ClientSideAvailability
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"clientSideAvailability" Flag
flag of
               Bool
True -> [ Key
"clientSideAvailability" Key -> ClientSideAvailability -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Flag -> ClientSideAvailability
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"clientSideAvailability" Flag
flag ]
               Bool
False -> [ ]

instance FromJSON Flag where
    parseJSON :: Value -> Parser Flag
parseJSON = String -> (Object -> Parser Flag) -> Value -> Parser Flag
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Flag" ((Object -> Parser Flag) -> Value -> Parser Flag)
-> (Object -> Parser Flag) -> Value -> Parser Flag
forall a b. (a -> b) -> a -> b
$ \Object
obj -> do
        Text
key <- Object
obj Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"key"
        Natural
version <- Object
obj Object -> Key -> Parser Natural
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"version"
        Bool
on <- Object
obj Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"on"
        Bool
trackEvents <- Object
obj Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"trackEvents"
        Bool
trackEventsFallthrough <- Object
obj Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"trackEventsFallthrough"
        Bool
deleted <- Object
obj Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"deleted"
        [Prerequisite]
prerequisites <- Object
obj Object -> Key -> Parser [Prerequisite]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"prerequisites"
        Text
salt <- Object
obj Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"salt"
        [Target]
targets <- Object
obj Object -> Key -> Parser [Target]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"targets"
        [Rule]
rules <- Object
obj Object -> Key -> Parser [Rule]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"rules"
        VariationOrRollout
fallthrough <- Object
obj Object -> Key -> Parser VariationOrRollout
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"fallthrough"
        Maybe Integer
offVariation <- Object
obj Object -> Key -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"offVariation"
        [Value]
variations <- Object
obj Object -> Key -> Parser [Value]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"variations"
        Maybe Natural
debugEventsUntilDate <- Object
obj Object -> Key -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"debugEventsUntilDate"
        Bool
clientSide <- Object
obj Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"clientSide" Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
False
        ClientSideAvailability
clientSideAvailability <- Object
obj Object -> Key -> Parser (Maybe ClientSideAvailability)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"clientSideAvailability" Parser (Maybe ClientSideAvailability)
-> ClientSideAvailability -> Parser ClientSideAvailability
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool -> Bool -> Bool -> ClientSideAvailability
ClientSideAvailability Bool
clientSide Bool
True Bool
False
        Flag -> Parser Flag
forall (f :: * -> *) a. Applicative f => a -> f a
pure Flag :: Text
-> Natural
-> Bool
-> Bool
-> Bool
-> Bool
-> [Prerequisite]
-> Text
-> [Target]
-> [Rule]
-> VariationOrRollout
-> Maybe Integer
-> [Value]
-> Maybe Natural
-> ClientSideAvailability
-> Flag
Flag { Bool
Natural
[Value]
[Prerequisite]
[Rule]
[Target]
Maybe Integer
Maybe Natural
Text
ClientSideAvailability
VariationOrRollout
clientSideAvailability :: ClientSideAvailability
debugEventsUntilDate :: Maybe Natural
variations :: [Value]
offVariation :: Maybe Integer
fallthrough :: VariationOrRollout
rules :: [Rule]
targets :: [Target]
salt :: Text
prerequisites :: [Prerequisite]
deleted :: Bool
trackEventsFallthrough :: Bool
trackEvents :: Bool
on :: Bool
version :: Natural
key :: Text
$sel:clientSideAvailability:Flag :: ClientSideAvailability
$sel:debugEventsUntilDate:Flag :: Maybe Natural
$sel:variations:Flag :: [Value]
$sel:offVariation:Flag :: Maybe Integer
$sel:fallthrough:Flag :: VariationOrRollout
$sel:rules:Flag :: [Rule]
$sel:targets:Flag :: [Target]
$sel:salt:Flag :: Text
$sel:prerequisites:Flag :: [Prerequisite]
$sel:deleted:Flag :: Bool
$sel:trackEventsFallthrough:Flag :: Bool
$sel:trackEvents:Flag :: Bool
$sel:on:Flag :: Bool
$sel:version:Flag :: Natural
$sel:key:Flag :: Text
.. }

isClientSideOnlyFlag :: Flag -> Bool
isClientSideOnlyFlag :: Flag -> Bool
isClientSideOnlyFlag Flag
flag = forall a s. HasField' "usingEnvironmentId" s a => s -> a
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"usingEnvironmentId" (ClientSideAvailability -> Bool) -> ClientSideAvailability -> Bool
forall a b. (a -> b) -> a -> b
$ Flag -> ClientSideAvailability
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField  @"clientSideAvailability" Flag
flag

-- If the reason for the flag is in an experiment,
-- or if it's a fallthrough reason and the flag has trackEventsFallthrough
-- or if it's a rule match and the rule that matched has track events turned on
-- otherwise false
isInExperiment :: Flag -> EvaluationReason -> Bool
isInExperiment :: Flag -> EvaluationReason -> Bool
isInExperiment Flag
_ EvaluationReason
reason
  | EvaluationReason -> Bool
D.isInExperiment EvaluationReason
reason = Bool
True
isInExperiment Flag
flag EvaluationReasonFallthrough {Bool
$sel:inExperiment:EvaluationReasonOff :: EvaluationReason -> Bool
inExperiment :: Bool
..} = Flag -> Bool
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"trackEventsFallthrough" Flag
flag
isInExperiment Flag
flag (EvaluationReasonRuleMatch Natural
ruleIndex Text
_ Bool
_) =
    let index :: Int
index = Natural -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Natural
ruleIndex
        rules :: [Rule]
rules = Flag -> [Rule]
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"rules" Flag
flag
        rule :: Maybe Rule
rule = [Rule]
rules [Rule] -> Getting (First Rule) [Rule] Rule -> Maybe Rule
forall s a. s -> Getting (First a) s a -> Maybe a
^? Int -> IndexedTraversal' Int [Rule] Rule
forall (t :: * -> *) a.
Traversable t =>
Int -> IndexedTraversal' Int (t a) a
element Int
index
    in Bool -> Maybe Bool -> Bool
forall a. a -> Maybe a -> a
fromMaybe Bool
False (Maybe Bool -> Bool) -> Maybe Bool -> Bool
forall a b. (a -> b) -> a -> b
$ (Rule -> Bool) -> Maybe Rule -> Maybe Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a s. HasField' "trackEvents" s a => s -> a
forall (f :: Symbol) a s. HasField' f s a => s -> a
getField @"trackEvents") Maybe Rule
rule
isInExperiment Flag
_ EvaluationReason
_ = Bool
False

data Prerequisite = Prerequisite
    { Prerequisite -> Text
key       :: !Text
    , Prerequisite -> Integer
variation :: !Integer
    } deriving ((forall x. Prerequisite -> Rep Prerequisite x)
-> (forall x. Rep Prerequisite x -> Prerequisite)
-> Generic Prerequisite
forall x. Rep Prerequisite x -> Prerequisite
forall x. Prerequisite -> Rep Prerequisite x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Prerequisite x -> Prerequisite
$cfrom :: forall x. Prerequisite -> Rep Prerequisite x
Generic, Value -> Parser [Prerequisite]
Value -> Parser Prerequisite
(Value -> Parser Prerequisite)
-> (Value -> Parser [Prerequisite]) -> FromJSON Prerequisite
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [Prerequisite]
$cparseJSONList :: Value -> Parser [Prerequisite]
parseJSON :: Value -> Parser Prerequisite
$cparseJSON :: Value -> Parser Prerequisite
FromJSON, [Prerequisite] -> Encoding
[Prerequisite] -> Value
Prerequisite -> Encoding
Prerequisite -> Value
(Prerequisite -> Value)
-> (Prerequisite -> Encoding)
-> ([Prerequisite] -> Value)
-> ([Prerequisite] -> Encoding)
-> ToJSON Prerequisite
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [Prerequisite] -> Encoding
$ctoEncodingList :: [Prerequisite] -> Encoding
toJSONList :: [Prerequisite] -> Value
$ctoJSONList :: [Prerequisite] -> Value
toEncoding :: Prerequisite -> Encoding
$ctoEncoding :: Prerequisite -> Encoding
toJSON :: Prerequisite -> Value
$ctoJSON :: Prerequisite -> Value
ToJSON, Int -> Prerequisite -> ShowS
[Prerequisite] -> ShowS
Prerequisite -> String
(Int -> Prerequisite -> ShowS)
-> (Prerequisite -> String)
-> ([Prerequisite] -> ShowS)
-> Show Prerequisite
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Prerequisite] -> ShowS
$cshowList :: [Prerequisite] -> ShowS
show :: Prerequisite -> String
$cshow :: Prerequisite -> String
showsPrec :: Int -> Prerequisite -> ShowS
$cshowsPrec :: Int -> Prerequisite -> ShowS
Show, Prerequisite -> Prerequisite -> Bool
(Prerequisite -> Prerequisite -> Bool)
-> (Prerequisite -> Prerequisite -> Bool) -> Eq Prerequisite
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Prerequisite -> Prerequisite -> Bool
$c/= :: Prerequisite -> Prerequisite -> Bool
== :: Prerequisite -> Prerequisite -> Bool
$c== :: Prerequisite -> Prerequisite -> Bool
Eq)

data SegmentRule = SegmentRule
    { SegmentRule -> Text
id       :: !Text
    , SegmentRule -> [Clause]
clauses  :: ![Clause]
    , SegmentRule -> Maybe Float
weight   :: !(Maybe Float)
    , SegmentRule -> Maybe Text
bucketBy :: !(Maybe Text)
    } deriving ((forall x. SegmentRule -> Rep SegmentRule x)
-> (forall x. Rep SegmentRule x -> SegmentRule)
-> Generic SegmentRule
forall x. Rep SegmentRule x -> SegmentRule
forall x. SegmentRule -> Rep SegmentRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SegmentRule x -> SegmentRule
$cfrom :: forall x. SegmentRule -> Rep SegmentRule x
Generic, Value -> Parser [SegmentRule]
Value -> Parser SegmentRule
(Value -> Parser SegmentRule)
-> (Value -> Parser [SegmentRule]) -> FromJSON SegmentRule
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [SegmentRule]
$cparseJSONList :: Value -> Parser [SegmentRule]
parseJSON :: Value -> Parser SegmentRule
$cparseJSON :: Value -> Parser SegmentRule
FromJSON, [SegmentRule] -> Encoding
[SegmentRule] -> Value
SegmentRule -> Encoding
SegmentRule -> Value
(SegmentRule -> Value)
-> (SegmentRule -> Encoding)
-> ([SegmentRule] -> Value)
-> ([SegmentRule] -> Encoding)
-> ToJSON SegmentRule
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [SegmentRule] -> Encoding
$ctoEncodingList :: [SegmentRule] -> Encoding
toJSONList :: [SegmentRule] -> Value
$ctoJSONList :: [SegmentRule] -> Value
toEncoding :: SegmentRule -> Encoding
$ctoEncoding :: SegmentRule -> Encoding
toJSON :: SegmentRule -> Value
$ctoJSON :: SegmentRule -> Value
ToJSON, Int -> SegmentRule -> ShowS
[SegmentRule] -> ShowS
SegmentRule -> String
(Int -> SegmentRule -> ShowS)
-> (SegmentRule -> String)
-> ([SegmentRule] -> ShowS)
-> Show SegmentRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SegmentRule] -> ShowS
$cshowList :: [SegmentRule] -> ShowS
show :: SegmentRule -> String
$cshow :: SegmentRule -> String
showsPrec :: Int -> SegmentRule -> ShowS
$cshowsPrec :: Int -> SegmentRule -> ShowS
Show, SegmentRule -> SegmentRule -> Bool
(SegmentRule -> SegmentRule -> Bool)
-> (SegmentRule -> SegmentRule -> Bool) -> Eq SegmentRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SegmentRule -> SegmentRule -> Bool
$c/= :: SegmentRule -> SegmentRule -> Bool
== :: SegmentRule -> SegmentRule -> Bool
$c== :: SegmentRule -> SegmentRule -> Bool
Eq)

data Segment = Segment
    { Segment -> Text
key      :: !Text
    , Segment -> HashSet Text
included :: !(HashSet Text)
    , Segment -> HashSet Text
excluded :: !(HashSet Text)
    , Segment -> Text
salt     :: !Text
    , Segment -> [SegmentRule]
rules    :: ![SegmentRule]
    , Segment -> Natural
version  :: !Natural
    , Segment -> Bool
deleted  :: !Bool
    } deriving ((forall x. Segment -> Rep Segment x)
-> (forall x. Rep Segment x -> Segment) -> Generic Segment
forall x. Rep Segment x -> Segment
forall x. Segment -> Rep Segment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Segment x -> Segment
$cfrom :: forall x. Segment -> Rep Segment x
Generic, Value -> Parser [Segment]
Value -> Parser Segment
(Value -> Parser Segment)
-> (Value -> Parser [Segment]) -> FromJSON Segment
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [Segment]
$cparseJSONList :: Value -> Parser [Segment]
parseJSON :: Value -> Parser Segment
$cparseJSON :: Value -> Parser Segment
FromJSON, [Segment] -> Encoding
[Segment] -> Value
Segment -> Encoding
Segment -> Value
(Segment -> Value)
-> (Segment -> Encoding)
-> ([Segment] -> Value)
-> ([Segment] -> Encoding)
-> ToJSON Segment
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [Segment] -> Encoding
$ctoEncodingList :: [Segment] -> Encoding
toJSONList :: [Segment] -> Value
$ctoJSONList :: [Segment] -> Value
toEncoding :: Segment -> Encoding
$ctoEncoding :: Segment -> Encoding
toJSON :: Segment -> Value
$ctoJSON :: Segment -> Value
ToJSON, Int -> Segment -> ShowS
[Segment] -> ShowS
Segment -> String
(Int -> Segment -> ShowS)
-> (Segment -> String) -> ([Segment] -> ShowS) -> Show Segment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Segment] -> ShowS
$cshowList :: [Segment] -> ShowS
show :: Segment -> String
$cshow :: Segment -> String
showsPrec :: Int -> Segment -> ShowS
$cshowsPrec :: Int -> Segment -> ShowS
Show, Segment -> Segment -> Bool
(Segment -> Segment -> Bool)
-> (Segment -> Segment -> Bool) -> Eq Segment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Segment -> Segment -> Bool
$c/= :: Segment -> Segment -> Bool
== :: Segment -> Segment -> Bool
$c== :: Segment -> Segment -> Bool
Eq)

data Clause = Clause
    { Clause -> Text
attribute :: !Text
    , Clause -> Bool
negate    :: !Bool
    , Clause -> Op
op        :: !Op
    , Clause -> [Value]
values    :: ![Value]
    } deriving ((forall x. Clause -> Rep Clause x)
-> (forall x. Rep Clause x -> Clause) -> Generic Clause
forall x. Rep Clause x -> Clause
forall x. Clause -> Rep Clause x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Clause x -> Clause
$cfrom :: forall x. Clause -> Rep Clause x
Generic, Value -> Parser [Clause]
Value -> Parser Clause
(Value -> Parser Clause)
-> (Value -> Parser [Clause]) -> FromJSON Clause
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [Clause]
$cparseJSONList :: Value -> Parser [Clause]
parseJSON :: Value -> Parser Clause
$cparseJSON :: Value -> Parser Clause
FromJSON, [Clause] -> Encoding
[Clause] -> Value
Clause -> Encoding
Clause -> Value
(Clause -> Value)
-> (Clause -> Encoding)
-> ([Clause] -> Value)
-> ([Clause] -> Encoding)
-> ToJSON Clause
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [Clause] -> Encoding
$ctoEncodingList :: [Clause] -> Encoding
toJSONList :: [Clause] -> Value
$ctoJSONList :: [Clause] -> Value
toEncoding :: Clause -> Encoding
$ctoEncoding :: Clause -> Encoding
toJSON :: Clause -> Value
$ctoJSON :: Clause -> Value
ToJSON, Int -> Clause -> ShowS
[Clause] -> ShowS
Clause -> String
(Int -> Clause -> ShowS)
-> (Clause -> String) -> ([Clause] -> ShowS) -> Show Clause
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Clause] -> ShowS
$cshowList :: [Clause] -> ShowS
show :: Clause -> String
$cshow :: Clause -> String
showsPrec :: Int -> Clause -> ShowS
$cshowsPrec :: Int -> Clause -> ShowS
Show, Clause -> Clause -> Bool
(Clause -> Clause -> Bool)
-> (Clause -> Clause -> Bool) -> Eq Clause
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Clause -> Clause -> Bool
$c/= :: Clause -> Clause -> Bool
== :: Clause -> Clause -> Bool
$c== :: Clause -> Clause -> Bool
Eq)