module TD.Data.InlineQueryResultsButton
  ( InlineQueryResultsButton(..)    
  , defaultInlineQueryResultsButton 
  ) 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
import qualified TD.Data.InlineQueryResultsButtonType as InlineQueryResultsButtonType

data InlineQueryResultsButton
  = InlineQueryResultsButton -- ^ Represents a button to be shown above inline query results
    { InlineQueryResultsButton -> Maybe Text
text  :: Maybe T.Text                                                    -- ^ The text of the button
    , InlineQueryResultsButton -> Maybe InlineQueryResultsButtonType
_type :: Maybe InlineQueryResultsButtonType.InlineQueryResultsButtonType -- ^ Type of the button
    }
  deriving (InlineQueryResultsButton -> InlineQueryResultsButton -> Bool
(InlineQueryResultsButton -> InlineQueryResultsButton -> Bool)
-> (InlineQueryResultsButton -> InlineQueryResultsButton -> Bool)
-> Eq InlineQueryResultsButton
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InlineQueryResultsButton -> InlineQueryResultsButton -> Bool
== :: InlineQueryResultsButton -> InlineQueryResultsButton -> Bool
$c/= :: InlineQueryResultsButton -> InlineQueryResultsButton -> Bool
/= :: InlineQueryResultsButton -> InlineQueryResultsButton -> Bool
Eq, Int -> InlineQueryResultsButton -> ShowS
[InlineQueryResultsButton] -> ShowS
InlineQueryResultsButton -> String
(Int -> InlineQueryResultsButton -> ShowS)
-> (InlineQueryResultsButton -> String)
-> ([InlineQueryResultsButton] -> ShowS)
-> Show InlineQueryResultsButton
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InlineQueryResultsButton -> ShowS
showsPrec :: Int -> InlineQueryResultsButton -> ShowS
$cshow :: InlineQueryResultsButton -> String
show :: InlineQueryResultsButton -> String
$cshowList :: [InlineQueryResultsButton] -> ShowS
showList :: [InlineQueryResultsButton] -> ShowS
Show)

instance I.ShortShow InlineQueryResultsButton where
  shortShow :: InlineQueryResultsButton -> String
shortShow InlineQueryResultsButton
    { text :: InlineQueryResultsButton -> Maybe Text
text  = Maybe Text
text_
    , _type :: InlineQueryResultsButton -> Maybe InlineQueryResultsButtonType
_type = Maybe InlineQueryResultsButtonType
_type_
    }
      = String
"InlineQueryResultsButton"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"text"  String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
text_
        , String
"_type" String -> Maybe InlineQueryResultsButtonType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InlineQueryResultsButtonType
_type_
        ]

instance AT.FromJSON InlineQueryResultsButton where
  parseJSON :: Value -> Parser InlineQueryResultsButton
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
"inlineQueryResultsButton" -> Value -> Parser InlineQueryResultsButton
parseInlineQueryResultsButton Value
v
      String
_                          -> Parser InlineQueryResultsButton
forall a. Monoid a => a
mempty
    
    where
      parseInlineQueryResultsButton :: A.Value -> AT.Parser InlineQueryResultsButton
      parseInlineQueryResultsButton :: Value -> Parser InlineQueryResultsButton
parseInlineQueryResultsButton = String
-> (Object -> Parser InlineQueryResultsButton)
-> Value
-> Parser InlineQueryResultsButton
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InlineQueryResultsButton" ((Object -> Parser InlineQueryResultsButton)
 -> Value -> Parser InlineQueryResultsButton)
-> (Object -> Parser InlineQueryResultsButton)
-> Value
-> Parser InlineQueryResultsButton
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
text_  <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        Maybe InlineQueryResultsButtonType
_type_ <- Object
o Object -> Key -> Parser (Maybe InlineQueryResultsButtonType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"type"
        InlineQueryResultsButton -> Parser InlineQueryResultsButton
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InlineQueryResultsButton -> Parser InlineQueryResultsButton)
-> InlineQueryResultsButton -> Parser InlineQueryResultsButton
forall a b. (a -> b) -> a -> b
$ InlineQueryResultsButton
          { text :: Maybe Text
text  = Maybe Text
text_
          , _type :: Maybe InlineQueryResultsButtonType
_type = Maybe InlineQueryResultsButtonType
_type_
          }
  parseJSON Value
_ = Parser InlineQueryResultsButton
forall a. Monoid a => a
mempty

instance AT.ToJSON InlineQueryResultsButton where
  toJSON :: InlineQueryResultsButton -> Value
toJSON InlineQueryResultsButton
    { text :: InlineQueryResultsButton -> Maybe Text
text  = Maybe Text
text_
    , _type :: InlineQueryResultsButton -> Maybe InlineQueryResultsButtonType
_type = Maybe InlineQueryResultsButtonType
_type_
    }
      = [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
"inlineQueryResultsButton"
        , Key
"text"  Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
text_
        , Key
"type"  Key -> Maybe InlineQueryResultsButtonType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InlineQueryResultsButtonType
_type_
        ]

defaultInlineQueryResultsButton :: InlineQueryResultsButton
defaultInlineQueryResultsButton :: InlineQueryResultsButton
defaultInlineQueryResultsButton =
  InlineQueryResultsButton
    { text :: Maybe Text
text  = Maybe Text
forall a. Maybe a
Nothing
    , _type :: Maybe InlineQueryResultsButtonType
_type = Maybe InlineQueryResultsButtonType
forall a. Maybe a
Nothing
    }