module TD.Data.ConnectionState
  (ConnectionState(..)) where

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

-- | Describes the current state of the connection to Telegram servers
data ConnectionState
  = ConnectionStateWaitingForNetwork -- ^ Waiting for the network to become available. Use setNetworkType to change the available network type
  | ConnectionStateConnectingToProxy -- ^ Establishing a connection with a proxy server
  | ConnectionStateConnecting -- ^ Establishing a connection to the Telegram servers
  | ConnectionStateUpdating -- ^ Downloading data expected to be received while the application was offline
  | ConnectionStateReady -- ^ There is a working connection to the Telegram servers
  deriving (ConnectionState -> ConnectionState -> Bool
(ConnectionState -> ConnectionState -> Bool)
-> (ConnectionState -> ConnectionState -> Bool)
-> Eq ConnectionState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ConnectionState -> ConnectionState -> Bool
== :: ConnectionState -> ConnectionState -> Bool
$c/= :: ConnectionState -> ConnectionState -> Bool
/= :: ConnectionState -> ConnectionState -> Bool
Eq, Int -> ConnectionState -> ShowS
[ConnectionState] -> ShowS
ConnectionState -> String
(Int -> ConnectionState -> ShowS)
-> (ConnectionState -> String)
-> ([ConnectionState] -> ShowS)
-> Show ConnectionState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ConnectionState -> ShowS
showsPrec :: Int -> ConnectionState -> ShowS
$cshow :: ConnectionState -> String
show :: ConnectionState -> String
$cshowList :: [ConnectionState] -> ShowS
showList :: [ConnectionState] -> ShowS
Show)

instance I.ShortShow ConnectionState where
  shortShow :: ConnectionState -> String
shortShow ConnectionState
ConnectionStateWaitingForNetwork
      = String
"ConnectionStateWaitingForNetwork"
  shortShow ConnectionState
ConnectionStateConnectingToProxy
      = String
"ConnectionStateConnectingToProxy"
  shortShow ConnectionState
ConnectionStateConnecting
      = String
"ConnectionStateConnecting"
  shortShow ConnectionState
ConnectionStateUpdating
      = String
"ConnectionStateUpdating"
  shortShow ConnectionState
ConnectionStateReady
      = String
"ConnectionStateReady"

instance AT.FromJSON ConnectionState where
  parseJSON :: Value -> Parser ConnectionState
parseJSON (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
"connectionStateWaitingForNetwork" -> ConnectionState -> Parser ConnectionState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ConnectionState
ConnectionStateWaitingForNetwork
      String
"connectionStateConnectingToProxy" -> ConnectionState -> Parser ConnectionState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ConnectionState
ConnectionStateConnectingToProxy
      String
"connectionStateConnecting"        -> ConnectionState -> Parser ConnectionState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ConnectionState
ConnectionStateConnecting
      String
"connectionStateUpdating"          -> ConnectionState -> Parser ConnectionState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ConnectionState
ConnectionStateUpdating
      String
"connectionStateReady"             -> ConnectionState -> Parser ConnectionState
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ConnectionState
ConnectionStateReady
      String
_                                  -> Parser ConnectionState
forall a. Monoid a => a
mempty
    
  parseJSON Value
_ = Parser ConnectionState
forall a. Monoid a => a
mempty