module TD.Data.MessageSchedulingState
(MessageSchedulingState(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
data MessageSchedulingState
= MessageSchedulingStateSendAtDate
{ MessageSchedulingState -> Maybe Int
send_date :: Maybe Int
}
| MessageSchedulingStateSendWhenOnline
| MessageSchedulingStateSendWhenVideoProcessed
{ send_date :: Maybe Int
}
deriving (MessageSchedulingState -> MessageSchedulingState -> Bool
(MessageSchedulingState -> MessageSchedulingState -> Bool)
-> (MessageSchedulingState -> MessageSchedulingState -> Bool)
-> Eq MessageSchedulingState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MessageSchedulingState -> MessageSchedulingState -> Bool
== :: MessageSchedulingState -> MessageSchedulingState -> Bool
$c/= :: MessageSchedulingState -> MessageSchedulingState -> Bool
/= :: MessageSchedulingState -> MessageSchedulingState -> Bool
Eq, Int -> MessageSchedulingState -> ShowS
[MessageSchedulingState] -> ShowS
MessageSchedulingState -> String
(Int -> MessageSchedulingState -> ShowS)
-> (MessageSchedulingState -> String)
-> ([MessageSchedulingState] -> ShowS)
-> Show MessageSchedulingState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageSchedulingState -> ShowS
showsPrec :: Int -> MessageSchedulingState -> ShowS
$cshow :: MessageSchedulingState -> String
show :: MessageSchedulingState -> String
$cshowList :: [MessageSchedulingState] -> ShowS
showList :: [MessageSchedulingState] -> ShowS
Show)
instance I.ShortShow MessageSchedulingState where
shortShow :: MessageSchedulingState -> String
shortShow MessageSchedulingStateSendAtDate
{ send_date :: MessageSchedulingState -> Maybe Int
send_date = Maybe Int
send_date_
}
= String
"MessageSchedulingStateSendAtDate"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"send_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
send_date_
]
shortShow MessageSchedulingState
MessageSchedulingStateSendWhenOnline
= String
"MessageSchedulingStateSendWhenOnline"
shortShow MessageSchedulingStateSendWhenVideoProcessed
{ send_date :: MessageSchedulingState -> Maybe Int
send_date = Maybe Int
send_date_
}
= String
"MessageSchedulingStateSendWhenVideoProcessed"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"send_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
send_date_
]
instance AT.FromJSON MessageSchedulingState where
parseJSON :: Value -> Parser MessageSchedulingState
parseJSON v :: Value
v@(AT.Object Object
obj) = do
String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String
case String
t of
String
"messageSchedulingStateSendAtDate" -> Value -> Parser MessageSchedulingState
parseMessageSchedulingStateSendAtDate Value
v
String
"messageSchedulingStateSendWhenOnline" -> MessageSchedulingState -> Parser MessageSchedulingState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageSchedulingState
MessageSchedulingStateSendWhenOnline
String
"messageSchedulingStateSendWhenVideoProcessed" -> Value -> Parser MessageSchedulingState
parseMessageSchedulingStateSendWhenVideoProcessed Value
v
String
_ -> Parser MessageSchedulingState
forall a. Monoid a => a
mempty
where
parseMessageSchedulingStateSendAtDate :: A.Value -> AT.Parser MessageSchedulingState
parseMessageSchedulingStateSendAtDate :: Value -> Parser MessageSchedulingState
parseMessageSchedulingStateSendAtDate = String
-> (Object -> Parser MessageSchedulingState)
-> Value
-> Parser MessageSchedulingState
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MessageSchedulingStateSendAtDate" ((Object -> Parser MessageSchedulingState)
-> Value -> Parser MessageSchedulingState)
-> (Object -> Parser MessageSchedulingState)
-> Value
-> Parser MessageSchedulingState
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
send_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"send_date"
MessageSchedulingState -> Parser MessageSchedulingState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MessageSchedulingState -> Parser MessageSchedulingState)
-> MessageSchedulingState -> Parser MessageSchedulingState
forall a b. (a -> b) -> a -> b
$ MessageSchedulingStateSendAtDate
{ send_date :: Maybe Int
send_date = Maybe Int
send_date_
}
parseMessageSchedulingStateSendWhenVideoProcessed :: A.Value -> AT.Parser MessageSchedulingState
parseMessageSchedulingStateSendWhenVideoProcessed :: Value -> Parser MessageSchedulingState
parseMessageSchedulingStateSendWhenVideoProcessed = String
-> (Object -> Parser MessageSchedulingState)
-> Value
-> Parser MessageSchedulingState
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MessageSchedulingStateSendWhenVideoProcessed" ((Object -> Parser MessageSchedulingState)
-> Value -> Parser MessageSchedulingState)
-> (Object -> Parser MessageSchedulingState)
-> Value
-> Parser MessageSchedulingState
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
send_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"send_date"
MessageSchedulingState -> Parser MessageSchedulingState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MessageSchedulingState -> Parser MessageSchedulingState)
-> MessageSchedulingState -> Parser MessageSchedulingState
forall a b. (a -> b) -> a -> b
$ MessageSchedulingStateSendWhenVideoProcessed
{ send_date :: Maybe Int
send_date = Maybe Int
send_date_
}
parseJSON Value
_ = Parser MessageSchedulingState
forall a. Monoid a => a
mempty
instance AT.ToJSON MessageSchedulingState where
toJSON :: MessageSchedulingState -> Value
toJSON MessageSchedulingStateSendAtDate
{ send_date :: MessageSchedulingState -> Maybe Int
send_date = Maybe Int
send_date_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"messageSchedulingStateSendAtDate"
, Key
"send_date" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
send_date_
]
toJSON MessageSchedulingState
MessageSchedulingStateSendWhenOnline
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"messageSchedulingStateSendWhenOnline"
]
toJSON MessageSchedulingStateSendWhenVideoProcessed
{ send_date :: MessageSchedulingState -> Maybe Int
send_date = Maybe Int
send_date_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"messageSchedulingStateSendWhenVideoProcessed"
, Key
"send_date" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
send_date_
]