module TD.Data.TonNft
  (TonNft(..)) 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.PhotoSize as PhotoSize
import qualified TD.Data.Document as Document
import qualified TD.Data.Sticker as Sticker
import qualified TD.Data.TonNftAttribute as TonNftAttribute
import qualified TD.Data.JsonValue as JsonValue

data TonNft
  = TonNft -- ^ Represents an NFT in the TON blockchain
    { TonNft -> Maybe Text
collection_address :: Maybe T.Text                            -- ^ Address of the collection to which the NFT belongs; may be empty if unknown
    , TonNft -> Maybe Text
address            :: Maybe T.Text                            -- ^ Address of the NFT
    , TonNft -> Maybe Text
owner_address      :: Maybe T.Text                            -- ^ Address of the owner of the NFT
    , TonNft -> Maybe Text
index              :: Maybe T.Text                            -- ^ Index of the NFT among all NFTs from the collection as a decimal number
    , TonNft -> Maybe Text
name               :: Maybe T.Text                            -- ^ Name of the NFT
    , TonNft -> Maybe Text
description        :: Maybe T.Text                            -- ^ Description of the NFT
    , TonNft -> Maybe PhotoSize
image              :: Maybe PhotoSize.PhotoSize               -- ^ Image of the NFT; may be null if none
    , TonNft -> Maybe PhotoSize
thumbnail          :: Maybe PhotoSize.PhotoSize               -- ^ Thumbnail of the NFT; may be null if none
    , TonNft -> Maybe Document
content            :: Maybe Document.Document                 -- ^ Content of the NFT; may be null if none
    , TonNft -> Maybe Sticker
sticker            :: Maybe Sticker.Sticker                   -- ^ Sticker of the NFT; may be null if none
    , TonNft -> Maybe [TonNftAttribute]
attributes         :: Maybe [TonNftAttribute.TonNftAttribute] -- ^ Attributes of the NFT
    , TonNft -> Maybe JsonValue
extra              :: Maybe JsonValue.JsonValue               -- ^ Additional data about the NFT; may be null if none
    }
  deriving (TonNft -> TonNft -> Bool
(TonNft -> TonNft -> Bool)
-> (TonNft -> TonNft -> Bool) -> Eq TonNft
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TonNft -> TonNft -> Bool
== :: TonNft -> TonNft -> Bool
$c/= :: TonNft -> TonNft -> Bool
/= :: TonNft -> TonNft -> Bool
Eq, Int -> TonNft -> ShowS
[TonNft] -> ShowS
TonNft -> String
(Int -> TonNft -> ShowS)
-> (TonNft -> String) -> ([TonNft] -> ShowS) -> Show TonNft
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TonNft -> ShowS
showsPrec :: Int -> TonNft -> ShowS
$cshow :: TonNft -> String
show :: TonNft -> String
$cshowList :: [TonNft] -> ShowS
showList :: [TonNft] -> ShowS
Show)

instance I.ShortShow TonNft where
  shortShow :: TonNft -> String
shortShow TonNft
    { collection_address :: TonNft -> Maybe Text
collection_address = Maybe Text
collection_address_
    , address :: TonNft -> Maybe Text
address            = Maybe Text
address_
    , owner_address :: TonNft -> Maybe Text
owner_address      = Maybe Text
owner_address_
    , index :: TonNft -> Maybe Text
index              = Maybe Text
index_
    , name :: TonNft -> Maybe Text
name               = Maybe Text
name_
    , description :: TonNft -> Maybe Text
description        = Maybe Text
description_
    , image :: TonNft -> Maybe PhotoSize
image              = Maybe PhotoSize
image_
    , thumbnail :: TonNft -> Maybe PhotoSize
thumbnail          = Maybe PhotoSize
thumbnail_
    , content :: TonNft -> Maybe Document
content            = Maybe Document
content_
    , sticker :: TonNft -> Maybe Sticker
sticker            = Maybe Sticker
sticker_
    , attributes :: TonNft -> Maybe [TonNftAttribute]
attributes         = Maybe [TonNftAttribute]
attributes_
    , extra :: TonNft -> Maybe JsonValue
extra              = Maybe JsonValue
extra_
    }
      = String
