{-# LANGUAGE TemplateHaskell #-}

-- | Discord Interactions
module Calamity.Types.Model.Interaction (
  Interaction (..),
  InteractionToken (..),
  InteractionData (..),
  ResolvedInteractionData (..),
  InteractionType (..),
  Application,
  ApplicationCommand,
) where

import Calamity.Types.Model.Channel (Attachment, Channel, Partial)
import Calamity.Types.Model.Channel.Component
import Calamity.Types.Model.Channel.Message (Message)
import Calamity.Types.Model.Guild (Guild, Role)
import Calamity.Types.Model.Guild.Member (Member)
import Calamity.Types.Model.User (User)
import Calamity.Types.Snowflake
import Data.Aeson ((.!=), (.:), (.:?))
import Data.Aeson qualified as Aeson
import Data.HashMap.Strict qualified as H
import Data.Scientific (toBoundedInteger)
import Data.Text qualified as T
import Optics.TH
import TextShow qualified
import TextShow.TH

-- | Empty type to flag application IDs
data Application

-- | Empty type to flag application command IDs
data ApplicationCommand

newtype InteractionToken = InteractionToken
  { InteractionToken -> Text
fromInteractionToken :: T.Text
  }
  deriving stock (Int -> InteractionToken -> ShowS
[InteractionToken] -> ShowS
InteractionToken -> String
(Int -> InteractionToken -> ShowS)
-> (InteractionToken -> String)
-> ([InteractionToken] -> ShowS)
-> Show InteractionToken
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InteractionToken -> ShowS
showsPrec :: Int -> InteractionToken -> ShowS
$cshow :: InteractionToken -> String
show :: InteractionToken -> String
$cshowList :: [InteractionToken] -> ShowS
showList :: [InteractionToken] -> ShowS
Show)
  deriving (Value -> Parser [InteractionToken]
Value -> Parser InteractionToken
(Value -> Parser InteractionToken)
-> (Value -> Parser [InteractionToken])
-> FromJSON InteractionToken
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
$cparseJSON :: Value -> Parser InteractionToken
parseJSON :: Value -> Parser InteractionToken
$cparseJSONList :: Value -> Parser [InteractionToken]
parseJSONList :: Value -> Parser [InteractionToken]
Aeson.FromJSON, [InteractionToken] -> Value
[InteractionToken] -> Encoding
InteractionToken -> Value
InteractionToken -> Encoding
(InteractionToken -> Value)
-> (InteractionToken -> Encoding)
-> ([InteractionToken] -> Value)
-> ([InteractionToken] -> Encoding)
-> ToJSON InteractionToken
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: InteractionToken -> Value
toJSON :: InteractionToken -> Value
$ctoEncoding :: InteractionToken -> Encoding
toEncoding :: InteractionToken -> Encoding
$ctoJSONList :: [InteractionToken] -> Value
toJSONList :: [InteractionToken] -> Value
$ctoEncodingList :: [InteractionToken] -> Encoding
toEncodingList :: [InteractionToken] -> Encoding
Aeson.ToJSON) via T.Text

data Interaction = Interaction
  { Interaction -> Snowflake Interaction
id :: Snowflake Interaction
  , Interaction -> Snowflake Application
applicationID :: Snowflake Application
  , Interaction -> InteractionType
type_ :: InteractionType
  , Interaction -> Maybe InteractionData
data_ :: Maybe InteractionData
  , Interaction -> Maybe (Snowflake Guild)
guildID :: Maybe (Snowflake Guild)
  , Interaction -> Maybe (Snowflake Channel)
channelID :: Maybe (Snowflake Channel)
  , Interaction -> Maybe Member
member :: Maybe Member
  , Interaction -> Maybe User
user :: Maybe User
  , Interaction -> InteractionToken
token :: InteractionToken
  , Interaction -> Int
version :: Int
  , Interaction -> Maybe Message
message :: Maybe Message
  , Interaction -> Maybe Text
locale :: Maybe T.Text
  , Interaction -> Maybe Text
guildLocale :: Maybe T.Text
  }
  deriving (Int -> Interaction -> ShowS
[Interaction] -> ShowS
Interaction -> String
(Int -> Interaction -> ShowS)
-> (Interaction -> String)
-> ([Interaction] -> ShowS)
-> Show Interaction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Interaction -> ShowS
showsPrec :: Int -> Interaction -> ShowS
$cshow :: Interaction -> String
show :: Interaction -> String
$cshowList :: [Interaction] -> ShowS
showList :: [Interaction] -> ShowS
Show)
  deriving (HasID Interaction) via HasIDField "id" Interaction
  deriving (HasID Application) via HasIDField "applicationID" Interaction

instance Aeson.FromJSON Interaction where
  parseJSON :: Value -> Parser Interaction
parseJSON = String
-> (Object -> Parser Interaction) -> Value -> Parser Interaction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"Interaction" ((Object -> Parser Interaction) -> Value -> Parser Interaction)
-> (Object -> Parser Interaction) -> Value -> Parser Interaction
forall a b. (a -> b) -> a -> b
$ \Object
v ->
    Snowflake Interaction
-> Snowflake Application
-> InteractionType
-> Maybe InteractionData
-> Maybe (Snowflake Guild)
-> Maybe (Snowflake Channel)
-> Maybe Member
-> Maybe User
-> InteractionToken
-> Int
-> Maybe Message
-> Maybe Text
-> Maybe Text
-> Interaction
Interaction
      (Snowflake Interaction
 -> Snowflake Application
 -> InteractionType
 -> Maybe InteractionData
 -> Maybe (Snowflake Guild)
 -> Maybe (Snowflake Channel)
 -> Maybe Member
 -> Maybe User
 -> InteractionToken
 -> Int
 -> Maybe Message
 -> Maybe Text
 -> Maybe Text
 -> Interaction)
-> Parser (Snowflake Interaction)
-> Parser
     (Snowflake Application
      -> InteractionType
      -> Maybe InteractionData
      -> Maybe (Snowflake Guild)
      -> Maybe (Snowflake Channel)
      -> Maybe Member
      -> Maybe User
      -> InteractionToken
      -> Int
      -> Maybe Message
      -> Maybe Text
      -> Maybe Text
      -> Interaction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Snowflake Interaction)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
      Parser
  (Snowflake Application
   -> InteractionType
   -> Maybe InteractionData
   -> Maybe (Snowflake Guild)
   -> Maybe (Snowflake Channel)
   -> Maybe Member
   -> Maybe User
   -> InteractionToken
   -> Int
   -> Maybe Message
   -> Maybe Text
   -> Maybe Text
   -> Interaction)
-> Parser (Snowflake Application)
-> Parser
     (InteractionType
      -> Maybe InteractionData
      -> Maybe (Snowflake Guild)
      -> Maybe (Snowflake Channel)
      -> Maybe Member
      -> Maybe User
      -> InteractionToken
      -> Int
      -> Maybe Message
      -> Maybe Text
      -> Maybe Text
      -> Interaction)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Snowflake Application)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"application_id"
      Parser
  (InteractionType
   -> Maybe InteractionData
   -> Maybe (Snowflake Guild)
   -> Maybe (Snowflake Channel)
   -> Maybe Member
   -> Maybe User
   -> InteractionToken
   -> Int
   -> Maybe Message
   -> Maybe Text
   -> Maybe Text
   -> Interaction)
