module TD.Data.TonConnectSessionEventId
  (TonConnectSessionEventId(..)) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I

data TonConnectSessionEventId
  = TonConnectSessionEventId -- ^ Represents identifier of an event in a TON Connect session
    { TonConnectSessionEventId -> Maybe Int
event_id :: Maybe Int -- ^ The event identifier
    }
  deriving (TonConnectSessionEventId -> TonConnectSessionEventId -> Bool
(TonConnectSessionEventId -> TonConnectSessionEventId -> Bool)
-> (TonConnectSessionEventId -> TonConnectSessionEventId -> Bool)
-> Eq TonConnectSessionEventId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TonConnectSessionEventId -> TonConnectSessionEventId -> Bool
== :: TonConnectSessionEventId -> TonConnectSessionEventId -> Bool
$c/= :: TonConnectSessionEventId -> TonConnectSessionEventId -> Bool
/= :: TonConnectSessionEventId -> TonConnectSessionEventId -> Bool
Eq, Int -> TonConnectSessionEventId -> ShowS
[TonConnectSessionEventId] -> ShowS
TonConnectSessionEventId -> String
(Int -> TonConnectSessionEventId -> ShowS)
-> (TonConnectSessionEventId -> String)
-> ([TonConnectSessionEventId] -> ShowS)
-> Show TonConnectSessionEventId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TonConnectSessionEventId -> ShowS
showsPrec :: Int -> TonConnectSessionEventId -> ShowS
$cshow :: TonConnectSessionEventId -> String
show :: TonConnectSessionEventId -> String
$cshowList :: [TonConnectSessionEventId] -> ShowS
showList :: [TonConnectSessionEventId] -> ShowS
Show)

instance I.ShortShow TonConnectSessionEventId where
  shortShow :: TonConnectSessionEventId -> String
shortShow TonConnectSessionEventId
    { event_id :: TonConnectSessionEventId -> Maybe Int
event_id = Maybe Int
event_id_
    }
      = String
"TonConnectSessionEventId"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"event_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
event_id_
        ]

instance AT.FromJSON TonConnectSessionEventId where
  parseJSON :: Value -> Parser TonConnectSessionEventId
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
"tonConnectSessionEventId" -> Value -> Parser TonConnectSessionEventId
parseTonConnectSessionEventId Value
v
      String
_                          -> Parser TonConnectSessionEventId
forall a. Monoid a => a
mempty
    
    where
      parseTonConnectSessionEventId :: A.Value -> AT.Parser TonConnectSessionEventId
      parseTonConnectSessionEventId :: Value -> Parser TonConnectSessionEventId
parseTonConnectSessionEventId = String
-> (Object -> Parser TonConnectSessionEventId)
-> Value
-> Parser TonConnectSessionEventId
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"TonConnectSessionEventId" ((Object -> Parser TonConnectSessionEventId)
 -> Value -> Parser TonConnectSessionEventId)
-> (Object -> Parser TonConnectSessionEventId)
-> Value
-> Parser TonConnectSessionEventId
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
event_id_ <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"event_id"
        TonConnectSessionEventId -> Parser TonConnectSessionEventId
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TonConnectSessionEventId -> Parser TonConnectSessionEventId)
-> TonConnectSessionEventId -> Parser TonConnectSessionEventId
forall a b. (a -> b) -> a -> b
$ TonConnectSessionEventId
          { event_id :: Maybe Int
event_id = Maybe Int
event_id_
          }
  parseJSON Value
_ = Parser TonConnectSessionEventId
forall a. Monoid a => a
mempty