module TD.Data.InlineButton
  ( InlineButton(..)    
  , defaultInlineButton 
  ) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import {-# SOURCE #-} qualified TD.Data.RichText as RichText
import qualified TD.Data.ButtonStyle as ButtonStyle
import qualified TD.Data.InlineKeyboardButtonType as InlineKeyboardButtonType

data InlineButton
  = InlineButton -- ^ Represents a button inside a rich message
    { InlineButton -> Maybe RichText
text  :: Maybe RichText.RichText                                 -- ^ Text of the button; only richTexts, richTextPlain, and richTextCustomEmoji are allowed
    , InlineButton -> Maybe ButtonStyle
style :: Maybe ButtonStyle.ButtonStyle                           -- ^ Style of the button
    , InlineButton -> Maybe InlineKeyboardButtonType
_type :: Maybe InlineKeyboardButtonType.InlineKeyboardButtonType -- ^ Type of the button; must be one of inlineKeyboardButtonTypeUrl, inlineKeyboardButtonTypeLoginUrl, inlineKeyboardButtonTypeWebApp, inlineKeyboardButtonTypeCallback, inlineKeyboardButtonTypeSwitchInline, inlineKeyboardButtonTypeUser, inlineKeyboardButtonTypeCopyText. Additionally, inlineKeyboardButtonTypeCallbackWithPassword and inlineKeyboardButtonTypeDisabled may be received in incoming messages. Regular users may use only inlineKeyboardButtonTypeUrl, inlineKeyboardButtonTypeUser and inlineKeyboardButtonTypeCopyText
    }
  deriving (InlineButton -> InlineButton -> Bool
(InlineButton -> InlineButton -> Bool)
-> (InlineButton -> InlineButton -> Bool) -> Eq InlineButton
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InlineButton -> InlineButton -> Bool
== :: InlineButton -> InlineButton -> Bool
$c/= :: InlineButton -> InlineButton -> Bool
/= :: InlineButton -> InlineButton -> Bool
Eq, Int -> InlineButton -> ShowS
[InlineButton] -> ShowS
InlineButton -> String
(Int -> InlineButton -> ShowS)
-> (InlineButton -> String)
-> ([InlineButton] -> ShowS)
-> Show InlineButton
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InlineButton -> ShowS
showsPrec :: Int -> InlineButton -> ShowS
$cshow :: InlineButton -> String
show :: InlineButton -> String
$cshowList :: [InlineButton] -> ShowS
showList :: [InlineButton] -> ShowS
Show)

instance I.ShortShow InlineButton where
  shortShow :: InlineButton -> String
shortShow InlineButton
    { text :: InlineButton -> Maybe RichText
text  = Maybe RichText
text_
    , style :: InlineButton -> Maybe ButtonStyle
style = Maybe ButtonStyle
style_
    , _type :: InlineButton -> Maybe InlineKeyboardButtonType
_type = Maybe InlineKeyboardButtonType
_type_
    }
      = String
"InlineButton"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"text"  String -> Maybe RichText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe RichText
text_
        , String
"style" String -> Maybe ButtonStyle -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ButtonStyle
style_
        , String
"_type" String -> Maybe InlineKeyboardButtonType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InlineKeyboardButtonType
_type_
        ]

instance AT.FromJSON InlineButton where
  parseJSON :: Value -> Parser InlineButton
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
"inlineButton" -> Value -> Parser InlineButton
parseInlineButton Value
v
      String
_              -> Parser InlineButton
forall a. Monoid a => a
mempty
    
    where
      parseInlineButton :: A.Value -> AT.Parser InlineButton
      parseInlineButton :: Value -> Parser InlineButton
parseInlineButton = String
-> (Object -> Parser InlineButton) -> Value -> Parser InlineButton
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InlineButton" ((Object -> Parser InlineButton) -> Value -> Parser InlineButton)
-> (Object -> Parser InlineButton) -> Value -> Parser InlineButton
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe RichText
text_  <- Object
o Object -> Key -> Parser (Maybe RichText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"text"
        Maybe ButtonStyle
style_ <- Object
o Object -> Key -> Parser (Maybe ButtonStyle)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"style"
        Maybe InlineKeyboardButtonType
_type_ <- Object
o Object -> Key -> Parser (Maybe InlineKeyboardButtonType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"type"
        InlineButton -> Parser InlineButton
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InlineButton -> Parser InlineButton)
-> InlineButton -> Parser InlineButton
forall a b. (a -> b) -> a -> b
$ InlineButton
          { text :: Maybe RichText
text  = Maybe RichText
text_
          , style :: Maybe ButtonStyle
style = Maybe ButtonStyle
style_
          , _type :: Maybe InlineKeyboardButtonType
_type = Maybe InlineKeyboardButtonType
_type_
          }
  parseJSON Value
_ = Parser InlineButton
forall a. Monoid a => a
mempty

instance AT.ToJSON InlineButton where
  toJSON :: InlineButton -> Value
toJSON InlineButton
    { text :: InlineButton -> Maybe RichText
text  = Maybe RichText
text_
    , style :: InlineButton -> Maybe ButtonStyle
style = Maybe ButtonStyle
style_
    , _type :: InlineButton -> Maybe InlineKeyboardButtonType
_type = Maybe InlineKeyboardButtonType
_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
"inlineButton"
        , Key
"text"  Key -> Maybe RichText -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe RichText
text_
        , Key
"style" Key -> Maybe ButtonStyle -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe ButtonStyle
style_
        , Key
"type"  Key -> Maybe InlineKeyboardButtonType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InlineKeyboardButtonType
_type_
        ]

defaultInlineButton :: InlineButton
defaultInlineButton :: InlineButton
defaultInlineButton =
  InlineButton
    { text :: Maybe RichText
text  = Maybe RichText
forall a. Maybe a
Nothing
    , style :: Maybe ButtonStyle
style = Maybe ButtonStyle
forall a. Maybe a
Nothing
    , _type :: Maybe InlineKeyboardButtonType
_type = Maybe InlineKeyboardButtonType
forall a. Maybe a
Nothing
    }