-> Parser InteractionType
-> Parser
     (Maybe InteractionData
      -> Maybe (Snowflake Guild)
      -> Maybe (Snowflake Channel)
      -> Maybe Member
      -> Maybe User
      -> InteractionToken
      -> Int
      -> Maybe Message
      -> Maybe Text
      -> Maybe Text
      -> Interaction)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser InteractionType
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
      Parser
  (Maybe InteractionData
   -> Maybe (Snowflake Guild)
   -> Maybe (Snowflake Channel)
   -> Maybe Member
   -> Maybe User
   -> InteractionToken
   -> Int
   -> Maybe Message
   -> Maybe Text
   -> Maybe Text
   -> Interaction)
-> Parser (Maybe InteractionData)
-> Parser
     (Maybe (Snowflake Guild)
      -> Maybe (Snowflake Channel)
      -> Maybe Member
      -> Maybe User
      -> InteractionToken
      -> Int
      -> Maybe Message
      -> Maybe Text
      -> Maybe Text
      -> Interaction)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe InteractionData)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"data"
      Parser
  (Maybe (Snowflake Guild)
   -> Maybe (Snowflake Channel)
   -> Maybe Member
   -> Maybe User
   -> InteractionToken
   -> Int
   -> Maybe Message
   -> Maybe Text
   -> Maybe Text
   -> Interaction)
