module TD.Data.MessageCopyOptions
  ( MessageCopyOptions(..)    
  , defaultMessageCopyOptions 
  ) 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.FormattedText as FormattedText

data MessageCopyOptions
  = MessageCopyOptions -- ^ Options to be used when a message content is copied without reference to the original sender. Service messages, messages with messageInvoice, messagePaidMedia, messageGiveaway, or messageGiveawayWinners content can't be copied
    { MessageCopyOptions -> Maybe Bool
send_copy                    :: Maybe Bool                        -- ^ True, if content of the message needs to be copied without reference to the original sender. Always true if the message is forwarded to a secret chat or is local. Use messageProperties.can_be_saved and messageProperties.can_be_copied_to_secret_chat to check whether the message is suitable
    , MessageCopyOptions -> Maybe Bool
replace_caption              :: Maybe Bool                        -- ^ True, if media caption of the message copy needs to be replaced. Ignored if send_copy is false
    , MessageCopyOptions -> Maybe FormattedText
new_caption                  :: Maybe FormattedText.FormattedText -- ^ New message caption; pass null to copy message without caption. Ignored if replace_caption is false
    , MessageCopyOptions -> Maybe Bool
new_show_caption_above_media :: Maybe Bool                        -- ^ True, if new caption must be shown above the media; otherwise, new caption must be shown below the media; not supported in secret chats. Ignored if replace_caption is false
    }
  deriving (MessageCopyOptions -> MessageCopyOptions -> Bool
(MessageCopyOptions -> MessageCopyOptions -> Bool)
-> (MessageCopyOptions -> MessageCopyOptions -> Bool)
-> Eq MessageCopyOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MessageCopyOptions -> MessageCopyOptions -> Bool
== :: MessageCopyOptions -> MessageCopyOptions -> Bool
$c/= :: MessageCopyOptions -> MessageCopyOptions -> Bool
/= :: MessageCopyOptions -> MessageCopyOptions -> Bool
Eq, Int -> MessageCopyOptions -> ShowS
[MessageCopyOptions] -> ShowS
MessageCopyOptions -> String
(Int -> MessageCopyOptions -> ShowS)
-> (MessageCopyOptions -> String)
-> ([MessageCopyOptions] -> ShowS)
-> Show MessageCopyOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageCopyOptions -> ShowS
showsPrec :: Int -> MessageCopyOptions -> ShowS
$cshow :: MessageCopyOptions -> String
show :: MessageCopyOptions -> String
$cshowList :: [MessageCopyOptions] -> ShowS
showList :: [MessageCopyOptions] -> ShowS
Show)

instance I.ShortShow MessageCopyOptions where
  shortShow :: MessageCopyOptions -> String
shortShow MessageCopyOptions
    { send_copy :: MessageCopyOptions -> Maybe Bool
send_copy                    = Maybe Bool
send_copy_
    , replace_caption :: MessageCopyOptions -> Maybe Bool
replace_caption              = Maybe Bool
replace_caption_
    , new_caption :: MessageCopyOptions -> Maybe FormattedText
new_caption                  = Maybe FormattedText
new_caption_
    , new_show_caption_above_media :: MessageCopyOptions -> Maybe Bool
new_show_caption_above_media = Maybe Bool
new_show_caption_above_media_
    }
      = String
"MessageCopyOptions"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"send_copy"                    String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
send_copy_
        , String
"replace_caption"              String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
replace_caption_
        , String
"new_caption"                  String -> Maybe FormattedText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe FormattedText
new_caption_
        , String
"new_show_caption_above_media" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
new_show_caption_above_media_
        ]

instance AT.FromJSON MessageCopyOptions where
  parseJSON :: Value -> Parser MessageCopyOptions
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
"messageCopyOptions" -> Value -> Parser MessageCopyOptions
parseMessageCopyOptions Value
v
      String
_                    -> Parser MessageCopyOptions
forall a. Monoid a => a
mempty
    
    where
      parseMessageCopyOptions :: A.Value -> AT.Parser MessageCopyOptions
      parseMessageCopyOptions :: Value -> Parser MessageCopyOptions
parseMessageCopyOptions = String
-> (Object -> Parser MessageCopyOptions)
-> Value
-> Parser MessageCopyOptions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MessageCopyOptions" ((Object -> Parser MessageCopyOptions)
 -> Value -> Parser MessageCopyOptions)
-> (Object -> Parser MessageCopyOptions)
-> Value
-> Parser MessageCopyOptions
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Bool
send_copy_                    <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"send_copy"
        Maybe Bool
replace_caption_              <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"replace_caption"
        Maybe FormattedText
new_caption_                  <- Object
o Object -> Key -> Parser (Maybe FormattedText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"new_caption"
        Maybe Bool
new_show_caption_above_media_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"new_show_caption_above_media"
        MessageCopyOptions -> Parser MessageCopyOptions
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MessageCopyOptions -> Parser MessageCopyOptions)
-> MessageCopyOptions -> Parser MessageCopyOptions
forall a b. (a -> b) -> a -> b
$ MessageCopyOptions
          { send_copy :: Maybe Bool
send_copy                    = Maybe Bool
send_copy_
          , replace_caption :: Maybe Bool
replace_caption              = Maybe Bool
replace_caption_
          , new_caption :: Maybe FormattedText
new_caption                  = Maybe FormattedText
new_caption_
          , new_show_caption_above_media :: Maybe Bool
new_show_caption_above_media = Maybe Bool
new_show_caption_above_media_
          }
  parseJSON Value
_ = Parser MessageCopyOptions
forall a. Monoid a => a
mempty

instance AT.ToJSON MessageCopyOptions where
  toJSON :: MessageCopyOptions -> Value
toJSON MessageCopyOptions
    { send_copy :: MessageCopyOptions -> Maybe Bool
send_copy                    = Maybe Bool
send_copy_
    , replace_caption :: MessageCopyOptions -> Maybe Bool
replace_caption              = Maybe Bool
replace_caption_
    , new_caption :: MessageCopyOptions -> Maybe FormattedText
new_caption                  = Maybe FormattedText
new_caption_
    , new_show_caption_above_media :: MessageCopyOptions -> Maybe Bool
new_show_caption_above_media = Maybe Bool
new_show_caption_above_media_
    }
      = [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
"messageCopyOptions"
        , Key
"send_copy"                    Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
send_copy_
        , Key
"replace_caption"              Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
replace_caption_
        , Key
"new_caption"                  Key -> Maybe FormattedText -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe FormattedText
new_caption_
        , Key
"new_show_caption_above_media" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
new_show_caption_above_media_
        ]

defaultMessageCopyOptions :: MessageCopyOptions
defaultMessageCopyOptions :: MessageCopyOptions
defaultMessageCopyOptions =
  MessageCopyOptions
    { send_copy :: Maybe Bool
send_copy                    = Maybe Bool
forall a. Maybe a
Nothing
    , replace_caption :: Maybe Bool
replace_caption              = Maybe Bool
forall a. Maybe a
Nothing
    , new_caption :: Maybe FormattedText
new_caption                  = Maybe FormattedText
forall a. Maybe a
Nothing
    , new_show_caption_above_media :: Maybe Bool
new_show_caption_above_media = Maybe Bool
forall a. Maybe a
Nothing
    }