module TD.Data.CollectibleItemType
(CollectibleItemType(..)) 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 CollectibleItemType
= CollectibleItemTypeUsername
{ CollectibleItemType -> Maybe Text
username :: Maybe T.Text
}
| CollectibleItemTypePhoneNumber
{ CollectibleItemType -> Maybe Text
phone_number :: Maybe T.Text
}
deriving (CollectibleItemType -> CollectibleItemType -> Bool
(CollectibleItemType -> CollectibleItemType -> Bool)
-> (CollectibleItemType -> CollectibleItemType -> Bool)
-> Eq CollectibleItemType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CollectibleItemType -> CollectibleItemType -> Bool
== :: CollectibleItemType -> CollectibleItemType -> Bool
$c/= :: CollectibleItemType -> CollectibleItemType -> Bool
/= :: CollectibleItemType -> CollectibleItemType -> Bool
Eq, Int -> CollectibleItemType -> ShowS
[CollectibleItemType] -> ShowS
CollectibleItemType -> String
(Int -> CollectibleItemType -> ShowS)
-> (CollectibleItemType -> String)
-> ([CollectibleItemType] -> ShowS)
-> Show CollectibleItemType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CollectibleItemType -> ShowS
showsPrec :: Int -> CollectibleItemType -> ShowS
$cshow :: CollectibleItemType -> String
show :: CollectibleItemType -> String
$cshowList :: [CollectibleItemType] -> ShowS
showList :: [CollectibleItemType] -> ShowS
Show)
instance I.ShortShow CollectibleItemType where
shortShow :: CollectibleItemType -> String
shortShow CollectibleItemTypeUsername
{ username :: CollectibleItemType -> Maybe Text
username = Maybe Text
username_
}
= String
"CollectibleItemTypeUsername"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"username" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
username_
]
shortShow CollectibleItemTypePhoneNumber
{ phone_number :: CollectibleItemType -> Maybe Text
phone_number = Maybe Text
phone_number_
}
= String
"CollectibleItemTypePhoneNumber"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"phone_number" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
phone_number_
]
instance AT.FromJSON CollectibleItemType where
parseJSON :: Value -> Parser CollectibleItemType
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
"collectibleItemTypeUsername" -> Value -> Parser CollectibleItemType
parseCollectibleItemTypeUsername Value
v
String
"collectibleItemTypePhoneNumber" -> Value -> Parser CollectibleItemType
parseCollectibleItemTypePhoneNumber Value
v
String
_ -> Parser CollectibleItemType
forall a. Monoid a => a
mempty
where
parseCollectibleItemTypeUsername :: A.Value -> AT.Parser CollectibleItemType
parseCollectibleItemTypeUsername :: Value -> Parser CollectibleItemType
parseCollectibleItemTypeUsername = String
-> (Object -> Parser CollectibleItemType)
-> Value
-> Parser CollectibleItemType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"CollectibleItemTypeUsername" ((Object -> Parser CollectibleItemType)
-> Value -> Parser CollectibleItemType)
-> (Object -> Parser CollectibleItemType)
-> Value
-> Parser CollectibleItemType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
username_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"username"
CollectibleItemType -> Parser CollectibleItemType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CollectibleItemType -> Parser CollectibleItemType)
-> CollectibleItemType -> Parser CollectibleItemType
forall a b. (a -> b) -> a -> b
$ CollectibleItemTypeUsername
{ username :: Maybe Text
username = Maybe Text
username_
}
parseCollectibleItemTypePhoneNumber :: A.Value -> AT.Parser CollectibleItemType
parseCollectibleItemTypePhoneNumber :: Value -> Parser CollectibleItemType
parseCollectibleItemTypePhoneNumber = String
-> (Object -> Parser CollectibleItemType)
-> Value
-> Parser CollectibleItemType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"CollectibleItemTypePhoneNumber" ((Object -> Parser CollectibleItemType)
-> Value -> Parser CollectibleItemType)
-> (Object -> Parser CollectibleItemType)
-> Value
-> Parser CollectibleItemType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
phone_number_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"phone_number"
CollectibleItemType -> Parser CollectibleItemType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CollectibleItemType -> Parser CollectibleItemType)
-> CollectibleItemType -> Parser CollectibleItemType
forall a b. (a -> b) -> a -> b
$ CollectibleItemTypePhoneNumber
{ phone_number :: Maybe Text
phone_number = Maybe Text
phone_number_
}
parseJSON Value
_ = Parser CollectibleItemType
forall a. Monoid a => a
mempty
instance AT.ToJSON CollectibleItemType where
toJSON :: CollectibleItemType -> Value
toJSON CollectibleItemTypeUsername
{ username :: CollectibleItemType -> Maybe Text
username = Maybe Text
username_
}
= [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
"collectibleItemTypeUsername"
, Key
"username" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
username_
]
toJSON CollectibleItemTypePhoneNumber
{ phone_number :: CollectibleItemType -> Maybe Text
phone_number = Maybe Text
phone_number_
}
= [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
"collectibleItemTypePhoneNumber"
, Key
"phone_number" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
phone_number_
]