module TD.Query.ProcessPushNotification
  (ProcessPushNotification(..)
  ) 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

-- | Handles a push notification. Returns an error with code 406 if the push notification is not supported and a connection to the server is required to fetch new data. Can be called before authorization. Returns 'TD.Data.Ok.Ok'
data ProcessPushNotification
  = ProcessPushNotification
    { ProcessPushNotification -> Maybe Text
payload :: Maybe T.Text -- ^ JSON-encoded push notification payload with all fields sent by the server, and "google.sent_time" and "google.notification.sound" fields added
    }
  deriving (ProcessPushNotification -> ProcessPushNotification -> Bool
(ProcessPushNotification -> ProcessPushNotification -> Bool)
-> (ProcessPushNotification -> ProcessPushNotification -> Bool)
-> Eq ProcessPushNotification
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ProcessPushNotification -> ProcessPushNotification -> Bool
== :: ProcessPushNotification -> ProcessPushNotification -> Bool
$c/= :: ProcessPushNotification -> ProcessPushNotification -> Bool
/= :: ProcessPushNotification -> ProcessPushNotification -> Bool
Eq, Int -> ProcessPushNotification -> ShowS
[ProcessPushNotification] -> ShowS
ProcessPushNotification -> String
(Int -> ProcessPushNotification -> ShowS)
-> (ProcessPushNotification -> String)
-> ([ProcessPushNotification] -> ShowS)
-> Show ProcessPushNotification
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ProcessPushNotification -> ShowS
showsPrec :: Int -> ProcessPushNotification -> ShowS
$cshow :: ProcessPushNotification -> String
show :: ProcessPushNotification -> String
$cshowList :: [ProcessPushNotification] -> ShowS
showList :: [ProcessPushNotification] -> ShowS
Show)

instance I.ShortShow ProcessPushNotification where
  shortShow :: ProcessPushNotification -> String
shortShow
    ProcessPushNotification
      { payload :: ProcessPushNotification -> Maybe Text
payload = Maybe Text
payload_
      }
        = String
"ProcessPushNotification"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"payload" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
payload_
          ]

instance AT.ToJSON ProcessPushNotification where
  toJSON :: ProcessPushNotification -> Value
toJSON
    ProcessPushNotification
      { payload :: ProcessPushNotification -> Maybe Text
payload = Maybe Text
payload_
      }
        = [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
"processPushNotification"
          , Key
"payload" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
payload_
          ]