-> Parser (Maybe (Snowflake Guild))
-> Parser
     (Maybe (Snowflake Channel)
      -> Maybe Member
      -> Maybe User
      -> InteractionToken
      -> Int
      -> Maybe Message
      -> Maybe Text
      -> Maybe Text
      -> Interaction)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe (Snowflake Guild))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"guild_id"
      Parser
  (Maybe (Snowflake Channel)
   -> Maybe Member
   -> Maybe User
   -> InteractionToken
   -> Int
   -> Maybe Message
   -> Maybe Text
   -> Maybe Text
   -> Interaction)
-> Parser (Maybe (Snowflake Channel))
-> Parser
     (Maybe Member
      -> Maybe User
      -> InteractionToken
      -> Int
      -> Maybe Message
      -> Maybe Text
      -> Maybe Text
      -> Interaction)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe (Snowflake Channel))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"channel_id"
      Parser
  (Maybe Member
   -> Maybe User
   -> InteractionToken
   -> Int
   -> Maybe Message
   -> Maybe Text
   -> Maybe Text
   -> Interaction)
-> Parser (Maybe Member)
-> Parser
     (Maybe User
      -> InteractionToken
      -> Int
      -> Maybe Message
      -> Maybe Text
      -> Maybe Text
      -> Interaction)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Member)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"member"
      Parser
  (Maybe User
   -> InteractionToken
   -> Int
   -> Maybe Message
   -> Maybe Text
   -> Maybe Text
   -> Interaction)
-> Parser (Maybe User)
-> Parser
     (InteractionToken
      -> Int -> Maybe Message -> Maybe Text -> Maybe Text -> Interaction)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe User)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"user"
      Parser
  (InteractionToken
   -> Int -> Maybe Message -> Maybe Text -> Maybe Text -> Interaction)
-> Parser InteractionToken
-> Parser
     (Int -> Maybe Message -> Maybe Text -> Maybe Text -> Interaction)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser InteractionToken
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"token"
      Parser
  (Int -> Maybe Message -> Maybe Text -> Maybe Text -> Interaction)
-> Parser Int
-> Parser
     (Maybe Message -> Maybe Text -> Maybe Text -> Interaction)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"version"
      Parser (Maybe Message -> Maybe Text -> Maybe Text -> Interaction)
-> Parser (Maybe Message)
-> Parser (Maybe Text -> Maybe Text -> Interaction)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Message)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"message"
      Parser (Maybe Text -> Maybe Text -> Interaction)
-> Parser (Maybe Text) -> Parser (Maybe Text -> Interaction)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"locale"
      Parser (Maybe Text -> Interaction)
-> Parser (Maybe Text) -> Parser Interaction
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"guild_locale"

