module TD.Data.OnRampPaymentSession
  (OnRampPaymentSession(..)) 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 OnRampPaymentSession
  = OnRampPaymentSession -- ^ Describes a session for an on-ramp purchase
    { OnRampPaymentSession -> Maybe Text
session_id      :: Maybe T.Text -- ^ Identifier of the session
    , OnRampPaymentSession -> Maybe Int
expiration_date :: Maybe Int    -- ^ Point in time (Unix timestamp) when the session will expire
    , OnRampPaymentSession -> Maybe Text
url             :: Maybe T.Text -- ^ HTTPS URL to be opened in a WebView to complete the purchase
    }
  deriving (OnRampPaymentSession -> OnRampPaymentSession -> Bool
(OnRampPaymentSession -> OnRampPaymentSession -> Bool)
-> (OnRampPaymentSession -> OnRampPaymentSession -> Bool)
-> Eq OnRampPaymentSession
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OnRampPaymentSession -> OnRampPaymentSession -> Bool
== :: OnRampPaymentSession -> OnRampPaymentSession -> Bool
$c/= :: OnRampPaymentSession -> OnRampPaymentSession -> Bool
/= :: OnRampPaymentSession -> OnRampPaymentSession -> Bool
Eq, Int -> OnRampPaymentSession -> ShowS
[OnRampPaymentSession] -> ShowS
OnRampPaymentSession -> String
(Int -> OnRampPaymentSession -> ShowS)
-> (OnRampPaymentSession -> String)
-> ([OnRampPaymentSession] -> ShowS)
-> Show OnRampPaymentSession
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OnRampPaymentSession -> ShowS
showsPrec :: Int -> OnRampPaymentSession -> ShowS
$cshow :: OnRampPaymentSession -> String
show :: OnRampPaymentSession -> String
$cshowList :: [OnRampPaymentSession] -> ShowS
showList :: [OnRampPaymentSession] -> ShowS
Show)

instance I.ShortShow OnRampPaymentSession where
  shortShow :: OnRampPaymentSession -> String
shortShow OnRampPaymentSession
    { session_id :: OnRampPaymentSession -> Maybe Text
session_id      = Maybe Text
session_id_
    , expiration_date :: OnRampPaymentSession -> Maybe Int
expiration_date = Maybe Int
expiration_date_
    , url :: OnRampPaymentSession -> Maybe Text
url             = Maybe Text
url_
    }
      = String
"OnRampPaymentSession"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"session_id"      String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
session_id_
        , String
"expiration_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
expiration_date_
        , String
"url"             String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
url_
        ]

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