module TD.Data.TonNftAttribute
(TonNftAttribute(..)) 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 TonNftAttribute
= TonNftAttribute
{ TonNftAttribute -> Maybe Text
trait_type :: Maybe T.Text
, TonNftAttribute -> Maybe Text
value :: Maybe T.Text
}
deriving (TonNftAttribute -> TonNftAttribute -> Bool
(TonNftAttribute -> TonNftAttribute -> Bool)
-> (TonNftAttribute -> TonNftAttribute -> Bool)
-> Eq TonNftAttribute
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TonNftAttribute -> TonNftAttribute -> Bool
== :: TonNftAttribute -> TonNftAttribute -> Bool
$c/= :: TonNftAttribute -> TonNftAttribute -> Bool
/= :: TonNftAttribute -> TonNftAttribute -> Bool
Eq, Int -> TonNftAttribute -> ShowS
[TonNftAttribute] -> ShowS
TonNftAttribute -> String
(Int -> TonNftAttribute -> ShowS)
-> (TonNftAttribute -> String)
-> ([TonNftAttribute] -> ShowS)
-> Show TonNftAttribute
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TonNftAttribute -> ShowS
showsPrec :: Int -> TonNftAttribute -> ShowS
$cshow :: TonNftAttribute -> String
show :: TonNftAttribute -> String
$cshowList :: [TonNftAttribute] -> ShowS
showList :: [TonNftAttribute] -> ShowS
Show)
instance I.ShortShow TonNftAttribute where
shortShow :: TonNftAttribute -> String
shortShow TonNftAttribute
{ trait_type :: TonNftAttribute -> Maybe Text
trait_type = Maybe Text
trait_type_
, value :: TonNftAttribute -> Maybe Text
value = Maybe Text
value_
}
= String
"TonNftAttribute"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"trait_type" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
trait_type_
, String
"value" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
value_
]
instance AT.FromJSON TonNftAttribute where
parseJSON :: Value -> Parser TonNftAttribute
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
"tonNftAttribute" -> Value -> Parser TonNftAttribute
parseTonNftAttribute Value
v
String
_ -> Parser TonNftAttribute
forall a. Monoid a => a
mempty
where
parseTonNftAttribute :: A.Value -> AT.Parser TonNftAttribute
parseTonNftAttribute :: Value -> Parser TonNftAttribute
parseTonNftAttribute = String
-> (Object -> Parser TonNftAttribute)
-> Value
-> Parser TonNftAttribute
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"TonNftAttribute" ((Object -> Parser TonNftAttribute)
-> Value -> Parser TonNftAttribute)
-> (Object -> Parser TonNftAttribute)
-> Value
-> Parser TonNftAttribute
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
trait_type_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"trait_type"
Maybe Text
value_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"value"
TonNftAttribute -> Parser TonNftAttribute
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TonNftAttribute -> Parser TonNftAttribute)
-> TonNftAttribute -> Parser TonNftAttribute
forall a b. (a -> b) -> a -> b
$ TonNftAttribute
{ trait_type :: Maybe Text
trait_type = Maybe Text
trait_type_
, value :: Maybe Text
value = Maybe Text
value_
}
parseJSON Value
_ = Parser TonNftAttribute
forall a. Monoid a => a
mempty