module TD.Data.OnRampPaymentMethod
  (OnRampPaymentMethod(..)) 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 OnRampPaymentMethod
  = OnRampPaymentMethod -- ^ Describes a payment method of an on-ramp provider
    { OnRampPaymentMethod -> Maybe Text
name         :: Maybe T.Text -- ^ Name of the method
    , OnRampPaymentMethod -> Maybe Bool
is_available :: Maybe Bool   -- ^ True, if the method is available to the user
    }
  deriving (OnRampPaymentMethod -> OnRampPaymentMethod -> Bool
(OnRampPaymentMethod -> OnRampPaymentMethod -> Bool)
-> (OnRampPaymentMethod -> OnRampPaymentMethod -> Bool)
-> Eq OnRampPaymentMethod
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OnRampPaymentMethod -> OnRampPaymentMethod -> Bool
== :: OnRampPaymentMethod -> OnRampPaymentMethod -> Bool
$c/= :: OnRampPaymentMethod -> OnRampPaymentMethod -> Bool
/= :: OnRampPaymentMethod -> OnRampPaymentMethod -> Bool
Eq, Int -> OnRampPaymentMethod -> ShowS
[OnRampPaymentMethod] -> ShowS
OnRampPaymentMethod -> String
(Int -> OnRampPaymentMethod -> ShowS)
-> (OnRampPaymentMethod -> String)
-> ([OnRampPaymentMethod] -> ShowS)
-> Show OnRampPaymentMethod
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OnRampPaymentMethod -> ShowS
showsPrec :: Int -> OnRampPaymentMethod -> ShowS
$cshow :: OnRampPaymentMethod -> String
show :: OnRampPaymentMethod -> String
$cshowList :: [OnRampPaymentMethod] -> ShowS
showList :: [OnRampPaymentMethod] -> ShowS
Show)

instance I.ShortShow OnRampPaymentMethod where
  shortShow :: OnRampPaymentMethod -> String
shortShow OnRampPaymentMethod
    { name :: OnRampPaymentMethod -> Maybe Text
name         = Maybe Text
name_
    , is_available :: OnRampPaymentMethod -> Maybe Bool
is_available = Maybe Bool
is_available_
    }
      = String
"OnRampPaymentMethod"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"name"         String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
name_
        , String
"is_available" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_available_
        ]

instance AT.FromJSON OnRampPaymentMethod where
  parseJSON :: Value -> Parser OnRampPaymentMethod
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
"onRampPaymentMethod" -> Value -> Parser OnRampPaymentMethod
parseOnRampPaymentMethod Value
v
      String
_                     -> Parser OnRampPaymentMethod
forall a. Monoid a => a
mempty
    
    where
      parseOnRampPaymentMethod :: A.Value -> AT.Parser OnRampPaymentMethod
      parseOnRampPaymentMethod :: Value -> Parser OnRampPaymentMethod
parseOnRampPaymentMethod = String
-> (Object -> Parser OnRampPaymentMethod)
-> Value
-> Parser OnRampPaymentMethod
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"OnRampPaymentMethod" ((Object -> Parser OnRampPaymentMethod)
 -> Value -> Parser OnRampPaymentMethod)
-> (Object -> Parser OnRampPaymentMethod)
-> Value
-> Parser OnRampPaymentMethod
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
name_         <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"name"
        Maybe Bool
is_available_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_available"
        OnRampPaymentMethod -> Parser OnRampPaymentMethod
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (OnRampPaymentMethod -> Parser OnRampPaymentMethod)
-> OnRampPaymentMethod -> Parser OnRampPaymentMethod
forall a b. (a -> b) -> a -> b
$ OnRampPaymentMethod
          { name :: Maybe Text
name         = Maybe Text
name_
          , is_available :: Maybe Bool
is_available = Maybe Bool
is_available_
          }
  parseJSON Value
_ = Parser OnRampPaymentMethod
forall a. Monoid a => a
mempty