module TD.Data.AccountInfo
(AccountInfo(..)) 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 AccountInfo
= AccountInfo
{ AccountInfo -> Maybe Int
registration_month :: Maybe Int
, AccountInfo -> Maybe Int
registration_year :: Maybe Int
, AccountInfo -> Maybe Text
phone_number_country_code :: Maybe T.Text
, AccountInfo -> Maybe Int
last_name_change_date :: Maybe Int
, AccountInfo -> Maybe Int
last_photo_change_date :: Maybe Int
}
deriving (AccountInfo -> AccountInfo -> Bool
(AccountInfo -> AccountInfo -> Bool)
-> (AccountInfo -> AccountInfo -> Bool) -> Eq AccountInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AccountInfo -> AccountInfo -> Bool
== :: AccountInfo -> AccountInfo -> Bool
$c/= :: AccountInfo -> AccountInfo -> Bool
/= :: AccountInfo -> AccountInfo -> Bool
Eq, Int -> AccountInfo -> ShowS
[AccountInfo] -> ShowS
AccountInfo -> String
(Int -> AccountInfo -> ShowS)
-> (AccountInfo -> String)
-> ([AccountInfo] -> ShowS)
-> Show AccountInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AccountInfo -> ShowS
showsPrec :: Int -> AccountInfo -> ShowS
$cshow :: AccountInfo -> String
show :: AccountInfo -> String
$cshowList :: [AccountInfo] -> ShowS
showList :: [AccountInfo] -> ShowS
Show)
instance I.ShortShow AccountInfo where
shortShow :: AccountInfo -> String
shortShow AccountInfo
{ registration_month :: AccountInfo -> Maybe Int
registration_month = Maybe Int
registration_month_
, registration_year :: AccountInfo -> Maybe Int
registration_year = Maybe Int
registration_year_
, phone_number_country_code :: AccountInfo -> Maybe Text
phone_number_country_code = Maybe Text
phone_number_country_code_
, last_name_change_date :: AccountInfo -> Maybe Int
last_name_change_date = Maybe Int
last_name_change_date_
, last_photo_change_date :: AccountInfo -> Maybe Int
last_photo_change_date = Maybe Int
last_photo_change_date_
}
= String
"AccountInfo"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"registration_month" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
registration_month_
, String
"registration_year" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
registration_year_
, String
"phone_number_country_code" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
phone_number_country_code_
, String
"last_name_change_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
last_name_change_date_
, String
"last_photo_change_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
last_photo_change_date_
]
instance AT.FromJSON AccountInfo where
parseJSON :: Value -> Parser AccountInfo
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
"accountInfo" -> Value -> Parser AccountInfo
parseAccountInfo Value
v
String
_ -> Parser AccountInfo
forall a. Monoid a => a
mempty
where
parseAccountInfo :: A.Value -> AT.Parser AccountInfo
parseAccountInfo :: Value -> Parser AccountInfo
parseAccountInfo = String
-> (Object -> Parser AccountInfo) -> Value -> Parser AccountInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"AccountInfo" ((Object -> Parser AccountInfo) -> Value -> Parser AccountInfo)
-> (Object -> Parser AccountInfo) -> Value -> Parser AccountInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
registration_month_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"registration_month"
Maybe Int
registration_year_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"registration_year"
Maybe Text
phone_number_country_code_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"phone_number_country_code"
Maybe Int
last_name_change_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"last_name_change_date"
Maybe Int
last_photo_change_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"last_photo_change_date"
AccountInfo -> Parser AccountInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AccountInfo -> Parser AccountInfo)
-> AccountInfo -> Parser AccountInfo
forall a b. (a -> b) -> a -> b
$ AccountInfo
{ registration_month :: Maybe Int
registration_month = Maybe Int
registration_month_
, registration_year :: Maybe Int
registration_year = Maybe Int
registration_year_
, phone_number_country_code :: Maybe Text
phone_number_country_code = Maybe Text
phone_number_country_code_
, last_name_change_date :: Maybe Int
last_name_change_date = Maybe Int
last_name_change_date_
, last_photo_change_date :: Maybe Int
last_photo_change_date = Maybe Int
last_photo_change_date_
}
parseJSON Value
_ = Parser AccountInfo
forall a. Monoid a => a
mempty