module TD.Data.PhoneNumberInfo
(PhoneNumberInfo(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.CountryInfo as CountryInfo
import qualified Data.Text as T
data PhoneNumberInfo
= PhoneNumberInfo
{ PhoneNumberInfo -> Maybe CountryInfo
country :: Maybe CountryInfo.CountryInfo
, PhoneNumberInfo -> Maybe Text
country_calling_code :: Maybe T.Text
, PhoneNumberInfo -> Maybe Text
formatted_phone_number :: Maybe T.Text
, PhoneNumberInfo -> Maybe Bool
is_anonymous :: Maybe Bool
}
deriving (PhoneNumberInfo -> PhoneNumberInfo -> Bool
(PhoneNumberInfo -> PhoneNumberInfo -> Bool)
-> (PhoneNumberInfo -> PhoneNumberInfo -> Bool)
-> Eq PhoneNumberInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PhoneNumberInfo -> PhoneNumberInfo -> Bool
== :: PhoneNumberInfo -> PhoneNumberInfo -> Bool
$c/= :: PhoneNumberInfo -> PhoneNumberInfo -> Bool
/= :: PhoneNumberInfo -> PhoneNumberInfo -> Bool
Eq, Int -> PhoneNumberInfo -> ShowS
[PhoneNumberInfo] -> ShowS
PhoneNumberInfo -> String
(Int -> PhoneNumberInfo -> ShowS)
-> (PhoneNumberInfo -> String)
-> ([PhoneNumberInfo] -> ShowS)
-> Show PhoneNumberInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PhoneNumberInfo -> ShowS
showsPrec :: Int -> PhoneNumberInfo -> ShowS
$cshow :: PhoneNumberInfo -> String
show :: PhoneNumberInfo -> String
$cshowList :: [PhoneNumberInfo] -> ShowS
showList :: [PhoneNumberInfo] -> ShowS
Show)
instance I.ShortShow PhoneNumberInfo where
shortShow :: PhoneNumberInfo -> String
shortShow PhoneNumberInfo
{ country :: PhoneNumberInfo -> Maybe CountryInfo
country = Maybe CountryInfo
country_
, country_calling_code :: PhoneNumberInfo -> Maybe Text
country_calling_code = Maybe Text
country_calling_code_
, formatted_phone_number :: PhoneNumberInfo -> Maybe Text
formatted_phone_number = Maybe Text
formatted_phone_number_
, is_anonymous :: PhoneNumberInfo -> Maybe Bool
is_anonymous = Maybe Bool
is_anonymous_
}
= String
"PhoneNumberInfo"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"country" String -> Maybe CountryInfo -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe CountryInfo
country_
, String
"country_calling_code" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
country_calling_code_
, String
"formatted_phone_number" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
formatted_phone_number_
, String
"is_anonymous" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_anonymous_
]
instance AT.FromJSON PhoneNumberInfo where
parseJSON :: Value -> Parser PhoneNumberInfo
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
"phoneNumberInfo" -> Value -> Parser PhoneNumberInfo
parsePhoneNumberInfo Value
v
String
_ -> Parser PhoneNumberInfo
forall a. Monoid a => a
mempty
where
parsePhoneNumberInfo :: A.Value -> AT.Parser PhoneNumberInfo
parsePhoneNumberInfo :: Value -> Parser PhoneNumberInfo
parsePhoneNumberInfo = String
-> (Object -> Parser PhoneNumberInfo)
-> Value
-> Parser PhoneNumberInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PhoneNumberInfo" ((Object -> Parser PhoneNumberInfo)
-> Value -> Parser PhoneNumberInfo)
-> (Object -> Parser PhoneNumberInfo)
-> Value
-> Parser PhoneNumberInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe CountryInfo
country_ <- Object
o Object -> Key -> Parser (Maybe CountryInfo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"country"
Maybe Text
country_calling_code_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"country_calling_code"
Maybe Text
formatted_phone_number_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"formatted_phone_number"
Maybe Bool
is_anonymous_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_anonymous"
PhoneNumberInfo -> Parser PhoneNumberInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PhoneNumberInfo -> Parser PhoneNumberInfo)
-> PhoneNumberInfo -> Parser PhoneNumberInfo
forall a b. (a -> b) -> a -> b
$ PhoneNumberInfo
{ country :: Maybe CountryInfo
country = Maybe CountryInfo
country_
, country_calling_code :: Maybe Text
country_calling_code = Maybe Text
country_calling_code_
, formatted_phone_number :: Maybe Text
formatted_phone_number = Maybe Text
formatted_phone_number_
, is_anonymous :: Maybe Bool
is_anonymous = Maybe Bool
is_anonymous_
}
parseJSON Value
_ = Parser PhoneNumberInfo
forall a. Monoid a => a
mempty