data InteractionData = InteractionData
  { InteractionData -> Maybe (Snowflake ApplicationCommand)
id :: Maybe (Snowflake ApplicationCommand)
  , InteractionData -> Maybe Text
name :: Maybe T.Text
  , InteractionData -> Maybe ResolvedInteractionData
resolved :: Maybe ResolvedInteractionData
  , -- , options :: [ApplicationCommandInteractionDataOptions]
    -- No commands yet
    InteractionData -> Maybe CustomID
customID :: Maybe CustomID
  , InteractionData -> Maybe ComponentType
componentType :: Maybe ComponentType
  , InteractionData -> Maybe [Text]
values :: Maybe [T.Text]
  , InteractionData -> Maybe (Snowflake ())
targetID :: Maybe (Snowflake ())
  , InteractionData -> Maybe [Value]
components :: Maybe [Aeson.Value]
  }
  deriving (Int -> InteractionData -> ShowS
[InteractionData] -> ShowS
InteractionData -> String
(Int -> InteractionData -> ShowS)
-> (InteractionData -> String)
-> ([InteractionData] -> ShowS)
-> Show InteractionData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InteractionData -> ShowS
showsPrec :: Int -> InteractionData -> ShowS
$cshow :: InteractionData -> String
show :: InteractionData -> String
$cshowList :: [InteractionData] -> ShowS
showList :: [InteractionData] -> ShowS
Show)
  deriving (Int -> InteractionData -> Text
Int -> InteractionData -> Builder
Int -> InteractionData -> Text
[InteractionData] -> Text
[InteractionData] -> Builder
[InteractionData] -> Text
InteractionData -> Text
InteractionData -> Builder
InteractionData -> Text
(Int -> InteractionData -> Builder)
-> (InteractionData -> Builder)
-> ([InteractionData] -> Builder)
-> (Int -> InteractionData -> Text)
-> (InteractionData -> Text)
-> ([InteractionData] -> Text)
-> (Int -> InteractionData -> Text)
-> (InteractionData -> Text)
-> ([InteractionData] -> Text)
-> TextShow InteractionData
forall a.
(Int -> a -> Builder)
-> (a -> Builder)
-> ([a] -> Builder)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> TextShow a
$cshowbPrec :: Int -> InteractionData -> Builder
showbPrec :: Int -> InteractionData -> Builder
$cshowb :: InteractionData -> Builder
showb :: InteractionData -> Builder
$cshowbList :: [InteractionData] -> Builder
showbList :: [InteractionData] -> Builder
$cshowtPrec :: Int -> InteractionData -> Text
showtPrec :: Int -> InteractionData -> Text
$cshowt :: InteractionData -> Text
showt :: InteractionData -> Text
$cshowtList :: [InteractionData] -> Text
showtList :: [InteractionData] -> Text
$cshowtlPrec :: Int -> InteractionData -> Text
showtlPrec :: Int -> InteractionData -> Text
$cshowtl :: InteractionData -> Text
showtl :: InteractionData -> Text
$cshowtlList :: [InteractionData] -> Text
showtlList :: [InteractionData] -> Text
TextShow.TextShow) via TextShow.FromStringShow InteractionData

instance Aeson.FromJSON InteractionData where
  parseJSON :: Value -> Parser InteractionData
parseJSON = String
-> (Object -> Parser InteractionData)
-> Value
-> Parser InteractionData
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"InteractionData" ((Object -> Parser InteractionData)
 -> Value -> Parser InteractionData)
-> (Object -> Parser InteractionData)
-> Value
-> Parser InteractionData
forall a b. (a -> b) -> a -> b
$ \Object
v ->
    Maybe (Snowflake ApplicationCommand)
-> Maybe Text
-> Maybe ResolvedInteractionData
-> Maybe CustomID
-> Maybe ComponentType
-> Maybe [Text]
-> Maybe (Snowflake ())
-> Maybe [Value]
-> InteractionData
InteractionData
      (Maybe (Snowflake ApplicationCommand)
 -> Maybe Text
 -> Maybe ResolvedInteractionData
 -> Maybe CustomID
 -> Maybe ComponentType
 -> Maybe [Text]
 -> Maybe (Snowflake ())
 -> Maybe [Value]
 -> InteractionData)
-> Parser (Maybe (Snowflake ApplicationCommand))
-> Parser
     (Maybe Text
      -> Maybe ResolvedInteractionData
      -> Maybe CustomID
      -> Maybe ComponentType
      -> Maybe [Text]
      -> Maybe (Snowflake ())
      -> Maybe [Value]
      -> InteractionData)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe (Snowflake ApplicationCommand))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"id"
      Parser
  (Maybe Text
   -> Maybe ResolvedInteractionData
   -> Maybe CustomID
   -> Maybe ComponentType
   -> Maybe [Text]
   -> Maybe (Snowflake ())
   -> Maybe [Value]
   -> InteractionData)
