module TD.Data.ValidatedOrderInfo
(ValidatedOrderInfo(..)) 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.ShippingOption as ShippingOption
data ValidatedOrderInfo
= ValidatedOrderInfo
{ ValidatedOrderInfo -> Maybe Text
order_info_id :: Maybe T.Text
, ValidatedOrderInfo -> Maybe [ShippingOption]
shipping_options :: Maybe [ShippingOption.ShippingOption]
}
deriving (ValidatedOrderInfo -> ValidatedOrderInfo -> Bool
(ValidatedOrderInfo -> ValidatedOrderInfo -> Bool)
-> (ValidatedOrderInfo -> ValidatedOrderInfo -> Bool)
-> Eq ValidatedOrderInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ValidatedOrderInfo -> ValidatedOrderInfo -> Bool
== :: ValidatedOrderInfo -> ValidatedOrderInfo -> Bool
$c/= :: ValidatedOrderInfo -> ValidatedOrderInfo -> Bool
/= :: ValidatedOrderInfo -> ValidatedOrderInfo -> Bool
Eq, Int -> ValidatedOrderInfo -> ShowS
[ValidatedOrderInfo] -> ShowS
ValidatedOrderInfo -> String
(Int -> ValidatedOrderInfo -> ShowS)
-> (ValidatedOrderInfo -> String)
-> ([ValidatedOrderInfo] -> ShowS)
-> Show ValidatedOrderInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ValidatedOrderInfo -> ShowS
showsPrec :: Int -> ValidatedOrderInfo -> ShowS
$cshow :: ValidatedOrderInfo -> String
show :: ValidatedOrderInfo -> String
$cshowList :: [ValidatedOrderInfo] -> ShowS
showList :: [ValidatedOrderInfo] -> ShowS
Show)
instance I.ShortShow ValidatedOrderInfo where
shortShow :: ValidatedOrderInfo -> String
shortShow ValidatedOrderInfo
{ order_info_id :: ValidatedOrderInfo -> Maybe Text
order_info_id = Maybe Text
order_info_id_
, shipping_options :: ValidatedOrderInfo -> Maybe [ShippingOption]
shipping_options = Maybe [ShippingOption]
shipping_options_
}
= String
"ValidatedOrderInfo"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"order_info_id" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
order_info_id_
, String
"shipping_options" String -> Maybe [ShippingOption] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [ShippingOption]
shipping_options_
]
instance AT.FromJSON ValidatedOrderInfo where
parseJSON :: Value -> Parser ValidatedOrderInfo
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
"validatedOrderInfo" -> Value -> Parser ValidatedOrderInfo
parseValidatedOrderInfo Value
v
String
_ -> Parser ValidatedOrderInfo
forall a. Monoid a => a
mempty
where
parseValidatedOrderInfo :: A.Value -> AT.Parser ValidatedOrderInfo
parseValidatedOrderInfo :: Value -> Parser ValidatedOrderInfo
parseValidatedOrderInfo = String
-> (Object -> Parser ValidatedOrderInfo)
-> Value
-> Parser ValidatedOrderInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ValidatedOrderInfo" ((Object -> Parser ValidatedOrderInfo)
-> Value -> Parser ValidatedOrderInfo)
-> (Object -> Parser ValidatedOrderInfo)
-> Value
-> Parser ValidatedOrderInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
order_info_id_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"order_info_id"
Maybe [ShippingOption]
shipping_options_ <- Object
o Object -> Key -> Parser (Maybe [ShippingOption])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"shipping_options"
ValidatedOrderInfo -> Parser ValidatedOrderInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ValidatedOrderInfo -> Parser ValidatedOrderInfo)
-> ValidatedOrderInfo -> Parser ValidatedOrderInfo
forall a b. (a -> b) -> a -> b
$ ValidatedOrderInfo
{ order_info_id :: Maybe Text
order_info_id = Maybe Text
order_info_id_
, shipping_options :: Maybe [ShippingOption]
shipping_options = Maybe [ShippingOption]
shipping_options_
}
parseJSON Value
_ = Parser ValidatedOrderInfo
forall a. Monoid a => a
mempty