module TD.Data.InputTonWalletCardSticker
  ( InputTonWalletCardSticker(..)    
  , defaultInputTonWalletCardSticker 
  ) 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.AreaPosition as AreaPosition
import qualified Data.Text as T

data InputTonWalletCardSticker
  = InputTonWalletCardSticker -- ^ Describes a sticker to be placed on the TON wallet card of the current user
    { InputTonWalletCardSticker -> Maybe AreaPosition
position    :: Maybe AreaPosition.AreaPosition -- ^ Position of the sticker on the card
    , InputTonWalletCardSticker -> Maybe Text
nft_address :: Maybe T.Text                    -- ^ Address of an NFT owned by the wallet, which is an upgraded gift; use getTonWalletNfts to get the list of owned NFTs
    }
  deriving (InputTonWalletCardSticker -> InputTonWalletCardSticker -> Bool
(InputTonWalletCardSticker -> InputTonWalletCardSticker -> Bool)
-> (InputTonWalletCardSticker -> InputTonWalletCardSticker -> Bool)
-> Eq InputTonWalletCardSticker
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputTonWalletCardSticker -> InputTonWalletCardSticker -> Bool
== :: InputTonWalletCardSticker -> InputTonWalletCardSticker -> Bool
$c/= :: InputTonWalletCardSticker -> InputTonWalletCardSticker -> Bool
/= :: InputTonWalletCardSticker -> InputTonWalletCardSticker -> Bool
Eq, Int -> InputTonWalletCardSticker -> ShowS
[InputTonWalletCardSticker] -> ShowS
InputTonWalletCardSticker -> String
(Int -> InputTonWalletCardSticker -> ShowS)
-> (InputTonWalletCardSticker -> String)
-> ([InputTonWalletCardSticker] -> ShowS)
-> Show InputTonWalletCardSticker
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputTonWalletCardSticker -> ShowS
showsPrec :: Int -> InputTonWalletCardSticker -> ShowS
$cshow :: InputTonWalletCardSticker -> String
show :: InputTonWalletCardSticker -> String
$cshowList :: [InputTonWalletCardSticker] -> ShowS
showList :: [InputTonWalletCardSticker] -> ShowS
Show)

instance I.ShortShow InputTonWalletCardSticker where
  shortShow :: InputTonWalletCardSticker -> String
shortShow InputTonWalletCardSticker
    { position :: InputTonWalletCardSticker -> Maybe AreaPosition
position    = Maybe AreaPosition
position_
    , nft_address :: InputTonWalletCardSticker -> Maybe Text
nft_address = Maybe Text
nft_address_
    }
      = String
"InputTonWalletCardSticker"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"position"    String -> Maybe AreaPosition -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe AreaPosition
position_
        , String
"nft_address" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
nft_address_
        ]

instance AT.FromJSON InputTonWalletCardSticker where
  parseJSON :: Value -> Parser InputTonWalletCardSticker
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
"inputTonWalletCardSticker" -> Value -> Parser InputTonWalletCardSticker
parseInputTonWalletCardSticker Value
v
      String
_                           -> Parser InputTonWalletCardSticker
forall a. Monoid a => a
mempty
    
    where
      parseInputTonWalletCardSticker :: A.Value -> AT.Parser InputTonWalletCardSticker
      parseInputTonWalletCardSticker :: Value -> Parser InputTonWalletCardSticker
parseInputTonWalletCardSticker = String
-> (Object -> Parser InputTonWalletCardSticker)
-> Value
-> Parser InputTonWalletCardSticker
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputTonWalletCardSticker" ((Object -> Parser InputTonWalletCardSticker)
 -> Value -> Parser InputTonWalletCardSticker)
-> (Object -> Parser InputTonWalletCardSticker)
-> Value
-> Parser InputTonWalletCardSticker
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe AreaPosition
position_    <- Object
o Object -> Key -> Parser (Maybe AreaPosition)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"position"
        Maybe Text
nft_address_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"nft_address"
        InputTonWalletCardSticker -> Parser InputTonWalletCardSticker
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputTonWalletCardSticker -> Parser InputTonWalletCardSticker)
-> InputTonWalletCardSticker -> Parser InputTonWalletCardSticker
forall a b. (a -> b) -> a -> b
$ InputTonWalletCardSticker
          { position :: Maybe AreaPosition
position    = Maybe AreaPosition
position_
          , nft_address :: Maybe Text
nft_address = Maybe Text
nft_address_
          }
  parseJSON Value
_ = Parser InputTonWalletCardSticker
forall a. Monoid a => a
mempty

instance AT.ToJSON InputTonWalletCardSticker where
  toJSON :: InputTonWalletCardSticker -> Value
toJSON InputTonWalletCardSticker
    { position :: InputTonWalletCardSticker -> Maybe AreaPosition
position    = Maybe AreaPosition
position_
    , nft_address :: InputTonWalletCardSticker -> Maybe Text
nft_address = Maybe Text
nft_address_
    }
      = [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
"inputTonWalletCardSticker"
        , Key
"position"    Key -> Maybe AreaPosition -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe AreaPosition
position_
        , Key
"nft_address" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
nft_address_
        ]

defaultInputTonWalletCardSticker :: InputTonWalletCardSticker
defaultInputTonWalletCardSticker :: InputTonWalletCardSticker
defaultInputTonWalletCardSticker =
  InputTonWalletCardSticker
    { position :: Maybe AreaPosition
position    = Maybe AreaPosition
forall a. Maybe a
Nothing
    , nft_address :: Maybe Text
nft_address = Maybe Text
forall a. Maybe a
Nothing
    }