module TD.Data.ReplyMarkup
  (ReplyMarkup(..)) 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.KeyboardButton as KeyboardButton
import qualified TD.Data.InlineKeyboardButton as InlineKeyboardButton

-- | Contains a description of a custom keyboard and actions that can be done with it to quickly reply to bots
data ReplyMarkup
  = ReplyMarkupRemoveKeyboard -- ^ Instructs application to remove the keyboard once this message has been received. This kind of keyboard can't be received in an incoming message; instead, updateChatReplyMarkup with message_id == 0 will be sent
    { ReplyMarkup -> Maybe Bool
is_personal :: Maybe Bool -- ^ True, if the keyboard is removed only for the mentioned users or the target user of a reply
    }
  | ReplyMarkupForceReply -- ^ Instructs application to force a reply to this message
    { is_personal             :: Maybe Bool   -- ^ True, if a forced reply must automatically be shown to the current user. For outgoing messages, specify true to show the forced reply only for the mentioned users and for the target user of a reply
    , ReplyMarkup -> Maybe Text
input_field_placeholder :: Maybe T.Text -- ^ If non-empty, the placeholder to be shown in the input field when the reply is active; 0-64 characters
    }
  | ReplyMarkupShowKeyboard -- ^ Contains a custom keyboard layout to quickly reply to bots
    { ReplyMarkup -> Maybe [[KeyboardButton]]
rows                    :: Maybe [[KeyboardButton.KeyboardButton]] -- ^ A list of rows of bot keyboard buttons
    , ReplyMarkup -> Maybe Bool
is_persistent           :: Maybe Bool                              -- ^ True, if the keyboard is expected to always be shown when the ordinary keyboard is hidden
    , ReplyMarkup -> Maybe Bool
resize_keyboard         :: Maybe Bool                              -- ^ True, if the application needs to resize the keyboard vertically
    , ReplyMarkup -> Maybe Bool
one_time                :: Maybe Bool                              -- ^ True, if the application needs to hide the keyboard after use
    , is_personal             :: Maybe Bool                              -- ^ True, if the keyboard must automatically be shown to the current user. For outgoing messages, specify true to show the keyboard only for the mentioned users and for the target user of a reply
    , input_field_placeholder :: Maybe T.Text                            -- ^ If non-empty, the placeholder to be shown in the input field when the keyboard is active; 0-64 characters
    }
  | ReplyMarkupInlineKeyboard -- ^ Contains an inline keyboard layout
    { ReplyMarkup -> Maybe [[InlineKeyboardButton]]
_rows :: Maybe [[InlineKeyboardButton.InlineKeyboardButton]] -- ^ A list of rows of inline keyboard buttons
    }
  deriving (ReplyMarkup -> ReplyMarkup -> Bool
(ReplyMarkup -> ReplyMarkup -> Bool)
-> (ReplyMarkup -> ReplyMarkup -> Bool) -> Eq ReplyMarkup
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ReplyMarkup -> ReplyMarkup -> Bool
== :: ReplyMarkup -> ReplyMarkup -> Bool
$c/= :: ReplyMarkup -> ReplyMarkup -> Bool
/= :: ReplyMarkup -> ReplyMarkup -> Bool
Eq, Int -> ReplyMarkup -> ShowS
[ReplyMarkup] -> ShowS
ReplyMarkup -> String
(Int -> ReplyMarkup -> ShowS)
-> (ReplyMarkup -> String)
-> ([ReplyMarkup] -> ShowS)
-> Show ReplyMarkup
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ReplyMarkup -> ShowS
showsPrec :: Int -> ReplyMarkup -> ShowS
$cshow :: ReplyMarkup -> String
show :: ReplyMarkup -> String
$cshowList :: [ReplyMarkup] -> ShowS
showList :: [ReplyMarkup] -> ShowS
Show)

instance I.ShortShow ReplyMarkup where
  shortShow :: ReplyMarkup -> String
shortShow ReplyMarkupRemoveKeyboard
    { is_personal :: ReplyMarkup -> Maybe Bool
is_personal = Maybe Bool
is_personal_
    }
      = String
"ReplyMarkupRemoveKeyboard"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"is_personal" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_personal_
        ]
  shortShow ReplyMarkupForceReply
    { is_personal :: ReplyMarkup -> Maybe Bool
is_personal             = Maybe Bool
is_personal_
    , input_field_placeholder :: ReplyMarkup -> Maybe Text
input_field_placeholder = Maybe Text
input_field_placeholder_
    }
      = String
"ReplyMarkupForceReply"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"is_personal"             String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_personal_
        , String
