module TD.Query.PingProxy
  (PingProxy(..)
  ) where

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

-- | Computes time needed to receive a response from a Telegram server through a proxy. Can be called before authorization. Returns 'TD.Data.Seconds.Seconds'
data PingProxy
  = PingProxy
    { PingProxy -> Maybe Int
proxy_id :: Maybe Int -- ^ Proxy identifier. Use 0 to ping a Telegram server without a proxy
    }
  deriving (PingProxy -> PingProxy -> Bool
(PingProxy -> PingProxy -> Bool)
-> (PingProxy -> PingProxy -> Bool) -> Eq PingProxy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PingProxy -> PingProxy -> Bool
== :: PingProxy -> PingProxy -> Bool
$c/= :: PingProxy -> PingProxy -> Bool
/= :: PingProxy -> PingProxy -> Bool
Eq, Int -> PingProxy -> ShowS
[PingProxy] -> ShowS
PingProxy -> String
(Int -> PingProxy -> ShowS)
-> (PingProxy -> String)
-> ([PingProxy] -> ShowS)
-> Show PingProxy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PingProxy -> ShowS
showsPrec :: Int -> PingProxy -> ShowS
$cshow :: PingProxy -> String
show :: PingProxy -> String
$cshowList :: [PingProxy] -> ShowS
showList :: [PingProxy] -> ShowS
Show)

instance I.ShortShow PingProxy where
  shortShow :: PingProxy -> String
shortShow
    PingProxy
      { proxy_id :: PingProxy -> Maybe Int
proxy_id = Maybe Int
proxy_id_
      }
        = String
"PingProxy"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"proxy_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
proxy_id_
          ]

instance AT.ToJSON PingProxy where
  toJSON :: PingProxy -> Value
toJSON
    PingProxy
      { proxy_id :: PingProxy -> Maybe Int
proxy_id = Maybe Int
proxy_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
"pingProxy"
          , Key
"proxy_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
proxy_id_
          ]