module TD.Data.ChatAction
  (ChatAction(..)) 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

-- | Describes the different types of activity in a chat
data ChatAction
  = ChatActionTyping -- ^ The user is typing a message
  | ChatActionRecordingVideo -- ^ The user is recording a video
  | ChatActionUploadingVideo -- ^ The user is uploading a video
    { ChatAction -> Maybe Int
progress :: Maybe Int -- ^ Upload progress, as a percentage
    }
  | ChatActionRecordingVoiceNote -- ^ The user is recording a voice note
  | ChatActionUploadingVoiceNote -- ^ The user is uploading a voice note
    { progress :: Maybe Int -- ^ Upload progress, as a percentage
    }
  | ChatActionUploadingPhoto -- ^ The user is uploading a photo
    { progress :: Maybe Int -- ^ Upload progress, as a percentage
    }
  | ChatActionUploadingDocument -- ^ The user is uploading a document
    { progress :: Maybe Int -- ^ Upload progress, as a percentage
    }
  | ChatActionChoosingSticker -- ^ The user is picking a sticker to send
  | ChatActionChoosingLocation -- ^ The user is picking a location or venue to send
  | ChatActionChoosingContact -- ^ The user is picking a contact to send
  | ChatActionStartPlayingGame -- ^ The user has started to play a game
  | ChatActionRecordingVideoNote -- ^ The user is recording a video note
  | ChatActionUploadingVideoNote -- ^ The user is uploading a video note
    { progress :: Maybe Int -- ^ Upload progress, as a percentage
    }
  | ChatActionWatchingAnimations -- ^ The user is watching animations sent by the other party by clicking on an animated emoji
    { ChatAction -> Maybe Text
emoji :: Maybe T.Text -- ^ The animated emoji
    }
  | ChatActionCancel -- ^ The user has canceled the previous action
  deriving (ChatAction -> ChatAction -> Bool
(ChatAction -> ChatAction -> Bool)
-> (ChatAction -> ChatAction -> Bool) -> Eq ChatAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatAction -> ChatAction -> Bool
== :: ChatAction -> ChatAction -> Bool
$c/= :: ChatAction -> ChatAction -> Bool
/= :: ChatAction -> ChatAction -> Bool
Eq, Int -> ChatAction -> ShowS
[ChatAction] -> ShowS
ChatAction -> String
(Int -> ChatAction -> ShowS)
-> (ChatAction -> String)
-> ([ChatAction] -> ShowS)
-> Show ChatAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatAction -> ShowS
showsPrec :: Int -> ChatAction -> ShowS
$cshow :: ChatAction -> String
show :: ChatAction -> String
$cshowList :: [ChatAction] -> ShowS
showList :: [ChatAction] -> ShowS
Show)

instance I.ShortShow ChatAction where
  shortShow :: ChatAction -> String
shortShow ChatAction
ChatActionTyping
      = String
"ChatActionTyping"
  shortShow ChatAction
ChatActionRecordingVideo
      = String
"ChatActionRecordingVideo"
  shortShow ChatActionUploadingVideo
    { progress :: ChatAction -> Maybe Int
progress = Maybe Int
progress_
    }
      = String
"ChatActionUploadingVideo"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"progress" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
progress_
        ]
  shortShow ChatAction
ChatActionRecordingVoiceNote
      = String
"ChatActionRecordingVoiceNote"
  shortShow ChatActionUploadingVoiceNote
    { progress :: ChatAction -> Maybe Int
progress = Maybe Int
progress_
    }
      = String
"ChatActionUploadingVoiceNote"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"progress" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
progress_
        ]
  shortShow ChatActionUploadingPhoto
    { progress :: ChatAction -> Maybe Int
progress = Maybe Int
progress_
    }
      = String
"ChatActionUploadingPhoto"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"progress" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
progress_
        ]
  shortShow ChatActionUploadingDocument
    { progress :: ChatAction -> Maybe Int
progress = Maybe Int
progress_
    }
      = String
"ChatActionUploadingDocument"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"progress" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
progress_
        ]
  shortShow ChatAction
ChatActionChoosingSticker
      = String
"ChatActionChoosingSticker"
  shortShow ChatAction
ChatActionChoosingLocation
      = String
"ChatActionChoosingLocation"
  shortShow ChatAction
ChatActionChoosingContact
      = String
"ChatActionChoosingContact"
  shortShow ChatAction
ChatActionStartPlayingGame
      = String
"ChatActionStartPlayingGame"
  shortShow ChatAction
ChatActionRecordingVideoNote
      = String
"ChatActionRecordingVideoNote"
  shortShow ChatActionUploadingVideoNote
    { progress :: ChatAction -> Maybe Int
progress = Maybe Int
progress_
    }
      = String
"ChatActionUploadingVideoNote"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"progress" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
progress_
        ]
  shortShow ChatActionWatchingAnimations
    { emoji :: ChatAction -> Maybe Text
emoji = Maybe Text
emoji_
    }
      = String
