module TD.Data.CallServer
(CallServer(..)) 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
import qualified TD.Data.CallServerType as CallServerType
data CallServer
= CallServer
{ CallServer -> Maybe Int
_id :: Maybe Int
, CallServer -> Maybe Text
ip_address :: Maybe T.Text
, CallServer -> Maybe Text
ipv6_address :: Maybe T.Text
, CallServer -> Maybe Int
port :: Maybe Int
, CallServer -> Maybe CallServerType
_type :: Maybe CallServerType.CallServerType
}
deriving (CallServer -> CallServer -> Bool
(CallServer -> CallServer -> Bool)
-> (CallServer -> CallServer -> Bool) -> Eq CallServer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CallServer -> CallServer -> Bool
== :: CallServer -> CallServer -> Bool
$c/= :: CallServer -> CallServer -> Bool
/= :: CallServer -> CallServer -> Bool
Eq, Int -> CallServer -> ShowS
[CallServer] -> ShowS
CallServer -> String
(Int -> CallServer -> ShowS)
-> (CallServer -> String)
-> ([CallServer] -> ShowS)
-> Show CallServer
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CallServer -> ShowS
showsPrec :: Int -> CallServer -> ShowS
$cshow :: CallServer -> String
show :: CallServer -> String
$cshowList :: [CallServer] -> ShowS
showList :: [CallServer] -> ShowS
Show)
instance I.ShortShow CallServer where
shortShow :: CallServer -> String
shortShow CallServer
{ _id :: CallServer -> Maybe Int
_id = Maybe Int
_id_
, ip_address :: CallServer -> Maybe Text
ip_address = Maybe Text
ip_address_
, ipv6_address :: CallServer -> Maybe Text
ipv6_address = Maybe Text
ipv6_address_
, port :: CallServer -> Maybe Int
port = Maybe Int
port_
, _type :: CallServer -> Maybe CallServerType
_type = Maybe CallServerType
_type_
}
= String
"CallServer"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
_id_
, String
"ip_address" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
ip_address_
, String
"ipv6_address" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
ipv6_address_
, String
"port" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
port_
, String
"_type" String -> Maybe CallServerType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe CallServerType
_type_
]
instance AT.FromJSON CallServer where
parseJSON :: Value -> Parser CallServer
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
"callServer" -> Value -> Parser CallServer
parseCallServer Value
v
String
_ -> Parser CallServer
forall a. Monoid a => a
mempty
where
parseCallServer :: A.Value -> AT.Parser CallServer
parseCallServer :: Value -> Parser CallServer
parseCallServer = String
-> (Object -> Parser CallServer) -> Value -> Parser CallServer
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"CallServer" ((Object -> Parser CallServer) -> Value -> Parser CallServer)
-> (Object -> Parser CallServer) -> Value -> Parser CallServer
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
_id_ <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"id"
Maybe Text
ip_address_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"ip_address"
Maybe Text
ipv6_address_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"ipv6_address"
Maybe Int
port_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"port"
Maybe CallServerType
_type_ <- Object
o Object -> Key -> Parser (Maybe CallServerType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"type"
CallServer -> Parser CallServer
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CallServer -> Parser CallServer)
-> CallServer -> Parser CallServer
forall a b. (a -> b) -> a -> b
$ CallServer
{ _id :: Maybe Int
_id = Maybe Int
_id_
, ip_address :: Maybe Text
ip_address = Maybe Text
ip_address_
, ipv6_address :: Maybe Text
ipv6_address = Maybe Text
ipv6_address_
, port :: Maybe Int
port = Maybe Int
port_
, _type :: Maybe CallServerType
_type = Maybe CallServerType
_type_
}
parseJSON Value
_ = Parser CallServer
forall a. Monoid a => a
mempty