-> Parser (Maybe Text)
-> Parser
     (Maybe ResolvedInteractionData
      -> Maybe CustomID
      -> Maybe ComponentType
      -> Maybe [Text]
      -> Maybe (Snowflake ())
      -> Maybe [Value]
      -> InteractionData)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"name"
      Parser
  (Maybe ResolvedInteractionData
   -> Maybe CustomID
   -> Maybe ComponentType
   -> Maybe [Text]
   -> Maybe (Snowflake ())
   -> Maybe [Value]
   -> InteractionData)
-> Parser (Maybe ResolvedInteractionData)
-> Parser
     (Maybe CustomID
      -> Maybe ComponentType
      -> Maybe [Text]
      -> Maybe (Snowflake ())
      -> Maybe [Value]
      -> InteractionData)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe ResolvedInteractionData)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"resolved"
      Parser
  (Maybe CustomID
   -> Maybe ComponentType
   -> Maybe [Text]
   -> Maybe (Snowflake ())
   -> Maybe [Value]
   -> InteractionData)
-> Parser (Maybe CustomID)
-> Parser
     (Maybe ComponentType
      -> Maybe [Text]
      -> Maybe (Snowflake ())
      -> Maybe [Value]
      -> InteractionData)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe CustomID)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"custom_id"
      Parser
  (Maybe ComponentType
   -> Maybe [Text]
   -> Maybe (Snowflake ())
   -> Maybe [Value]
   -> InteractionData)
-> Parser (Maybe ComponentType)
-> Parser
     (Maybe [Text]
      -> Maybe (Snowflake ()) -> Maybe [Value] -> InteractionData)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe ComponentType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"component_type"
      Parser
  (Maybe [Text]
   -> Maybe (Snowflake ()) -> Maybe [Value] -> InteractionData)
-> Parser (Maybe [Text])
-> Parser
     (Maybe (Snowflake ()) -> Maybe [Value] -> InteractionData)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe [Text])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"values"
      Parser (Maybe (Snowflake ()) -> Maybe [Value] -> InteractionData)
-> Parser (Maybe (Snowflake ()))
-> Parser (Maybe [Value] -> InteractionData)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe (Snowflake ()))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"target_id"
      Parser (Maybe [Value] -> InteractionData)
-> Parser (Maybe [Value]) -> Parser InteractionData
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe [Value])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"components"