"input_field_placeholder" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
input_field_placeholder_
        ]
  shortShow ReplyMarkupShowKeyboard
    { rows :: ReplyMarkup -> Maybe [[KeyboardButton]]
rows                    = Maybe [[KeyboardButton]]
rows_
    , is_persistent :: ReplyMarkup -> Maybe Bool
is_persistent           = Maybe Bool
is_persistent_
    , resize_keyboard :: ReplyMarkup -> Maybe Bool
resize_keyboard         = Maybe Bool
resize_keyboard_
    , one_time :: ReplyMarkup -> Maybe Bool
one_time                = Maybe Bool
one_time_
    , is_personal :: ReplyMarkup -> Maybe Bool
is_personal             = Maybe Bool
is_personal_
    , input_field_placeholder :: ReplyMarkup -> Maybe Text
input_field_placeholder = Maybe Text
input_field_placeholder_
    }
      = String
"ReplyMarkupShowKeyboard"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"rows"                    String -> Maybe [[KeyboardButton]] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [[KeyboardButton]]
rows_
        , String
"is_persistent"           String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_persistent_
        , String
"resize_keyboard"         String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
resize_keyboard_
        , String
"one_time"                String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
one_time_
        , String
"is_personal"             String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_personal_
        , String
"input_field_placeholder" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
input_field_placeholder_
        ]
  shortShow ReplyMarkupInlineKeyboard
    { _rows :: ReplyMarkup -> Maybe [[InlineKeyboardButton]]
_rows = Maybe [[InlineKeyboardButton]]
_rows_
    }
      = String
"ReplyMarkupInlineKeyboard"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_rows" String -> Maybe [[InlineKeyboardButton]] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [[InlineKeyboardButton]]
_rows_
        ]

instance AT.FromJSON ReplyMarkup where
  parseJSON :: Value -> Parser ReplyMarkup
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
"replyMarkupRemoveKeyboard" -> Value -> Parser ReplyMarkup
parseReplyMarkupRemoveKeyboard Value
v
      String
"replyMarkupForceReply"     -> Value -> Parser ReplyMarkup
parseReplyMarkupForceReply Value
v
      String
"replyMarkupShowKeyboard"   -> Value -> Parser ReplyMarkup
parseReplyMarkupShowKeyboard Value
v
      String
"replyMarkupInlineKeyboard" -> Value -> Parser ReplyMarkup
parseReplyMarkupInlineKeyboard Value
v
      String
_                           -> Parser ReplyMarkup
forall a. Monoid a => a
mempty
    
    where
      parseReplyMarkupRemoveKeyboard :: A.Value -> AT.Parser ReplyMarkup
      parseReplyMarkupRemoveKeyboard :: Value -> Parser ReplyMarkup
