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