data ResolvedInteractionData = ResolvedInteractionData
  { ResolvedInteractionData -> HashMap (Snowflake User) User
users :: H.HashMap (Snowflake User) User
  , ResolvedInteractionData -> HashMap (Snowflake Member) Member
members :: H.HashMap (Snowflake Member) Member
  , ResolvedInteractionData -> HashMap (Snowflake Role) Role
roles :: H.HashMap (Snowflake Role) Role
  , ResolvedInteractionData
-> HashMap (Snowflake Channel) (Partial Channel)
channels :: H.HashMap (Snowflake Channel) (Partial Channel)
  , ResolvedInteractionData
-> HashMap (Snowflake Message) (Partial Message)
messages :: H.HashMap (Snowflake Message) (Partial Message)
  , ResolvedInteractionData
-> HashMap (Snowflake Attachment) Attachment
attachments :: H.HashMap (Snowflake Attachment) Attachment
  }
  deriving (Int -> ResolvedInteractionData -> ShowS
[ResolvedInteractionData] -> ShowS
ResolvedInteractionData -> String
(Int -> ResolvedInteractionData -> ShowS)
-> (ResolvedInteractionData -> String)
-> ([ResolvedInteractionData] -> ShowS)
-> Show ResolvedInteractionData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ResolvedInteractionData -> ShowS
showsPrec :: Int -> ResolvedInteractionData -> ShowS
$cshow :: ResolvedInteractionData -> String
show :: ResolvedInteractionData -> String
$cshowList :: [ResolvedInteractionData] -> ShowS
showList :: [ResolvedInteractionData] -> ShowS
Show)
  deriving (Int -> ResolvedInteractionData -> Text
Int -> ResolvedInteractionData -> Builder
Int -> ResolvedInteractionData -> Text
[ResolvedInteractionData] -> Text
[ResolvedInteractionData] -> Builder
[ResolvedInteractionData] -> Text
ResolvedInteractionData -> Text
ResolvedInteractionData -> Builder
ResolvedInteractionData -> Text
(Int -> ResolvedInteractionData -> Builder)
-> (ResolvedInteractionData -> Builder)
-> ([ResolvedInteractionData] -> Builder)
-> (Int -> ResolvedInteractionData -> Text)
-> (ResolvedInteractionData -> Text)
-> ([ResolvedInteractionData] -> Text)
-> (Int -> ResolvedInteractionData -> Text)
-> (ResolvedInteractionData -> Text)
-> ([ResolvedInteractionData] -> Text)
-> TextShow ResolvedInteractionData
forall a.
(Int -> a -> Builder)
-> (a -> Builder)
-> ([a] -> Builder)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> TextShow a
$cshowbPrec :: Int -> ResolvedInteractionData -> Builder
showbPrec :: Int -> ResolvedInteractionData -> Builder
$cshowb :: ResolvedInteractionData -> Builder
showb :: ResolvedInteractionData -> Builder
$cshowbList :: [ResolvedInteractionData] -> Builder
showbList :: [ResolvedInteractionData] -> Builder
$cshowtPrec :: Int -> ResolvedInteractionData -> Text
showtPrec :: Int -> ResolvedInteractionData -> Text
$cshowt :: ResolvedInteractionData -> Text
showt :: ResolvedInteractionData -> Text
$cshowtList :: [ResolvedInteractionData] -> Text
showtList :: [ResolvedInteractionData] -> Text
$cshowtlPrec :: Int -> ResolvedInteractionData -> Text
showtlPrec :: Int -> ResolvedInteractionData -> Text
$cshowtl :: ResolvedInteractionData -> Text
showtl :: ResolvedInteractionData -> Text
$cshowtlList :: [ResolvedInteractionData] -> Text
showtlList :: [ResolvedInteractionData] -> Text
TextShow.TextShow) via TextShow.FromStringShow ResolvedInteractionData

instance Aeson.FromJSON ResolvedInteractionData where
  parseJSON :: Value -> Parser ResolvedInteractionData
parseJSON = String
-> (Object -> Parser ResolvedInteractionData)
-> Value
-> Parser ResolvedInteractionData
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"ResolvedInteractionData" ((Object -> Parser ResolvedInteractionData)
 -> Value -> Parser ResolvedInteractionData)
-> (Object -> Parser ResolvedInteractionData)
-> Value
-> Parser ResolvedInteractionData
forall a b. (a -> b) -> a -> b
$ \Object
v ->
    HashMap (Snowflake User) User
-> HashMap (Snowflake Member) Member
-> HashMap (Snowflake Role) Role
-> HashMap (Snowflake Channel) (Partial Channel)
-> HashMap (Snowflake Message) (Partial Message)
-> HashMap (Snowflake Attachment) Attachment
-> ResolvedInteractionData
ResolvedInteractionData
      (HashMap (Snowflake User) User
 -> HashMap (Snowflake Member) Member
 -> HashMap (Snowflake Role) Role
 -> HashMap (Snowflake Channel) (Partial Channel)
 -> HashMap (Snowflake Message) (Partial Message)
 -> HashMap (Snowflake Attachment) Attachment
 -> ResolvedInteractionData)
