module TD.Data.InputMessageReplyTo
  (InputMessageReplyTo(..)) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.InputTextQuote as InputTextQuote

-- | Contains information about the message or the story to be replied
data InputMessageReplyTo
  = InputMessageReplyToMessage -- ^ Describes a message to be replied in the same chat and forum topic
    { InputMessageReplyTo -> Maybe Int
message_id :: Maybe Int                           -- ^ The identifier of the message to be replied in the same chat and forum topic. A message can be replied in the same chat and forum topic only if messageProperties.can_be_replied
    , InputMessageReplyTo -> Maybe InputTextQuote
quote      :: Maybe InputTextQuote.InputTextQuote -- ^ Quote from the message to be replied; pass null if none. Must always be null for replies in secret chats
    }
  | InputMessageReplyToExternalMessage -- ^ Describes a message to be replied that is from a different chat or a forum topic; not supported in secret chats
    { InputMessageReplyTo -> Maybe Int
chat_id    :: Maybe Int                           -- ^ The identifier of the chat to which the message to be replied belongs
    , message_id :: Maybe Int                           -- ^ The identifier of the message to be replied in the specified chat. A message can be replied in another chat or forum topic only if messageProperties.can_be_replied_in_another_chat
    , quote      :: Maybe InputTextQuote.InputTextQuote -- ^ Quote from the message to be replied; pass null if none
    }
  | InputMessageReplyToStory -- ^ Describes a story to be replied
    { InputMessageReplyTo -> Maybe Int
story_sender_chat_id :: Maybe Int -- ^ The identifier of the sender of the story. Currently, stories can be replied only in the sender's chat and channel stories can't be replied
    , InputMessageReplyTo -> Maybe Int
story_id             :: Maybe Int -- ^ The identifier of the story
    }
  deriving (InputMessageReplyTo -> InputMessageReplyTo -> Bool
(InputMessageReplyTo -> InputMessageReplyTo -> Bool)
-> (InputMessageReplyTo -> InputMessageReplyTo -> Bool)
-> Eq InputMessageReplyTo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputMessageReplyTo -> InputMessageReplyTo -> Bool
== :: InputMessageReplyTo -> InputMessageReplyTo -> Bool
$c/= :: InputMessageReplyTo -> InputMessageReplyTo -> Bool
/= :: InputMessageReplyTo -> InputMessageReplyTo -> Bool
Eq, Int -> InputMessageReplyTo -> ShowS
[InputMessageReplyTo] -> ShowS
InputMessageReplyTo -> String
(Int -> InputMessageReplyTo -> ShowS)
-> (InputMessageReplyTo -> String)
-> ([InputMessageReplyTo] -> ShowS)
-> Show InputMessageReplyTo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputMessageReplyTo -> ShowS
showsPrec :: Int -> InputMessageReplyTo -> ShowS
$cshow :: InputMessageReplyTo -> String
show :: InputMessageReplyTo -> String
$cshowList :: [InputMessageReplyTo] -> ShowS
showList :: [InputMessageReplyTo] -> ShowS
Show)

instance I.ShortShow InputMessageReplyTo where
  shortShow :: InputMessageReplyTo -> String
shortShow InputMessageReplyToMessage
    { message_id :: InputMessageReplyTo -> Maybe Int
message_id = Maybe Int
message_id_
    , quote :: InputMessageReplyTo -> Maybe InputTextQuote
quote      = Maybe InputTextQuote
quote_
    }
      = String
"InputMessageReplyToMessage"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"message_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
message_id_
        , String
"quote"      String -> Maybe InputTextQuote -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputTextQuote
quote_
        ]
  shortShow InputMessageReplyToExternalMessage
    { chat_id :: InputMessageReplyTo -> Maybe Int
chat_id    = Maybe Int
chat_id_
    , message_id :: InputMessageReplyTo -> Maybe Int
message_id = Maybe Int
message_id_
    , quote :: InputMessageReplyTo -> Maybe InputTextQuote
quote      = Maybe InputTextQuote
quote_
    }
      = String
"InputMessageReplyToExternalMessage"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"chat_id"    String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
        , String
"message_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
message_id_
        , String
"quote"      String -> Maybe InputTextQuote -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputTextQuote
quote_
        ]
  shortShow InputMessageReplyToStory
    { story_sender_chat_id :: InputMessageReplyTo -> Maybe Int
story_sender_chat_id = Maybe Int
story_sender_chat_id_
    , story_id :: InputMessageReplyTo -> Maybe Int
story_id             = Maybe Int
story_id_
    }
      = String
"InputMessageReplyToStory"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"story_sender_chat_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
story_sender_chat_id_
        , String
"story_id"             String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
story_id_
        ]

instance AT.FromJSON InputMessageReplyTo where
  parseJSON :: Value -> Parser InputMessageReplyTo
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
"inputMessageReplyToMessage"         -> Value -> Parser InputMessageReplyTo
parseInputMessageReplyToMessage Value
v
      String
"inputMessageReplyToExternalMessage" -> Value -> Parser InputMessageReplyTo
parseInputMessageReplyToExternalMessage Value
v
      String
"inputMessageReplyToStory"           -> Value -> Parser InputMessageReplyTo
parseInputMessageReplyToStory Value
v
      String
_                                    -> Parser InputMessageReplyTo
forall a. Monoid a => a
mempty
    
    where
      parseInputMessageReplyToMessage :: A.Value -> AT.Parser InputMessageReplyTo
      parseInputMessageReplyToMessage :: Value -> Parser InputMessageReplyTo
