module TD.Data.PersonalDetails
( PersonalDetails(..)
, defaultPersonalDetails
) 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.Date as Date
data PersonalDetails
= PersonalDetails
{ PersonalDetails -> Maybe Text
first_name :: Maybe T.Text
, PersonalDetails -> Maybe Text
middle_name :: Maybe T.Text
, PersonalDetails -> Maybe Text
last_name :: Maybe T.Text
, PersonalDetails -> Maybe Text
native_first_name :: Maybe T.Text
, PersonalDetails -> Maybe Text
native_middle_name :: Maybe T.Text
, PersonalDetails -> Maybe Text
native_last_name :: Maybe T.Text
, PersonalDetails -> Maybe Date
birthdate :: Maybe Date.Date
, PersonalDetails -> Maybe Text
gender :: Maybe T.Text
, PersonalDetails -> Maybe Text
country_code :: Maybe T.Text
, PersonalDetails -> Maybe Text
residence_country_code :: Maybe T.Text
}
deriving (PersonalDetails -> PersonalDetails -> Bool
(PersonalDetails -> PersonalDetails -> Bool)
-> (PersonalDetails -> PersonalDetails -> Bool)
-> Eq PersonalDetails
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PersonalDetails -> PersonalDetails -> Bool
== :: PersonalDetails -> PersonalDetails -> Bool
$c/= :: PersonalDetails -> PersonalDetails -> Bool
/= :: PersonalDetails -> PersonalDetails -> Bool
Eq, Int -> PersonalDetails -> ShowS
[PersonalDetails] -> ShowS
PersonalDetails -> String
(Int -> PersonalDetails -> ShowS)
-> (PersonalDetails -> String)
-> ([PersonalDetails] -> ShowS)
-> Show PersonalDetails
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PersonalDetails -> ShowS
showsPrec :: Int -> PersonalDetails -> ShowS
$cshow :: PersonalDetails -> String
show :: PersonalDetails -> String
$cshowList :: [PersonalDetails] -> ShowS
showList :: [PersonalDetails] -> ShowS
Show)
instance I.ShortShow PersonalDetails where
shortShow :: PersonalDetails -> String
shortShow PersonalDetails
{ first_name :: PersonalDetails -> Maybe Text
first_name = Maybe Text
first_name_
, middle_name :: PersonalDetails -> Maybe Text
middle_name = Maybe Text
middle_name_
, last_name :: PersonalDetails -> Maybe Text
last_name = Maybe Text
last_name_
, native_first_name :: PersonalDetails -> Maybe Text
native_first_name = Maybe Text
native_first_name_
, native_middle_name :: PersonalDetails -> Maybe Text
native_middle_name = Maybe Text
native_middle_name_
, native_last_name :: PersonalDetails -> Maybe Text
native_last_name = Maybe Text
native_last_name_
, birthdate :: PersonalDetails -> Maybe Date
birthdate = Maybe Date
birthdate_
, gender :: PersonalDetails -> Maybe Text
gender = Maybe Text
gender_
, country_code :: PersonalDetails -> Maybe Text
country_code = Maybe Text
country_code_
, residence_country_code :: PersonalDetails -> Maybe Text
residence_country_code = Maybe Text
residence_country_code_
}
= String
"PersonalDetails"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"first_name" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
first_name_
, String
"middle_name" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
middle_name_
, String
"last_name" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
last_name_
, String
"native_first_name" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
native_first_name_
, String
"native_middle_name" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
native_middle_name_
, String
"native_last_name" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
native_last_name_
, String
"birthdate" String -> Maybe Date -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Date
birthdate_
, String
"gender" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
gender_
, String
"country_code" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
country_code_
, String
"residence_country_code" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
residence_country_code_
]
instance AT.FromJSON PersonalDetails where
parseJSON :: Value -> Parser PersonalDetails
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
"personalDetails" -> Value -> Parser PersonalDetails
parsePersonalDetails Value
v
String
_ -> Parser PersonalDetails
forall a. Monoid a => a
mempty
where
parsePersonalDetails :: A.Value -> AT.Parser PersonalDetails
parsePersonalDetails :: Value -> Parser PersonalDetails
parsePersonalDetails = String
-> (Object -> Parser PersonalDetails)
-> Value
-> Parser PersonalDetails
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PersonalDetails" ((Object -> Parser PersonalDetails)
-> Value -> Parser PersonalDetails)
-> (Object -> Parser PersonalDetails)
-> Value
-> Parser PersonalDetails
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
first_name_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"first_name"
Maybe Text
middle_name_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"middle_name"
Maybe Text
last_name_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"last_name"
Maybe Text
native_first_name_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"native_first_name"
Maybe Text
native_middle_name_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"native_middle_name"
Maybe Text
native_last_name_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"native_last_name"
Maybe Date
birthdate_ <- Object
o Object -> Key -> Parser (Maybe Date)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"birthdate"
Maybe Text
gender_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"gender"
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
residence_country_code_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"residence_country_code"
PersonalDetails -> Parser PersonalDetails
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PersonalDetails -> Parser PersonalDetails)
-> PersonalDetails -> Parser PersonalDetails
forall a b. (a -> b) -> a -> b
$ PersonalDetails
{ first_name :: Maybe Text
first_name = Maybe Text
first_name_
, middle_name :: Maybe Text
middle_name = Maybe Text
middle_name_
, last_name :: Maybe Text
last_name = Maybe Text
last_name_
, native_first_name :: Maybe Text
native_first_name = Maybe Text
native_first_name_
, native_middle_name :: Maybe Text
native_middle_name = Maybe Text
native_middle_name_
, native_last_name :: Maybe Text
native_last_name = Maybe Text
native_last_name_
, birthdate :: Maybe Date
birthdate = Maybe Date
birthdate_
, gender :: Maybe Text
gender = Maybe Text
gender_
, country_code :: Maybe Text
country_code = Maybe Text
country_code_
, residence_country_code :: Maybe Text
residence_country_code = Maybe Text
residence_country_code_
}
parseJSON Value
_ = Parser PersonalDetails
forall a. Monoid a => a
mempty
instance AT.ToJSON PersonalDetails where
toJSON :: PersonalDetails -> Value
toJSON PersonalDetails
{ first_name :: PersonalDetails -> Maybe Text
first_name = Maybe Text
first_name_
, middle_name :: PersonalDetails -> Maybe Text
middle_name = Maybe Text
middle_name_
, last_name :: PersonalDetails -> Maybe Text
last_name = Maybe Text
last_name_
, native_first_name :: PersonalDetails -> Maybe Text
native_first_name = Maybe Text
native_first_name_
, native_middle_name :: PersonalDetails -> Maybe Text
native_middle_name = Maybe Text
native_middle_name_
, native_last_name :: PersonalDetails -> Maybe Text
native_last_name = Maybe Text
native_last_name_
, birthdate :: PersonalDetails -> Maybe Date
birthdate = Maybe Date
birthdate_
, gender :: PersonalDetails -> Maybe Text
gender = Maybe Text
gender_
, country_code :: PersonalDetails -> Maybe Text
country_code = Maybe Text
country_code_
, residence_country_code :: PersonalDetails -> Maybe Text
residence_country_code = Maybe Text
residence_country_code_
}
= [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
"personalDetails"
, Key
"first_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
first_name_
, Key
"middle_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
middle_name_
, Key
"last_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
last_name_
, Key
"native_first_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
native_first_name_
, Key
"native_middle_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
native_middle_name_
, Key
"native_last_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
native_last_name_
, Key
"birthdate" Key -> Maybe Date -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Date
birthdate_
, Key
"gender" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
gender_
, 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
"residence_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
residence_country_code_
]
defaultPersonalDetails :: PersonalDetails
defaultPersonalDetails :: PersonalDetails
defaultPersonalDetails =
PersonalDetails
{ first_name :: Maybe Text
first_name = Maybe Text
forall a. Maybe a
Nothing
, middle_name :: Maybe Text
middle_name = Maybe Text
forall a. Maybe a
Nothing
, last_name :: Maybe Text
last_name = Maybe Text
forall a. Maybe a
Nothing
, native_first_name :: Maybe Text
native_first_name = Maybe Text
forall a. Maybe a
Nothing
, native_middle_name :: Maybe Text
native_middle_name = Maybe Text
forall a. Maybe a
Nothing
, native_last_name :: Maybe Text
native_last_name = Maybe Text
forall a. Maybe a
Nothing
, birthdate :: Maybe Date
birthdate = Maybe Date
forall a. Maybe a
Nothing
, gender :: Maybe Text
gender = Maybe Text
forall a. Maybe a
Nothing
, country_code :: Maybe Text
country_code = Maybe Text
forall a. Maybe a
Nothing
, residence_country_code :: Maybe Text
residence_country_code = Maybe Text
forall a. Maybe a
Nothing
}