-> Parser (HashMap (Snowflake User) User)
-> Parser
     (HashMap (Snowflake Member) Member
      -> HashMap (Snowflake Role) Role
      -> HashMap (Snowflake Channel) (Partial Channel)
      -> HashMap (Snowflake Message) (Partial Message)
      -> HashMap (Snowflake Attachment) Attachment
      -> ResolvedInteractionData)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe (HashMap (Snowflake User) User))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"users" Parser (Maybe (HashMap (Snowflake User) User))
-> HashMap (Snowflake User) User
-> Parser (HashMap (Snowflake User) User)
forall a. Parser (Maybe a) -> a -> Parser a
.!= HashMap (Snowflake User) User
forall k v. HashMap k v
H.empty
      Parser
  (HashMap (Snowflake Member) Member
   -> HashMap (Snowflake Role) Role
   -> HashMap (Snowflake Channel) (Partial Channel)
   -> HashMap (Snowflake Message) (Partial Message)
   -> HashMap (Snowflake Attachment) Attachment
   -> ResolvedInteractionData)
-> Parser (HashMap (Snowflake Member) Member)
-> Parser
     (HashMap (Snowflake Role) Role
      -> HashMap (Snowflake Channel) (Partial Channel)
      -> HashMap (Snowflake Message) (Partial Message)
      -> HashMap (Snowflake Attachment) Attachment
      -> ResolvedInteractionData)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe (HashMap (Snowflake Member) Member))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"members" Parser (Maybe (HashMap (Snowflake Member) Member))
-> HashMap (Snowflake Member) Member
-> Parser (HashMap (Snowflake Member) Member)
forall a. Parser (Maybe a) -> a -> Parser a
.!= HashMap (Snowflake Member) Member
forall k v. HashMap k v
H.empty
      Parser
  (HashMap (Snowflake Role) Role
   -> HashMap (Snowflake Channel) (Partial Channel)
   -> HashMap (Snowflake Message) (Partial Message)
   -> HashMap (Snowflake Attachment) Attachment
   -> ResolvedInteractionData)
-> Parser (HashMap (Snowflake Role) Role)
-> Parser
     (HashMap (Snowflake Channel) (Partial Channel)
      -> HashMap (Snowflake Message) (Partial Message)
      -> HashMap (Snowflake Attachment) Attachment
      -> ResolvedInteractionData)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe (HashMap (Snowflake Role) Role))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"roles" Parser (Maybe (HashMap (Snowflake Role) Role))
-> HashMap (Snowflake Role) Role
-> Parser (HashMap (Snowflake Role) Role)
forall a. Parser (Maybe a) -> a -> Parser a
.!= HashMap (Snowflake Role) Role
forall k v. HashMap k v
H.empty
      Parser
  (HashMap (Snowflake Channel) (Partial Channel)
   -> HashMap (Snowflake Message) (Partial Message)
   -> HashMap (Snowflake Attachment) Attachment
   -> ResolvedInteractionData)
-> Parser (HashMap (Snowflake Channel) (Partial Channel))
-> Parser
     (HashMap (Snowflake Message) (Partial Message)
      -> HashMap (Snowflake Attachment) Attachment
      -> ResolvedInteractionData)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object
-> Key
-> Parser (Maybe (HashMap (Snowflake Channel) (Partial Channel)))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"channels" Parser (Maybe (HashMap (Snowflake Channel) (Partial Channel)))
-> HashMap (Snowflake Channel) (Partial Channel)
-> Parser (HashMap (Snowflake Channel) (Partial Channel))
forall a. Parser (Maybe a) -> a -> Parser a
.!= HashMap (Snowflake Channel) (Partial Channel)
forall k v. HashMap k v
H.empty
      Parser
  (HashMap (Snowflake Message) (Partial Message)
   -> HashMap (Snowflake Attachment) Attachment
   -> ResolvedInteractionData)
-> Parser (HashMap (Snowflake Message) (Partial Message))
-> Parser
     (HashMap (Snowflake Attachment) Attachment
      -> ResolvedInteractionData)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object