"ChatActionWatchingAnimations"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"emoji" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
emoji_
        ]
  shortShow ChatAction
ChatActionCancel
      = String
"ChatActionCancel"

instance AT.FromJSON ChatAction where
  parseJSON :: Value -> Parser ChatAction
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
"chatActionTyping"             -> ChatAction -> Parser ChatAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatAction
ChatActionTyping
      String
"chatActionRecordingVideo"     -> ChatAction -> Parser ChatAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatAction
ChatActionRecordingVideo
      String
"chatActionUploadingVideo"     -> Value -> Parser ChatAction
parseChatActionUploadingVideo Value
v
      String
"chatActionRecordingVoiceNote" -> ChatAction -> Parser ChatAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatAction
ChatActionRecordingVoiceNote
      String
"chatActionUploadingVoiceNote" -> Value -> Parser ChatAction
parseChatActionUploadingVoiceNote Value
v
      String
"chatActionUploadingPhoto"     -> Value -> Parser ChatAction
parseChatActionUploadingPhoto Value
v
      String
"chatActionUploadingDocument"  -> Value -> Parser ChatAction
parseChatActionUploadingDocument Value
v
      String
"chatActionChoosingSticker"    -> ChatAction -> Parser ChatAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatAction
ChatActionChoosingSticker
      String
"chatActionChoosingLocation"   -> ChatAction -> Parser ChatAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatAction
ChatActionChoosingLocation
      String
"chatActionChoosingContact"    -> ChatAction -> Parser ChatAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatAction
ChatActionChoosingContact
      String
"chatActionStartPlayingGame"   -> ChatAction -> Parser ChatAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatAction
ChatActionStartPlayingGame
      String
"chatActionRecordingVideoNote" -> ChatAction -> Parser ChatAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatAction
ChatActionRecordingVideoNote
      String
"chatActionUploadingVideoNote" -> Value -> Parser ChatAction
parseChatActionUploadingVideoNote Value
v
      String
"chatActionWatchingAnimations" -> Value -> Parser ChatAction
parseChatActionWatchingAnimations Value
v
      String
"chatActionCancel"             -> ChatAction -> Parser ChatAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ChatAction
ChatActionCancel
      String
_                              -> Parser ChatAction
forall a. Monoid a => a
mempty
    
    where
      parseChatActionUploadingVideo :: A.Value -> AT.Parser ChatAction
      parseChatActionUploadingVideo :: Value -> Parser ChatAction
parseChatActionUploadingVideo = String
-> (Object -> Parser ChatAction) -> Value -> Parser ChatAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatActionUploadingVideo" ((Object -> Parser ChatAction) -> Value -> Parser ChatAction)
-> (Object -> Parser ChatAction) -> Value -> Parser ChatAction
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
progress_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"progress"
        ChatAction -> Parser ChatAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatAction -> Parser ChatAction)
-> ChatAction -> Parser ChatAction
forall a b. (a -> b) -> a -> b
$ ChatActionUploadingVideo
          { progress :: Maybe Int
progress = Maybe Int
progress_
          }
      parseChatActionUploadingVoiceNote :: A.Value -> AT.Parser ChatAction
      parseChatActionUploadingVoiceNote :: Value -> Parser ChatAction
parseChatActionUploadingVoiceNote = String
-> (Object -> Parser ChatAction) -> Value -> Parser ChatAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatActionUploadingVoiceNote" ((Object -> Parser ChatAction) -> Value -> Parser ChatAction)
-> (Object -> Parser ChatAction) -> Value -> Parser ChatAction
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
progress_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"progress"
        ChatAction -> Parser ChatAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatAction -> Parser ChatAction)
-> ChatAction -> Parser ChatAction
forall a b. (a -> b) -> a -> b
$ ChatActionUploadingVoiceNote
          { progress :: Maybe Int
progress = Maybe Int
progress_
          }
      parseChatActionUploadingPhoto :: A.Value -> AT.Parser ChatAction
      parseChatActionUploadingPhoto :: Value -> Parser ChatAction
parseChatActionUploadingPhoto = String
-> (Object -> Parser ChatAction) -> Value -> Parser ChatAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatActionUploadingPhoto" ((Object -> Parser ChatAction) -> Value -> Parser ChatAction)
-> (Object -> Parser ChatAction) -> Value -> Parser ChatAction
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
progress_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"progress"
        ChatAction -> Parser ChatAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatAction -> Parser ChatAction)
-> ChatAction -> Parser ChatAction
forall a b. (a -> b) -> a -> b
$ ChatActionUploadingPhoto
          { progress :: Maybe Int
progress = Maybe Int
progress_
          }
      parseChatActionUploadingDocument :: A.Value -> AT.Parser ChatAction
      parseChatActionUploadingDocument :: Value -> Parser ChatAction
