module TD.Data.LocationAddress
( LocationAddress(..)
, defaultLocationAddress
) 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 LocationAddress
= LocationAddress
{ LocationAddress -> Maybe Text
country_code :: Maybe T.Text
, LocationAddress -> Maybe Text
state :: Maybe T.Text
, LocationAddress -> Maybe Text
city :: Maybe T.Text
, LocationAddress -> Maybe Text
street :: Maybe T.Text
}
deriving (LocationAddress -> LocationAddress -> Bool
(LocationAddress -> LocationAddress -> Bool)
-> (LocationAddress -> LocationAddress -> Bool)
-> Eq LocationAddress
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LocationAddress -> LocationAddress -> Bool
== :: LocationAddress -> LocationAddress -> Bool
$c/= :: LocationAddress -> LocationAddress -> Bool
/= :: LocationAddress -> LocationAddress -> Bool
Eq, Int -> LocationAddress -> ShowS
[LocationAddress] -> ShowS
LocationAddress -> String
(Int -> LocationAddress -> ShowS)
-> (LocationAddress -> String)
-> ([LocationAddress] -> ShowS)
-> Show LocationAddress
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LocationAddress -> ShowS
showsPrec :: Int -> LocationAddress -> ShowS
$cshow :: LocationAddress -> String
show :: LocationAddress -> String
$cshowList :: [LocationAddress] -> ShowS
showList :: [LocationAddress] -> ShowS
Show)
instance I.ShortShow LocationAddress where
shortShow :: LocationAddress -> String
shortShow LocationAddress
{ country_code :: LocationAddress -> Maybe Text
country_code = Maybe Text
country_code_
, state :: LocationAddress -> Maybe Text
state = Maybe Text
state_
, city :: LocationAddress -> Maybe Text
city = Maybe Text
city_
, street :: LocationAddress -> Maybe Text
street = Maybe Text
street_
}
= String
"LocationAddress"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"country_code" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
country_code_
, String
"state" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
state_
, String
"city" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
city_
, String
"street" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
street_
]
instance AT.FromJSON LocationAddress where
parseJSON :: Value -> Parser LocationAddress
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
"locationAddress" -> Value -> Parser LocationAddress
parseLocationAddress Value
v
String
_ -> Parser LocationAddress
forall a. Monoid a => a
mempty
where
parseLocationAddress :: A.Value -> AT.Parser LocationAddress
parseLocationAddress :: Value -> Parser LocationAddress
parseLocationAddress = String
-> (Object -> Parser LocationAddress)
-> Value
-> Parser LocationAddress
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"LocationAddress" ((Object -> Parser LocationAddress)
-> Value -> Parser LocationAddress)
-> (Object -> Parser LocationAddress)
-> Value
-> Parser LocationAddress
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
country_code_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"country_code"
Maybe Text
state_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"state"
Maybe Text
city_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"city"
Maybe Text
street_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"street"
LocationAddress -> Parser LocationAddress
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (LocationAddress -> Parser LocationAddress)
-> LocationAddress -> Parser LocationAddress
forall a b. (a -> b) -> a -> b
$ LocationAddress
{ country_code :: Maybe Text
country_code = Maybe Text
country_code_
, state :: Maybe Text
state = Maybe Text
state_
, city :: Maybe Text
city = Maybe Text
city_
, street :: Maybe Text
street = Maybe Text
street_
}
parseJSON Value
_ = Parser LocationAddress
forall a. Monoid a => a
mempty
instance AT.ToJSON LocationAddress where
toJSON :: LocationAddress -> Value
toJSON LocationAddress
{ country_code :: LocationAddress -> Maybe Text
country_code = Maybe Text
country_code_
, state :: LocationAddress -> Maybe Text
state = Maybe Text
state_
, city :: LocationAddress -> Maybe Text
city = Maybe Text
city_
, street :: LocationAddress -> Maybe Text
street = Maybe Text
street_
}
= [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
"locationAddress"
, Key
"country_code" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
country_code_
, Key
"state" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
state_
, Key
"city" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
city_
, Key
"street" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
street_
]
defaultLocationAddress :: LocationAddress
defaultLocationAddress :: LocationAddress
defaultLocationAddress =
LocationAddress
{ country_code :: Maybe Text
country_code = Maybe Text
forall a. Maybe a
Nothing
, state :: Maybe Text
state = Maybe Text
forall a. Maybe a
Nothing
, city :: Maybe Text
city = Maybe Text
forall a. Maybe a
Nothing
, street :: Maybe Text
street = Maybe Text
forall a. Maybe a
Nothing
}