module TD.Query.SetNetworkType
  (SetNetworkType(..)
  ) 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.NetworkType as NetworkType

-- | Sets the current network type. Can be called before authorization. Calling this method forces all network connections to reopen, mitigating the delay in switching between different networks, so it must be called whenever the network is changed, even if the network type remains the same. Network type is used to check whether the library can use the network at all and also for collecting detailed network data usage statistics. Returns 'TD.Data.Ok.Ok'
data SetNetworkType
  = SetNetworkType
    { SetNetworkType -> Maybe NetworkType
_type :: Maybe NetworkType.NetworkType -- ^ The new network type; pass null to set network type to networkTypeOther
    }
  deriving (SetNetworkType -> SetNetworkType -> Bool
(SetNetworkType -> SetNetworkType -> Bool)
-> (SetNetworkType -> SetNetworkType -> Bool) -> Eq SetNetworkType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetNetworkType -> SetNetworkType -> Bool
== :: SetNetworkType -> SetNetworkType -> Bool
$c/= :: SetNetworkType -> SetNetworkType -> Bool
/= :: SetNetworkType -> SetNetworkType -> Bool
Eq, Int -> SetNetworkType -> ShowS
[SetNetworkType] -> ShowS
SetNetworkType -> String
(Int -> SetNetworkType -> ShowS)
-> (SetNetworkType -> String)
-> ([SetNetworkType] -> ShowS)
-> Show SetNetworkType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetNetworkType -> ShowS
showsPrec :: Int -> SetNetworkType -> ShowS
$cshow :: SetNetworkType -> String
show :: SetNetworkType -> String
$cshowList :: [SetNetworkType] -> ShowS
showList :: [SetNetworkType] -> ShowS
Show)

instance I.ShortShow SetNetworkType where
  shortShow :: SetNetworkType -> String
shortShow
    SetNetworkType
      { _type :: SetNetworkType -> Maybe NetworkType
_type = Maybe NetworkType
_type_
      }
        = String
"SetNetworkType"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"_type" String -> Maybe NetworkType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe NetworkType
_type_
          ]

instance AT.ToJSON SetNetworkType where
  toJSON :: SetNetworkType -> Value
toJSON
    SetNetworkType
      { _type :: SetNetworkType -> Maybe NetworkType
_type = Maybe NetworkType
_type_
      }
        = [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
"setNetworkType"
          , Key
"type"  Key -> Maybe NetworkType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe NetworkType
_type_
          ]