module TD.Data.TonCenterStreamingApiUrl
  (TonCenterStreamingApiUrl(..)) 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

data TonCenterStreamingApiUrl
  = TonCenterStreamingApiUrl -- ^ Contains an HTTP URL for TON Center Streaming API
    { TonCenterStreamingApiUrl -> Maybe Text
url        :: Maybe T.Text -- ^ The URL
    , TonCenterStreamingApiUrl -> Maybe Int
expires_in :: Maybe Int    -- ^ Time after which the URL expires
    }
  deriving (TonCenterStreamingApiUrl -> TonCenterStreamingApiUrl -> Bool
(TonCenterStreamingApiUrl -> TonCenterStreamingApiUrl -> Bool)
-> (TonCenterStreamingApiUrl -> TonCenterStreamingApiUrl -> Bool)
-> Eq TonCenterStreamingApiUrl
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TonCenterStreamingApiUrl -> TonCenterStreamingApiUrl -> Bool
== :: TonCenterStreamingApiUrl -> TonCenterStreamingApiUrl -> Bool
$c/= :: TonCenterStreamingApiUrl -> TonCenterStreamingApiUrl -> Bool
/= :: TonCenterStreamingApiUrl -> TonCenterStreamingApiUrl -> Bool
Eq, Int -> TonCenterStreamingApiUrl -> ShowS
[TonCenterStreamingApiUrl] -> ShowS
TonCenterStreamingApiUrl -> String
(Int -> TonCenterStreamingApiUrl -> ShowS)
-> (TonCenterStreamingApiUrl -> String)
-> ([TonCenterStreamingApiUrl] -> ShowS)
-> Show TonCenterStreamingApiUrl
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TonCenterStreamingApiUrl -> ShowS
showsPrec :: Int -> TonCenterStreamingApiUrl -> ShowS
$cshow :: TonCenterStreamingApiUrl -> String
show :: TonCenterStreamingApiUrl -> String
$cshowList :: [TonCenterStreamingApiUrl] -> ShowS
showList :: [TonCenterStreamingApiUrl] -> ShowS
Show)

instance I.ShortShow TonCenterStreamingApiUrl where
  shortShow :: TonCenterStreamingApiUrl -> String
shortShow TonCenterStreamingApiUrl
    { url :: TonCenterStreamingApiUrl -> Maybe Text
url        = Maybe Text
url_
    , expires_in :: TonCenterStreamingApiUrl -> Maybe Int
expires_in = Maybe Int
expires_in_
    }
      = String
"TonCenterStreamingApiUrl"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"url"        String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
url_
        , String
"expires_in" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
expires_in_
        ]

instance AT.FromJSON TonCenterStreamingApiUrl where
  parseJSON :: Value -> Parser TonCenterStreamingApiUrl
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
"tonCenterStreamingApiUrl" -> Value -> Parser TonCenterStreamingApiUrl
parseTonCenterStreamingApiUrl Value
v
      String
_                          -> Parser TonCenterStreamingApiUrl
forall a. Monoid a => a
mempty
    
    where
      parseTonCenterStreamingApiUrl :: A.Value -> AT.Parser TonCenterStreamingApiUrl
      parseTonCenterStreamingApiUrl :: Value -> Parser TonCenterStreamingApiUrl
parseTonCenterStreamingApiUrl = String
-> (Object -> Parser TonCenterStreamingApiUrl)
-> Value
-> Parser TonCenterStreamingApiUrl
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"TonCenterStreamingApiUrl" ((Object -> Parser TonCenterStreamingApiUrl)
 -> Value -> Parser TonCenterStreamingApiUrl)
-> (Object -> Parser TonCenterStreamingApiUrl)
-> Value
-> Parser TonCenterStreamingApiUrl
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
url_        <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"url"
        Maybe Int
expires_in_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"expires_in"
        TonCenterStreamingApiUrl -> Parser TonCenterStreamingApiUrl
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TonCenterStreamingApiUrl -> Parser TonCenterStreamingApiUrl)
-> TonCenterStreamingApiUrl -> Parser TonCenterStreamingApiUrl
forall a b. (a -> b) -> a -> b
$ TonCenterStreamingApiUrl
          { url :: Maybe Text
url        = Maybe Text
url_
          , expires_in :: Maybe Int
expires_in = Maybe Int
expires_in_
          }
  parseJSON Value
_ = Parser TonCenterStreamingApiUrl
forall a. Monoid a => a
mempty