parseChatActionUploadingDocument = String
-> (Object -> Parser ChatAction) -> Value -> Parser ChatAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatActionUploadingDocument" ((Object -> Parser ChatAction) -> Value -> Parser ChatAction)
-> (Object -> Parser ChatAction) -> Value -> Parser ChatAction
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
progress_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"progress"
        ChatAction -> Parser ChatAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatAction -> Parser ChatAction)
-> ChatAction -> Parser ChatAction
forall a b. (a -> b) -> a -> b
$ ChatActionUploadingDocument
          { progress :: Maybe Int
progress = Maybe Int
progress_
          }
      parseChatActionUploadingVideoNote :: A.Value -> AT.Parser ChatAction
      parseChatActionUploadingVideoNote :: Value -> Parser ChatAction
parseChatActionUploadingVideoNote = String
-> (Object -> Parser ChatAction) -> Value -> Parser ChatAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatActionUploadingVideoNote" ((Object -> Parser ChatAction) -> Value -> Parser ChatAction)
-> (Object -> Parser ChatAction) -> Value -> Parser ChatAction
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
progress_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"progress"
        ChatAction -> Parser ChatAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatAction -> Parser ChatAction)
-> ChatAction -> Parser ChatAction
forall a b. (a -> b) -> a -> b
$ ChatActionUploadingVideoNote
          { progress :: Maybe Int
progress = Maybe Int
progress_
          }
      parseChatActionWatchingAnimations :: A.Value -> AT.Parser ChatAction
      parseChatActionWatchingAnimations :: Value -> Parser ChatAction
parseChatActionWatchingAnimations = String
-> (Object -> Parser ChatAction) -> Value -> Parser ChatAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatActionWatchingAnimations" ((Object -> Parser ChatAction) -> Value -> Parser ChatAction)
-> (Object -> Parser ChatAction) -> Value -> Parser ChatAction
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
emoji_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"emoji"
        ChatAction -> Parser ChatAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatAction -> Parser ChatAction)
-> ChatAction -> Parser ChatAction
forall a b. (a -> b) -> a -> b
$ ChatActionWatchingAnimations
          { emoji :: Maybe Text
emoji = Maybe Text
emoji_
          }
  parseJSON Value
_ = Parser ChatAction
forall a. Monoid a => a
mempty

instance AT.ToJSON ChatAction where
  toJSON :: ChatAction -> Value
toJSON ChatAction
ChatActionTyping
      = [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
"chatActionTyping"
        ]
  toJSON ChatAction
ChatActionRecordingVideo
      = [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
"chatActionRecordingVideo"
        ]
  toJSON ChatActionUploadingVideo
    { progress :: ChatAction -> Maybe Int
progress = Maybe Int
progress_
    }
      = [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
"chatActionUploadingVideo"
        , Key
"progress" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
progress_
        ]
  toJSON ChatAction
ChatActionRecordingVoiceNote
      = [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
"chatActionRecordingVoiceNote"
        ]
  toJSON ChatActionUploadingVoiceNote
    { progress :: ChatAction -> Maybe Int
progress = Maybe Int
progress_
    }
      = [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
"chatActionUploadingVoiceNote"
        , Key
"progress" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
progress_
        ]
  toJSON ChatActionUploadingPhoto
    { progress :: ChatAction -> Maybe Int
progress = Maybe Int
progress_
    }
      = [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
"chatActionUploadingPhoto"
        , Key
"progress" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
progress_
        ]
  toJSON ChatActionUploadingDocument
    { progress :: ChatAction -> Maybe Int
progress = Maybe Int
progress_
    }
      = [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
"chatActionUploadingDocument"
        , Key
"progress" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
progress_
        ]
  toJSON ChatAction
ChatActionChoosingSticker
      = [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
"chatActionChoosingSticker"
        ]
  toJSON ChatAction
ChatActionChoosingLocation
      = [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
"chatActionChoosingLocation"
        ]
  toJSON ChatAction
ChatActionChoosingContact
      = [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
"chatActionChoosingContact"
        ]
  toJSON ChatAction
ChatActionStartPlayingGame
      = [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
"chatActionStartPlayingGame"
        ]
  toJSON ChatAction
ChatActionRecordingVideoNote
      = [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
"chatActionRecordingVideoNote"
        ]
  toJSON ChatActionUploadingVideoNote
    { progress :: ChatAction -> Maybe Int
progress = Maybe Int
progress_
    }
      = [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
"chatActionUploadingVideoNote"
        , Key
"progress" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
progress_
        ]
  toJSON ChatActionWatchingAnimations
    { emoji :: ChatAction -> Maybe Text
emoji = Maybe Text
emoji_
    }
      = [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
"chatActionWatchingAnimations"
        , Key
"emoji" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
emoji_
        ]
  toJSON ChatAction
ChatActionCancel
      = [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
"chatActionCancel"
        ]