parseInputMessageReplyToMessage = String
-> (Object -> Parser InputMessageReplyTo)
-> Value
-> Parser InputMessageReplyTo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputMessageReplyToMessage" ((Object -> Parser InputMessageReplyTo)
 -> Value -> Parser InputMessageReplyTo)
-> (Object -> Parser InputMessageReplyTo)
-> Value
-> Parser InputMessageReplyTo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
message_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"message_id"
        Maybe InputTextQuote
quote_      <- Object
o Object -> Key -> Parser (Maybe InputTextQuote)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"quote"
        InputMessageReplyTo -> Parser InputMessageReplyTo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputMessageReplyTo -> Parser InputMessageReplyTo)
-> InputMessageReplyTo -> Parser InputMessageReplyTo
forall a b. (a -> b) -> a -> b
$ InputMessageReplyToMessage
          { message_id :: Maybe Int
message_id = Maybe Int
message_id_
          , quote :: Maybe InputTextQuote
quote      = Maybe InputTextQuote
quote_
          }
      parseInputMessageReplyToExternalMessage :: A.Value -> AT.Parser InputMessageReplyTo
      parseInputMessageReplyToExternalMessage :: Value -> Parser InputMessageReplyTo
parseInputMessageReplyToExternalMessage = String
-> (Object -> Parser InputMessageReplyTo)
-> Value
-> Parser InputMessageReplyTo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputMessageReplyToExternalMessage" ((Object -> Parser InputMessageReplyTo)
 -> Value -> Parser InputMessageReplyTo)
-> (Object -> Parser InputMessageReplyTo)
-> Value
-> Parser InputMessageReplyTo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
chat_id_    <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"chat_id"
        Maybe Int
message_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"message_id"
        Maybe InputTextQuote
quote_      <- Object
o Object -> Key -> Parser (Maybe InputTextQuote)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"quote"
        InputMessageReplyTo -> Parser InputMessageReplyTo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputMessageReplyTo -> Parser InputMessageReplyTo)
-> InputMessageReplyTo -> Parser InputMessageReplyTo
forall a b. (a -> b) -> a -> b
$ InputMessageReplyToExternalMessage
          { chat_id :: Maybe Int
chat_id    = Maybe Int
chat_id_
          , message_id :: Maybe Int
message_id = Maybe Int
message_id_
          , quote :: Maybe InputTextQuote
quote      = Maybe InputTextQuote
quote_
          }
      parseInputMessageReplyToStory :: A.Value -> AT.Parser InputMessageReplyTo
      parseInputMessageReplyToStory :: Value -> Parser InputMessageReplyTo
parseInputMessageReplyToStory = String
-> (Object -> Parser InputMessageReplyTo)
-> Value
-> Parser InputMessageReplyTo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputMessageReplyToStory" ((Object -> Parser InputMessageReplyTo)
 -> Value -> Parser InputMessageReplyTo)
-> (Object -> Parser InputMessageReplyTo)
-> Value
-> Parser InputMessageReplyTo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
story_sender_chat_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"story_sender_chat_id"
        Maybe Int
story_id_             <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"story_id"
        InputMessageReplyTo -> Parser InputMessageReplyTo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputMessageReplyTo -> Parser InputMessageReplyTo)
-> InputMessageReplyTo -> Parser InputMessageReplyTo
forall a b. (a -> b) -> a -> b
$ InputMessageReplyToStory
          { story_sender_chat_id :: Maybe Int
story_sender_chat_id = Maybe Int
story_sender_chat_id_
          , story_id :: Maybe Int
story_id             = Maybe Int
story_id_
          }
  parseJSON Value
_ = Parser InputMessageReplyTo
forall a. Monoid a => a
mempty

instance AT.ToJSON InputMessageReplyTo where
  toJSON :: InputMessageReplyTo -> Value
toJSON InputMessageReplyToMessage
    { message_id :: InputMessageReplyTo -> Maybe Int
message_id = Maybe Int
message_id_
    , quote :: InputMessageReplyTo -> Maybe InputTextQuote
quote      = Maybe InputTextQuote
quote_
    }
      = [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
"inputMessageReplyToMessage"
        , Key
"message_id" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
message_id_
        , Key
"quote"      Key -> Maybe InputTextQuote -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputTextQuote
quote_
        ]
  toJSON InputMessageReplyToExternalMessage
    { chat_id :: InputMessageReplyTo -> Maybe Int
chat_id    = Maybe Int
chat_id_
    , message_id :: InputMessageReplyTo -> Maybe Int
message_id = Maybe Int
message_id_
    , quote :: InputMessageReplyTo -> Maybe InputTextQuote
quote      = Maybe InputTextQuote
quote_
    }
      = [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
"inputMessageReplyToExternalMessage"
        , Key
"chat_id"    Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
chat_id_
        , Key
"message_id" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
message_id_
        , Key
"quote"      Key -> Maybe InputTextQuote -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputTextQuote
quote_
        ]
  toJSON InputMessageReplyToStory
    { story_sender_chat_id :: InputMessageReplyTo -> Maybe Int
story_sender_chat_id = Maybe Int
story_sender_chat_id_
    , story_id :: InputMessageReplyTo -> Maybe Int
story_id             = Maybe Int
story_id_
    }
      = [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
"inputMessageReplyToStory"
        , Key
"story_sender_chat_id" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
story_sender_chat_id_
        , Key
"story_id"             Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
story_id_
        ]