parseReplyMarkupRemoveKeyboard = String
-> (Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ReplyMarkupRemoveKeyboard" ((Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup)
-> (Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Bool
is_personal_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_personal"
        ReplyMarkup -> Parser ReplyMarkup
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReplyMarkup -> Parser ReplyMarkup)
-> ReplyMarkup -> Parser ReplyMarkup
forall a b. (a -> b) -> a -> b
$ ReplyMarkupRemoveKeyboard
          { is_personal :: Maybe Bool
is_personal = Maybe Bool
is_personal_
          }
      parseReplyMarkupForceReply :: A.Value -> AT.Parser ReplyMarkup
      parseReplyMarkupForceReply :: Value -> Parser ReplyMarkup
parseReplyMarkupForceReply = String
-> (Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ReplyMarkupForceReply" ((Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup)
-> (Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Bool
is_personal_             <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_personal"
        Maybe Text
input_field_placeholder_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"input_field_placeholder"
        ReplyMarkup -> Parser ReplyMarkup
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReplyMarkup -> Parser ReplyMarkup)
-> ReplyMarkup -> Parser ReplyMarkup
forall a b. (a -> b) -> a -> b
$ ReplyMarkupForceReply
          { is_personal :: Maybe Bool
is_personal             = Maybe Bool
is_personal_
          , input_field_placeholder :: Maybe Text
input_field_placeholder = Maybe Text
input_field_placeholder_
          }
      parseReplyMarkupShowKeyboard :: A.Value -> AT.Parser ReplyMarkup
      parseReplyMarkupShowKeyboard :: Value -> Parser ReplyMarkup
parseReplyMarkupShowKeyboard = String
-> (Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ReplyMarkupShowKeyboard" ((Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup)
-> (Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe [[KeyboardButton]]
rows_                    <- Object
o Object -> Key -> Parser (Maybe [[KeyboardButton]])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"rows"
        Maybe Bool
is_persistent_           <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_persistent"
        Maybe Bool
resize_keyboard_         <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"resize_keyboard"
        Maybe Bool
one_time_                <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"one_time"
        Maybe Bool
is_personal_             <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_personal"
        Maybe Text
input_field_placeholder_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"input_field_placeholder"
        ReplyMarkup -> Parser ReplyMarkup
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReplyMarkup -> Parser ReplyMarkup)
-> ReplyMarkup -> Parser ReplyMarkup
forall a b. (a -> b) -> a -> b
$ ReplyMarkupShowKeyboard
          { rows :: Maybe [[KeyboardButton]]
rows                    = Maybe [[KeyboardButton]]
rows_
          , is_persistent :: Maybe Bool
is_persistent           = Maybe Bool
is_persistent_
          , resize_keyboard :: Maybe Bool
resize_keyboard         = Maybe Bool
resize_keyboard_
          , one_time :: Maybe Bool
one_time                = Maybe Bool
one_time_
          , is_personal :: Maybe Bool
is_personal             = Maybe Bool
is_personal_
          , input_field_placeholder :: Maybe Text
input_field_placeholder = Maybe Text
input_field_placeholder_
          }
      parseReplyMarkupInlineKeyboard :: A.Value -> AT.Parser ReplyMarkup
      parseReplyMarkupInlineKeyboard :: Value -> Parser ReplyMarkup
parseReplyMarkupInlineKeyboard = String
-> (Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ReplyMarkupInlineKeyboard" ((Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup)
-> (Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe [[InlineKeyboardButton]]
_rows_ <- Object
o Object -> Key -> Parser (Maybe [[InlineKeyboardButton]])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"rows"
        ReplyMarkup -> Parser ReplyMarkup
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReplyMarkup -> Parser ReplyMarkup)
-> ReplyMarkup -> Parser ReplyMarkup
forall a b. (a -> b) -> a -> b
$ ReplyMarkupInlineKeyboard
          { _rows :: Maybe [[InlineKeyboardButton]]
_rows = Maybe [[InlineKeyboardButton]]
_rows_
          }
  parseJSON Value
_ = Parser ReplyMarkup
forall a. Monoid a => a
mempty

instance AT.ToJSON ReplyMarkup where
  toJSON :: ReplyMarkup -> Value
toJSON ReplyMarkupRemoveKeyboard
    { is_personal :: ReplyMarkup -> Maybe Bool
is_personal = Maybe Bool
is_personal_
    }
      = [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
"replyMarkupRemoveKeyboard"
        , Key
"is_personal" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
is_personal_
        ]
  toJSON ReplyMarkupForceReply
    { is_personal :: ReplyMarkup -> Maybe Bool
is_personal             = Maybe Bool
is_personal_
    , input_field_placeholder :: ReplyMarkup -> Maybe Text
input_field_placeholder = Maybe Text
input_field_placeholder_
    }
      = [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
"replyMarkupForceReply"
        , Key
"is_personal"             Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
is_personal_
        , Key
"input_field_placeholder" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
input_field_placeholder_
        ]
  toJSON ReplyMarkupShowKeyboard
    { rows :: ReplyMarkup -> Maybe [[KeyboardButton]]
rows                    = Maybe [[KeyboardButton]]
rows_
    , is_persistent :: ReplyMarkup -> Maybe Bool
is_persistent           = Maybe Bool
is_persistent_
    , resize_keyboard :: ReplyMarkup -> Maybe Bool
resize_keyboard         = Maybe Bool
resize_keyboard_
    , one_time :: ReplyMarkup -> Maybe Bool
one_time                = Maybe Bool
one_time_
    , is_personal :: ReplyMarkup -> Maybe Bool
is_personal             = Maybe Bool
is_personal_
    , input_field_placeholder :: ReplyMarkup -> Maybe Text
input_field_placeholder = Maybe Text
input_field_placeholder_
    }
      = [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
"replyMarkupShowKeyboard"
        , Key
"rows"                    Key -> Maybe [[KeyboardButton]] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [[KeyboardButton]]
rows_
        , Key
"is_persistent"           Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
is_persistent_
        , Key
"resize_keyboard"         Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
resize_keyboard_
        , Key
"one_time"                Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
one_time_
        , Key
"is_personal"             Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
is_personal_
        , Key
"input_field_placeholder" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
input_field_placeholder_
        ]
  toJSON ReplyMarkupInlineKeyboard
    { _rows :: ReplyMarkup -> Maybe [[InlineKeyboardButton]]
_rows = Maybe [[InlineKeyboardButton]]
_rows_
    }
      = [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
"replyMarkupInlineKeyboard"
        , Key
"rows"  Key -> Maybe [[InlineKeyboardButton]] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [[InlineKeyboardButton]]
_rows_
        ]