module TD.Data.ShippingOption
( ShippingOption(..)
, defaultShippingOption
) 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.LabeledPricePart as LabeledPricePart
data ShippingOption
= ShippingOption
{ ShippingOption -> Maybe Text
_id :: Maybe T.Text
, ShippingOption -> Maybe Text
title :: Maybe T.Text
, ShippingOption -> Maybe [LabeledPricePart]
price_parts :: Maybe [LabeledPricePart.LabeledPricePart]
}
deriving (ShippingOption -> ShippingOption -> Bool
(ShippingOption -> ShippingOption -> Bool)
-> (ShippingOption -> ShippingOption -> Bool) -> Eq ShippingOption
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ShippingOption -> ShippingOption -> Bool
== :: ShippingOption -> ShippingOption -> Bool
$c/= :: ShippingOption -> ShippingOption -> Bool
/= :: ShippingOption -> ShippingOption -> Bool
Eq, Int -> ShippingOption -> ShowS
[ShippingOption] -> ShowS
ShippingOption -> String
(Int -> ShippingOption -> ShowS)
-> (ShippingOption -> String)
-> ([ShippingOption] -> ShowS)
-> Show ShippingOption
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ShippingOption -> ShowS
showsPrec :: Int -> ShippingOption -> ShowS
$cshow :: ShippingOption -> String
show :: ShippingOption -> String
$cshowList :: [ShippingOption] -> ShowS
showList :: [ShippingOption] -> ShowS
Show)
instance I.ShortShow ShippingOption where
shortShow :: ShippingOption -> String
shortShow ShippingOption
{ _id :: ShippingOption -> Maybe Text
_id = Maybe Text
_id_
, title :: ShippingOption -> Maybe Text
title = Maybe Text
title_
, price_parts :: ShippingOption -> Maybe [LabeledPricePart]
price_parts = Maybe [LabeledPricePart]
price_parts_
}
= String
"ShippingOption"
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
"title" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
, String
"price_parts" String -> Maybe [LabeledPricePart] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [LabeledPricePart]
price_parts_
]
instance AT.FromJSON ShippingOption where
parseJSON :: Value -> Parser ShippingOption
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
"shippingOption" -> Value -> Parser ShippingOption
parseShippingOption Value
v
String
_ -> Parser ShippingOption
forall a. Monoid a => a
mempty
where
parseShippingOption :: A.Value -> AT.Parser ShippingOption
parseShippingOption :: Value -> Parser ShippingOption
parseShippingOption = String
-> (Object -> Parser ShippingOption)
-> Value
-> Parser ShippingOption
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ShippingOption" ((Object -> Parser ShippingOption)
-> Value -> Parser ShippingOption)
-> (Object -> Parser ShippingOption)
-> Value
-> Parser ShippingOption
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
title_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"title"
Maybe [LabeledPricePart]
price_parts_ <- Object
o Object -> Key -> Parser (Maybe [LabeledPricePart])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"price_parts"
ShippingOption -> Parser ShippingOption
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ShippingOption -> Parser ShippingOption)
-> ShippingOption -> Parser ShippingOption
forall a b. (a -> b) -> a -> b
$ ShippingOption
{ _id :: Maybe Text
_id = Maybe Text
_id_
, title :: Maybe Text
title = Maybe Text
title_
, price_parts :: Maybe [LabeledPricePart]
price_parts = Maybe [LabeledPricePart]
price_parts_
}
parseJSON Value
_ = Parser ShippingOption
forall a. Monoid a => a
mempty
instance AT.ToJSON ShippingOption where
toJSON :: ShippingOption -> Value
toJSON ShippingOption
{ _id :: ShippingOption -> Maybe Text
_id = Maybe Text
_id_
, title :: ShippingOption -> Maybe Text
title = Maybe Text
title_
, price_parts :: ShippingOption -> Maybe [LabeledPricePart]
price_parts = Maybe [LabeledPricePart]
price_parts_
}
= [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
"shippingOption"
, Key
"id" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
_id_
, Key
"title" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
title_
, Key
"price_parts" Key -> Maybe [LabeledPricePart] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [LabeledPricePart]
price_parts_
]
defaultShippingOption :: ShippingOption
defaultShippingOption :: ShippingOption
defaultShippingOption =
ShippingOption
{ _id :: Maybe Text
_id = Maybe Text
forall a. Maybe a
Nothing
, title :: Maybe Text
title = Maybe Text
forall a. Maybe a
Nothing
, price_parts :: Maybe [LabeledPricePart]
price_parts = Maybe [LabeledPricePart]
forall a. Maybe a
Nothing
}