"TonNft"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"collection_address" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
collection_address_
        , String
"address"            String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
address_
        , String
"owner_address"      String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
owner_address_
        , String
"index"              String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
index_
        , String
"name"               String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
name_
        , String
"description"        String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
description_
        , String
"image"              String -> Maybe PhotoSize -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe PhotoSize
image_
        , String
"thumbnail"          String -> Maybe PhotoSize -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe PhotoSize
thumbnail_
        , String
"content"            String -> Maybe Document -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Document
content_
        , String
"sticker"            String -> Maybe Sticker -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Sticker
sticker_
        , String
"attributes"         String -> Maybe [TonNftAttribute] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [TonNftAttribute]
attributes_
        , String
"extra"              String -> Maybe JsonValue -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe JsonValue
extra_
        ]

instance AT.FromJSON TonNft where
  parseJSON :: Value -> Parser TonNft
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
"tonNft" -> Value -> Parser TonNft
parseTonNft Value
v
      String
_        -> Parser TonNft
forall a. Monoid a => a
mempty
    
    where
      parseTonNft :: A.Value -> AT.Parser TonNft
      parseTonNft :: Value -> Parser TonNft
parseTonNft = String -> (Object -> Parser TonNft) -> Value -> Parser TonNft
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"TonNft" ((Object -> Parser TonNft) -> Value -> Parser TonNft)
-> (Object -> Parser TonNft) -> Value -> Parser TonNft
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
collection_address_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"collection_address"
        Maybe Text
address_            <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"address"
        Maybe Text
owner_address_      <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"owner_address"
        Maybe Text
index_              <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"index"
        Maybe Text
name_               <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"name"
        Maybe Text
description_        <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"description"
        Maybe PhotoSize
image_              <- Object
o Object -> Key -> Parser (Maybe PhotoSize)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"image"
        Maybe PhotoSize
thumbnail_          <- Object
o Object -> Key -> Parser (Maybe PhotoSize)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"thumbnail"
        Maybe Document
content_            <- Object
o Object -> Key -> Parser (Maybe Document)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"content"
        Maybe Sticker
sticker_            <- Object
o Object -> Key -> Parser (Maybe Sticker)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"sticker"
        Maybe [TonNftAttribute]
attributes_         <- Object
o Object -> Key -> Parser (Maybe [TonNftAttribute])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"attributes"
        Maybe JsonValue
extra_              <- Object
o Object -> Key -> Parser (Maybe JsonValue)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"extra"
        TonNft -> Parser TonNft
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TonNft -> Parser TonNft) -> TonNft -> Parser TonNft
forall a b. (a -> b) -> a -> b
$ TonNft
          { collection_address :: Maybe Text
collection_address = Maybe Text
collection_address_
          , address :: Maybe Text
address            = Maybe Text
address_
          , owner_address :: Maybe Text
owner_address      = Maybe Text
owner_address_
          , index :: Maybe Text
index              = Maybe Text
index_
          , name :: Maybe Text
name               = Maybe Text
name_
          , description :: Maybe Text
description        = Maybe Text
description_
          , image :: Maybe PhotoSize
image              = Maybe PhotoSize
image_
          , thumbnail :: Maybe PhotoSize
thumbnail          = Maybe PhotoSize
thumbnail_
          , content :: Maybe Document
content            = Maybe Document
content_
          , sticker :: Maybe Sticker
sticker            = Maybe Sticker
sticker_
          , attributes :: Maybe [TonNftAttribute]
attributes         = Maybe [TonNftAttribute]
attributes_
          , extra :: Maybe JsonValue
extra              = Maybe JsonValue
extra_
          }
  parseJSON Value
_ = Parser TonNft
forall a. Monoid a => a
mempty