module TD.Data.InputChatTheme
(InputChatTheme(..)) 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 InputChatTheme
= InputChatThemeEmoji
{ InputChatTheme -> Maybe Text
name :: Maybe T.Text
}
| InputChatThemeGift
{ name :: Maybe T.Text
}
deriving (InputChatTheme -> InputChatTheme -> Bool
(InputChatTheme -> InputChatTheme -> Bool)
-> (InputChatTheme -> InputChatTheme -> Bool) -> Eq InputChatTheme
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputChatTheme -> InputChatTheme -> Bool
== :: InputChatTheme -> InputChatTheme -> Bool
$c/= :: InputChatTheme -> InputChatTheme -> Bool
/= :: InputChatTheme -> InputChatTheme -> Bool
Eq, Int -> InputChatTheme -> ShowS
[InputChatTheme] -> ShowS
InputChatTheme -> String
(Int -> InputChatTheme -> ShowS)
-> (InputChatTheme -> String)
-> ([InputChatTheme] -> ShowS)
-> Show InputChatTheme
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputChatTheme -> ShowS
showsPrec :: Int -> InputChatTheme -> ShowS
$cshow :: InputChatTheme -> String
show :: InputChatTheme -> String
$cshowList :: [InputChatTheme] -> ShowS
showList :: [InputChatTheme] -> ShowS
Show)
instance I.ShortShow InputChatTheme where
shortShow :: InputChatTheme -> String
shortShow InputChatThemeEmoji
{ name :: InputChatTheme -> Maybe Text
name = Maybe Text
name_
}
= String
"InputChatThemeEmoji"
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 InputChatThemeGift
{ name :: InputChatTheme -> Maybe Text
name = Maybe Text
name_
}
= String
"InputChatThemeGift"
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_
]
instance AT.FromJSON InputChatTheme where
parseJSON :: Value -> Parser InputChatTheme
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
"inputChatThemeEmoji" -> Value -> Parser InputChatTheme
parseInputChatThemeEmoji Value
v
String
"inputChatThemeGift" -> Value -> Parser InputChatTheme
parseInputChatThemeGift Value
v
String
_ -> Parser InputChatTheme
forall a. Monoid a => a
mempty
where
parseInputChatThemeEmoji :: A.Value -> AT.Parser InputChatTheme
parseInputChatThemeEmoji :: Value -> Parser InputChatTheme
parseInputChatThemeEmoji = String
-> (Object -> Parser InputChatTheme)
-> Value
-> Parser InputChatTheme
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputChatThemeEmoji" ((Object -> Parser InputChatTheme)
-> Value -> Parser InputChatTheme)
-> (Object -> Parser InputChatTheme)
-> Value
-> Parser InputChatTheme
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"
InputChatTheme -> Parser InputChatTheme
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputChatTheme -> Parser InputChatTheme)
-> InputChatTheme -> Parser InputChatTheme
forall a b. (a -> b) -> a -> b
$ InputChatThemeEmoji
{ name :: Maybe Text
name = Maybe Text
name_
}
parseInputChatThemeGift :: A.Value -> AT.Parser InputChatTheme
parseInputChatThemeGift :: Value -> Parser InputChatTheme
parseInputChatThemeGift = String
-> (Object -> Parser InputChatTheme)
-> Value
-> Parser InputChatTheme
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputChatThemeGift" ((Object -> Parser InputChatTheme)
-> Value -> Parser InputChatTheme)
-> (Object -> Parser InputChatTheme)
-> Value
-> Parser InputChatTheme
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"
InputChatTheme -> Parser InputChatTheme
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputChatTheme -> Parser InputChatTheme)
-> InputChatTheme -> Parser InputChatTheme
forall a b. (a -> b) -> a -> b
$ InputChatThemeGift
{ name :: Maybe Text
name = Maybe Text
name_
}
parseJSON Value
_ = Parser InputChatTheme
forall a. Monoid a => a
mempty
instance AT.ToJSON InputChatTheme where
toJSON :: InputChatTheme -> Value
toJSON InputChatThemeEmoji
{ name :: InputChatTheme -> Maybe Text
name = Maybe Text
name_
}
= [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
"inputChatThemeEmoji"
, Key
"name" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
name_
]
toJSON InputChatThemeGift
{ name :: InputChatTheme -> Maybe Text
name = Maybe Text
name_
}
= [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
"inputChatThemeGift"
, Key
"name" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
name_
]