module TD.Data.MessageFileType
(MessageFileType(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T
data MessageFileType
= MessageFileTypePrivate
{ MessageFileType -> Maybe Text
name :: Maybe T.Text
}
| MessageFileTypeGroup
{ MessageFileType -> Maybe Text
title :: Maybe T.Text
}
| MessageFileTypeUnknown
deriving (MessageFileType -> MessageFileType -> Bool
(MessageFileType -> MessageFileType -> Bool)
-> (MessageFileType -> MessageFileType -> Bool)
-> Eq MessageFileType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MessageFileType -> MessageFileType -> Bool
== :: MessageFileType -> MessageFileType -> Bool
$c/= :: MessageFileType -> MessageFileType -> Bool
/= :: MessageFileType -> MessageFileType -> Bool
Eq, Int -> MessageFileType -> ShowS
[MessageFileType] -> ShowS
MessageFileType -> String
(Int -> MessageFileType -> ShowS)
-> (MessageFileType -> String)
-> ([MessageFileType] -> ShowS)
-> Show MessageFileType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageFileType -> ShowS
showsPrec :: Int -> MessageFileType -> ShowS
$cshow :: MessageFileType -> String
show :: MessageFileType -> String
$cshowList :: [MessageFileType] -> ShowS
showList :: [MessageFileType] -> ShowS
Show)
instance I.ShortShow MessageFileType where
shortShow :: MessageFileType -> String
shortShow MessageFileTypePrivate
{ name :: MessageFileType -> Maybe Text
name = Maybe Text
name_
}
= String
"MessageFileTypePrivate"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"name" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
name_
]
shortShow MessageFileTypeGroup
{ title :: MessageFileType -> Maybe Text
title = Maybe Text
title_
}
= String
"MessageFileTypeGroup"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"title" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
]
shortShow MessageFileType
MessageFileTypeUnknown
= String
"MessageFileTypeUnknown"
instance AT.FromJSON MessageFileType where
parseJSON :: Value -> Parser MessageFileType
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
"messageFileTypePrivate" -> Value -> Parser MessageFileType
parseMessageFileTypePrivate Value
v
String
"messageFileTypeGroup" -> Value -> Parser MessageFileType
parseMessageFileTypeGroup Value
v
String
"messageFileTypeUnknown" -> MessageFileType -> Parser MessageFileType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageFileType
MessageFileTypeUnknown
String
_ -> Parser MessageFileType
forall a. Monoid a => a
mempty
where
parseMessageFileTypePrivate :: A.Value -> AT.Parser MessageFileType
parseMessageFileTypePrivate :: Value -> Parser MessageFileType
parseMessageFileTypePrivate = String
-> (Object -> Parser MessageFileType)
-> Value
-> Parser MessageFileType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MessageFileTypePrivate" ((Object -> Parser MessageFileType)
-> Value -> Parser MessageFileType)
-> (Object -> Parser MessageFileType)
-> Value
-> Parser MessageFileType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
name_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"name"
MessageFileType -> Parser MessageFileType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MessageFileType -> Parser MessageFileType)
-> MessageFileType -> Parser MessageFileType
forall a b. (a -> b) -> a -> b
$ MessageFileTypePrivate
{ name :: Maybe Text
name = Maybe Text
name_
}
parseMessageFileTypeGroup :: A.Value -> AT.Parser MessageFileType
parseMessageFileTypeGroup :: Value -> Parser MessageFileType
parseMessageFileTypeGroup = String
-> (Object -> Parser MessageFileType)
-> Value
-> Parser MessageFileType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MessageFileTypeGroup" ((Object -> Parser MessageFileType)
-> Value -> Parser MessageFileType)
-> (Object -> Parser MessageFileType)
-> Value
-> Parser MessageFileType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
title_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"title"
MessageFileType -> Parser MessageFileType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MessageFileType -> Parser MessageFileType)
-> MessageFileType -> Parser MessageFileType
forall a b. (a -> b) -> a -> b
$ MessageFileTypeGroup
{ title :: Maybe Text
title = Maybe Text
title_
}
parseJSON Value
_ = Parser MessageFileType
forall a. Monoid a => a
mempty