-> Key
-> Parser (Maybe (HashMap (Snowflake Message) (Partial Message)))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"messages" Parser (Maybe (HashMap (Snowflake Message) (Partial Message)))
-> HashMap (Snowflake Message) (Partial Message)
-> Parser (HashMap (Snowflake Message) (Partial Message))
forall a. Parser (Maybe a) -> a -> Parser a
.!= HashMap (Snowflake Message) (Partial Message)
forall k v. HashMap k v
H.empty
      Parser
  (HashMap (Snowflake Attachment) Attachment
   -> ResolvedInteractionData)
-> Parser (HashMap (Snowflake Attachment) Attachment)
-> Parser ResolvedInteractionData
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object
-> Key
-> Parser (Maybe (HashMap (Snowflake Attachment) Attachment))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"attachments" Parser (Maybe (HashMap (Snowflake Attachment) Attachment))
-> HashMap (Snowflake Attachment) Attachment
-> Parser (HashMap (Snowflake Attachment) Attachment)
forall a. Parser (Maybe a) -> a -> Parser a
.!= HashMap (Snowflake Attachment) Attachment
forall k v. HashMap k v
H.empty

data InteractionType
  = PingType
  | ApplicationCommandType
  | MessageComponentType
  | ApplicationCommandAutoCompleteType
  | ModalSubmitType
  deriving (InteractionType -> InteractionType -> Bool
(InteractionType -> InteractionType -> Bool)
-> (InteractionType -> InteractionType -> Bool)
-> Eq InteractionType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InteractionType -> InteractionType -> Bool
== :: InteractionType -> InteractionType -> Bool
$c/= :: InteractionType -> InteractionType -> Bool
/= :: InteractionType -> InteractionType -> Bool
Eq, Int -> InteractionType -> ShowS
[InteractionType] -> ShowS
InteractionType -> String
(Int -> InteractionType -> ShowS)
-> (InteractionType -> String)
-> ([InteractionType] -> ShowS)
-> Show InteractionType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InteractionType -> ShowS
showsPrec :: Int -> InteractionType -> ShowS
$cshow :: InteractionType -> String
show :: InteractionType -> String
$cshowList :: [InteractionType] -> ShowS
showList :: [InteractionType] -> ShowS
Show)

instance Aeson.FromJSON InteractionType where
  parseJSON :: Value -> Parser InteractionType
parseJSON = String
-> (Scientific -> Parser InteractionType)
-> Value
-> Parser InteractionType
forall a. String -> (Scientific -> Parser a) -> Value -> Parser a
Aeson.withScientific String
"InteractionType" ((Scientific -> Parser InteractionType)
 -> Value -> Parser InteractionType)
-> (Scientific -> Parser InteractionType)
-> Value
-> Parser InteractionType
forall a b. (a -> b) -> a -> b
$ \Scientific
n -> case forall i. (Integral i, Bounded i) => Scientific -> Maybe i
toBoundedInteger @Int Scientific
n of
    Just Int
1 -> InteractionType -> Parser InteractionType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InteractionType
PingType
    Just Int
2 -> InteractionType -> Parser InteractionType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InteractionType
ApplicationCommandType
    Just Int
3 -> InteractionType -> Parser InteractionType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InteractionType
MessageComponentType
    Just Int
4 -> InteractionType -> Parser InteractionType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InteractionType
ApplicationCommandAutoCompleteType
    Just Int
5 -> InteractionType -> Parser InteractionType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InteractionType
ModalSubmitType
    Maybe Int
_ -> String -> Parser InteractionType
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser InteractionType)
-> String -> Parser InteractionType
forall a b. (a -> b) -> a -> b
$ String
"Invalid InteractionType: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Scientific -> String
forall a. Show a => a -> String
show Scientific
n

$(deriveTextShow ''InteractionToken)
$(deriveTextShow ''InteractionType)
$(deriveTextShow ''Interaction)
$(makeFieldLabelsNoPrefix ''InteractionToken)
$(makeFieldLabelsNoPrefix ''Interaction)
$(makeFieldLabelsNoPrefix ''InteractionData)
$(makeFieldLabelsNoPrefix ''ResolvedInteractionData)
$(makeFieldLabelsNoPrefix ''InteractionType)