module TD.Data.InputChecklistTask
( InputChecklistTask(..)
, defaultInputChecklistTask
) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.FormattedText as FormattedText
data InputChecklistTask
= InputChecklistTask
{ InputChecklistTask -> Maybe Int
_id :: Maybe Int
, InputChecklistTask -> Maybe FormattedText
text :: Maybe FormattedText.FormattedText
}
deriving (InputChecklistTask -> InputChecklistTask -> Bool
(InputChecklistTask -> InputChecklistTask -> Bool)
-> (InputChecklistTask -> InputChecklistTask -> Bool)
-> Eq InputChecklistTask
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputChecklistTask -> InputChecklistTask -> Bool
== :: InputChecklistTask -> InputChecklistTask -> Bool
$c/= :: InputChecklistTask -> InputChecklistTask -> Bool
/= :: InputChecklistTask -> InputChecklistTask -> Bool
Eq, Int -> InputChecklistTask -> ShowS
[InputChecklistTask] -> ShowS
InputChecklistTask -> String
(Int -> InputChecklistTask -> ShowS)
-> (InputChecklistTask -> String)
-> ([InputChecklistTask] -> ShowS)
-> Show InputChecklistTask
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputChecklistTask -> ShowS
showsPrec :: Int -> InputChecklistTask -> ShowS
$cshow :: InputChecklistTask -> String
show :: InputChecklistTask -> String
$cshowList :: [InputChecklistTask] -> ShowS
showList :: [InputChecklistTask] -> ShowS
Show)
instance I.ShortShow InputChecklistTask where
shortShow :: InputChecklistTask -> String
shortShow InputChecklistTask
{ _id :: InputChecklistTask -> Maybe Int
_id = Maybe Int
_id_
, text :: InputChecklistTask -> Maybe FormattedText
text = Maybe FormattedText
text_
}
= String
"InputChecklistTask"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
_id_
, String
"text" String -> Maybe FormattedText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe FormattedText
text_
]
instance AT.FromJSON InputChecklistTask where
parseJSON :: Value -> Parser InputChecklistTask
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
"inputChecklistTask" -> Value -> Parser InputChecklistTask
parseInputChecklistTask Value
v
String
_ -> Parser InputChecklistTask
forall a. Monoid a => a
mempty
where
parseInputChecklistTask :: A.Value -> AT.Parser InputChecklistTask
parseInputChecklistTask :: Value -> Parser InputChecklistTask
parseInputChecklistTask = String
-> (Object -> Parser InputChecklistTask)
-> Value
-> Parser InputChecklistTask
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputChecklistTask" ((Object -> Parser InputChecklistTask)
-> Value -> Parser InputChecklistTask)
-> (Object -> Parser InputChecklistTask)
-> Value
-> Parser InputChecklistTask
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"id"
Maybe FormattedText
text_ <- Object
o Object -> Key -> Parser (Maybe FormattedText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"text"
InputChecklistTask -> Parser InputChecklistTask
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputChecklistTask -> Parser InputChecklistTask)
-> InputChecklistTask -> Parser InputChecklistTask
forall a b. (a -> b) -> a -> b
$ InputChecklistTask
{ _id :: Maybe Int
_id = Maybe Int
_id_
, text :: Maybe FormattedText
text = Maybe FormattedText
text_
}
parseJSON Value
_ = Parser InputChecklistTask
forall a. Monoid a => a
mempty
instance AT.ToJSON InputChecklistTask where
toJSON :: InputChecklistTask -> Value
toJSON InputChecklistTask
{ _id :: InputChecklistTask -> Maybe Int
_id = Maybe Int
_id_
, text :: InputChecklistTask -> Maybe FormattedText
text = Maybe FormattedText
text_
}
= [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
"inputChecklistTask"
, Key
"id" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
_id_
, Key
"text" Key -> Maybe FormattedText -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe FormattedText
text_
]
defaultInputChecklistTask :: InputChecklistTask
defaultInputChecklistTask :: InputChecklistTask
defaultInputChecklistTask =
InputChecklistTask
{ _id :: Maybe Int
_id = Maybe Int
forall a. Maybe a
Nothing
, text :: Maybe FormattedText
text = Maybe FormattedText
forall a. Maybe a
Nothing
}