module TD.Data.OnRampProvider
  (OnRampProvider(..)) 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 OnRampProvider
  = OnRampProvider -- ^ Describes an on-ramp provider
    { OnRampProvider -> Maybe Text
_id                      :: Maybe T.Text   -- ^ Unique identifier of the provider
    , OnRampProvider -> Maybe Text
name                     :: Maybe T.Text   -- ^ Name of the provider
    , OnRampProvider -> Maybe [Text]
cryptocurrencies         :: Maybe [T.Text] -- ^ List of cryptocurrencies supported by the provider
    , OnRampProvider -> Maybe Bool
supports_base_currencies :: Maybe Bool     -- ^ True, if the provider supports base currencies and can be used in the method getOnRampProviderBaseCurrencies
    , OnRampProvider -> Maybe Bool
supports_limits          :: Maybe Bool     -- ^ True, if the provider supports limits retrieval using the method getOnRampPaymentLimits
    , OnRampProvider -> Maybe Bool
supports_quote           :: Maybe Bool     -- ^ True, if the provider supports quote retrieval using the method getOnRampPaymentQuote
    }
  deriving (OnRampProvider -> OnRampProvider -> Bool
(OnRampProvider -> OnRampProvider -> Bool)
-> (OnRampProvider -> OnRampProvider -> Bool) -> Eq OnRampProvider
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OnRampProvider -> OnRampProvider -> Bool
== :: OnRampProvider -> OnRampProvider -> Bool
$c/= :: OnRampProvider -> OnRampProvider -> Bool
/= :: OnRampProvider -> OnRampProvider -> Bool
Eq, Int -> OnRampProvider -> ShowS
[OnRampProvider] -> ShowS
OnRampProvider -> String
(Int -> OnRampProvider -> ShowS)
-> (OnRampProvider -> String)
-> ([OnRampProvider] -> ShowS)
-> Show OnRampProvider
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OnRampProvider -> ShowS
showsPrec :: Int -> OnRampProvider -> ShowS
$cshow :: OnRampProvider -> String
show :: OnRampProvider -> String
$cshowList :: [OnRampProvider] -> ShowS
showList :: [OnRampProvider] -> ShowS
Show)

instance I.ShortShow OnRampProvider where
  shortShow :: OnRampProvider -> String
shortShow OnRampProvider
    { _id :: OnRampProvider -> Maybe Text
_id                      = Maybe Text
_id_
    , name :: OnRampProvider -> Maybe Text
name                     = Maybe Text
name_
    , cryptocurrencies :: OnRampProvider -> Maybe [Text]
cryptocurrencies         = Maybe [Text]
cryptocurrencies_
    , supports_base_currencies :: OnRampProvider -> Maybe Bool
supports_base_currencies = Maybe Bool
supports_base_currencies_
    , supports_limits :: OnRampProvider -> Maybe Bool
supports_limits          = Maybe Bool
supports_limits_
    , supports_quote :: OnRampProvider -> Maybe Bool
supports_quote           = Maybe Bool
supports_quote_
    }
      = String
"OnRampProvider"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_id"                      String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
_id_
        , String
"name"                     String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
name_
        , String
"cryptocurrencies"         String -> Maybe [Text] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Text]
cryptocurrencies_
        , String
"supports_base_currencies" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
supports_base_currencies_
        , String
"supports_limits"          String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
supports_limits_
        , String
"supports_quote"           String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
supports_quote_
        ]

instance AT.FromJSON OnRampProvider where
  parseJSON :: Value -> Parser OnRampProvider
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
"onRampProvider" -> Value -> Parser OnRampProvider
parseOnRampProvider Value
v
      String
_                -> Parser OnRampProvider
forall a. Monoid a => a
mempty
    
    where
      parseOnRampProvider :: A.Value -> AT.Parser OnRampProvider
      parseOnRampProvider :: Value -> Parser OnRampProvider
parseOnRampProvider = String
-> (Object -> Parser OnRampProvider)
-> Value
-> Parser OnRampProvider
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"OnRampProvider" ((Object -> Parser OnRampProvider)
 -> Value -> Parser OnRampProvider)
-> (Object -> Parser OnRampProvider)
-> Value
-> Parser OnRampProvider
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
_id_                      <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"id"
        Maybe Text
name_                     <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"name"
        Maybe [Text]
cryptocurrencies_         <- Object
o Object -> Key -> Parser (Maybe [Text])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"cryptocurrencies"
        Maybe Bool
supports_base_currencies_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"supports_base_currencies"
        Maybe Bool
supports_limits_          <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"supports_limits"
        Maybe Bool
supports_quote_           <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"supports_quote"
        OnRampProvider -> Parser OnRampProvider
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (OnRampProvider -> Parser OnRampProvider)
-> OnRampProvider -> Parser OnRampProvider
forall a b. (a -> b) -> a -> b
$ OnRampProvider
          { _id :: Maybe Text
_id                      = Maybe Text
_id_
          , name :: Maybe Text
name                     = Maybe Text
name_
          , cryptocurrencies :: Maybe [Text]
cryptocurrencies         = Maybe [Text]
cryptocurrencies_
          , supports_base_currencies :: Maybe Bool
supports_base_currencies = Maybe Bool
supports_base_currencies_
          , supports_limits :: Maybe Bool
supports_limits          = Maybe Bool
supports_limits_
          , supports_quote :: Maybe Bool
supports_quote           = Maybe Bool
supports_quote_
          }
  parseJSON Value
_ = Parser OnRampProvider
forall a. Monoid a => a
mempty