module TD.Data.OrderInfo
( OrderInfo(..)
, defaultOrderInfo
) 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.Address as Address
data OrderInfo
= OrderInfo
{ OrderInfo -> Maybe Text
name :: Maybe T.Text
, OrderInfo -> Maybe Text
phone_number :: Maybe T.Text
, OrderInfo -> Maybe Text
email_address :: Maybe T.Text
, OrderInfo -> Maybe Address
shipping_address :: Maybe Address.Address
}
deriving (OrderInfo -> OrderInfo -> Bool
(OrderInfo -> OrderInfo -> Bool)
-> (OrderInfo -> OrderInfo -> Bool) -> Eq OrderInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OrderInfo -> OrderInfo -> Bool
== :: OrderInfo -> OrderInfo -> Bool
$c/= :: OrderInfo -> OrderInfo -> Bool
/= :: OrderInfo -> OrderInfo -> Bool
Eq, Int -> OrderInfo -> ShowS
[OrderInfo] -> ShowS
OrderInfo -> String
(Int -> OrderInfo -> ShowS)
-> (OrderInfo -> String)
-> ([OrderInfo] -> ShowS)
-> Show OrderInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OrderInfo -> ShowS
showsPrec :: Int -> OrderInfo -> ShowS
$cshow :: OrderInfo -> String
show :: OrderInfo -> String
$cshowList :: [OrderInfo] -> ShowS
showList :: [OrderInfo] -> ShowS
Show)
instance I.ShortShow OrderInfo where
shortShow :: OrderInfo -> String
shortShow OrderInfo
{ name :: OrderInfo -> Maybe Text
name = Maybe Text
name_
, phone_number :: OrderInfo -> Maybe Text
phone_number = Maybe Text
phone_number_
, email_address :: OrderInfo -> Maybe Text
email_address = Maybe Text
email_address_
, shipping_address :: OrderInfo -> Maybe Address
shipping_address = Maybe Address
shipping_address_
}
= String
"OrderInfo"
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
"phone_number" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
phone_number_
, String
"email_address" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
email_address_
, String
"shipping_address" String -> Maybe Address -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Address
shipping_address_
]
instance AT.FromJSON OrderInfo where
parseJSON :: Value -> Parser OrderInfo
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
"orderInfo" -> Value -> Parser OrderInfo
parseOrderInfo Value
v
String
_ -> Parser OrderInfo
forall a. Monoid a => a
mempty
where
parseOrderInfo :: A.Value -> AT.Parser OrderInfo
parseOrderInfo :: Value -> Parser OrderInfo
parseOrderInfo = String -> (Object -> Parser OrderInfo) -> Value -> Parser OrderInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"OrderInfo" ((Object -> Parser OrderInfo) -> Value -> Parser OrderInfo)
-> (Object -> Parser OrderInfo) -> Value -> Parser OrderInfo
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 Text
phone_number_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"phone_number"
Maybe Text
email_address_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"email_address"
Maybe Address
shipping_address_ <- Object
o Object -> Key -> Parser (Maybe Address)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"shipping_address"
OrderInfo -> Parser OrderInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (OrderInfo -> Parser OrderInfo) -> OrderInfo -> Parser OrderInfo
forall a b. (a -> b) -> a -> b
$ OrderInfo
{ name :: Maybe Text
name = Maybe Text
name_
, phone_number :: Maybe Text
phone_number = Maybe Text
phone_number_
, email_address :: Maybe Text
email_address = Maybe Text
email_address_
, shipping_address :: Maybe Address
shipping_address = Maybe Address
shipping_address_
}
parseJSON Value
_ = Parser OrderInfo
forall a. Monoid a => a
mempty
instance AT.ToJSON OrderInfo where
toJSON :: OrderInfo -> Value
toJSON OrderInfo
{ name :: OrderInfo -> Maybe Text
name = Maybe Text
name_
, phone_number :: OrderInfo -> Maybe Text
phone_number = Maybe Text
phone_number_
, email_address :: OrderInfo -> Maybe Text
email_address = Maybe Text
email_address_
, shipping_address :: OrderInfo -> Maybe Address
shipping_address = Maybe Address
shipping_address_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"orderInfo"
, Key
"name" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
name_
, Key
"phone_number" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
phone_number_
, Key
"email_address" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
email_address_
, Key
"shipping_address" Key -> Maybe Address -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Address
shipping_address_
]
defaultOrderInfo :: OrderInfo
defaultOrderInfo :: OrderInfo
defaultOrderInfo =
OrderInfo
{ name :: Maybe Text
name = Maybe Text
forall a. Maybe a
Nothing
, phone_number :: Maybe Text
phone_number = Maybe Text
forall a. Maybe a
Nothing
, email_address :: Maybe Text
email_address = Maybe Text
forall a. Maybe a
Nothing
, shipping_address :: Maybe Address
shipping_address = Maybe Address
forall a. Maybe a
Nothing
}