{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeApplications #-}

module Discord.Internal.Rest.Interactions where

import Data.Aeson (ToJSON (toJSON), Value)
import Network.HTTP.Req as R

import Discord.Internal.Rest.Prelude
import Discord.Internal.Types
import Discord.Internal.Types.Interactions

data InteractionResponseRequest a where
  CreateInteractionResponse :: InteractionId -> InteractionToken -> InteractionResponse -> InteractionResponseRequest ()
  GetOriginalInteractionResponse :: ApplicationId -> InteractionToken -> InteractionResponseRequest Message
  EditOriginalInteractionResponse :: ApplicationId -> InteractionToken -> InteractionCallbackMessages -> InteractionResponseRequest Message
  DeleteOriginalInteractionResponse :: ApplicationId -> InteractionToken -> InteractionResponseRequest ()
  CreateFollowupInteractionMessage :: ApplicationId -> InteractionToken -> InteractionCallbackMessages  -> InteractionResponseRequest Message
  GetFollowupInteractionMessage :: ApplicationId -> InteractionToken -> MessageId -> InteractionResponseRequest Message
  EditFollowupInteractionMessage :: ApplicationId -> InteractionToken -> MessageId -> InteractionResponse -> InteractionResponseRequest Message
  DeleteFollowupInteractionMessage :: ApplicationId -> InteractionToken -> MessageId -> InteractionResponseRequest ()

instance Request (InteractionResponseRequest a) where
  jsonRequest :: InteractionResponseRequest a -> JsonRequest
jsonRequest = InteractionResponseRequest a -> JsonRequest
forall a. InteractionResponseRequest a -> JsonRequest
interactionResponseJsonRequest
  majorRoute :: InteractionResponseRequest a -> String
majorRoute = InteractionResponseRequest a -> String
forall a. InteractionResponseRequest a -> String
interactionResponseMajorRoute

interactionResponseMajorRoute :: InteractionResponseRequest a -> String
interactionResponseMajorRoute :: InteractionResponseRequest a -> String
interactionResponseMajorRoute InteractionResponseRequest a
a = case InteractionResponseRequest a
a of
  (CreateInteractionResponse InteractionId
iid InteractionToken
_ InteractionResponse
_) -> String
"intresp " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> InteractionId -> String
forall a. Show a => a -> String
show InteractionId
iid
  (GetOriginalInteractionResponse InteractionId
aid InteractionToken
_) -> String
"intresp " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> InteractionId -> String
forall a. Show a => a -> String
show InteractionId
aid
  (EditOriginalInteractionResponse InteractionId
aid InteractionToken
_ InteractionCallbackMessages
_) -> String
"intresp " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> InteractionId -> String
forall a. Show a => a -> String
show InteractionId
aid
  (DeleteOriginalInteractionResponse InteractionId
aid InteractionToken
_) -> String
"intresp " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> InteractionId -> String
forall a. Show a => a -> String
show InteractionId
aid
  (CreateFollowupInteractionMessage InteractionId
iid InteractionToken
_ InteractionCallbackMessages
_) -> String
"intrespf " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> InteractionId -> String
forall a. Show a => a -> String
show InteractionId
iid
  (GetFollowupInteractionMessage InteractionId
aid InteractionToken
_ InteractionId
_) -> String
"intrespf " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> InteractionId -> String
forall a. Show a => a -> String
show InteractionId
aid
  (EditFollowupInteractionMessage InteractionId
aid InteractionToken
_ InteractionId
_ InteractionResponse
_) -> String
"intrespf " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> InteractionId -> String
forall a. Show a => a -> String
show InteractionId
aid
  (DeleteFollowupInteractionMessage InteractionId
aid InteractionToken
_ InteractionId
_) -> String
"intrespf " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> InteractionId -> String
forall a. Show a => a -> String
show InteractionId
aid

interaction :: ApplicationId -> InteractionToken -> R.Url 'R.Https
interaction :: InteractionId -> InteractionToken -> Url 'Https
interaction InteractionId
aid InteractionToken
it = Url 'Https
baseUrl Url 'Https -> InteractionToken -> Url 'Https
forall (scheme :: Scheme).
Url scheme -> InteractionToken -> Url scheme
/: InteractionToken
"webhooks" Url 'Https -> InteractionId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// InteractionId
aid Url 'Https -> InteractionToken -> Url 'Https
forall (scheme :: Scheme).
Url scheme -> InteractionToken -> Url scheme
/: InteractionToken
it Url 'Https -> InteractionToken -> Url 'Https
forall (scheme :: Scheme).
Url scheme -> InteractionToken -> Url scheme
/: InteractionToken
"messages"

interactionResponseJsonRequest :: InteractionResponseRequest a -> JsonRequest
interactionResponseJsonRequest :: InteractionResponseRequest a -> JsonRequest
interactionResponseJsonRequest InteractionResponseRequest a
a = case InteractionResponseRequest a
a of
  (CreateInteractionResponse InteractionId
iid InteractionToken
it InteractionResponse
i) ->
    Url 'Https
-> RestIO (ReqBodyJson Value) -> Option 'Https -> JsonRequest
forall a.
HttpBody a =>
Url 'Https -> RestIO a -> Option 'Https -> JsonRequest
Post (Url 'Https
baseUrl Url 'Https -> InteractionToken -> Url 'Https
forall (scheme :: Scheme).
Url scheme -> InteractionToken -> Url scheme
/: InteractionToken
"interactions" Url 'Https -> InteractionId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// InteractionId
iid Url 'Https -> InteractionToken -> Url 'Https
forall (scheme :: Scheme).
Url scheme -> InteractionToken -> Url scheme
/: InteractionToken
it Url 'Https -> InteractionToken -> Url 'Https
forall (scheme :: Scheme).
Url scheme -> InteractionToken -> Url scheme
/: InteractionToken
"callback") (InteractionResponse -> RestIO (ReqBodyJson Value)
forall a. ToJSON a => a -> RestIO (ReqBodyJson Value)
convert InteractionResponse
i) Option 'Https
forall a. Monoid a => a
mempty
  (GetOriginalInteractionResponse InteractionId
aid InteractionToken
it) ->
    Url 'Https -> Option 'Https -> JsonRequest
Get (InteractionId -> InteractionToken -> Url 'Https
interaction InteractionId
aid InteractionToken
it Url 'Https -> InteractionToken -> Url 'Https
forall (scheme :: Scheme).
Url scheme -> InteractionToken -> Url scheme
/: InteractionToken
"@original") Option 'Https
forall a. Monoid a => a
mempty
  (EditOriginalInteractionResponse InteractionId
aid InteractionToken
it InteractionCallbackMessages
i) ->
    Url 'Https
-> RestIO (ReqBodyJson Value) -> Option 'Https -> JsonRequest
forall a.
HttpBody a =>
Url 'Https -> RestIO a -> Option 'Https -> JsonRequest
Patch (InteractionId -> InteractionToken -> Url 'Https
interaction InteractionId
aid InteractionToken
it Url 'Https -> InteractionToken -> Url 'Https
forall (scheme :: Scheme).
Url scheme -> InteractionToken -> Url scheme
/: InteractionToken
"@original") (InteractionCallbackMessages -> RestIO (ReqBodyJson Value)
forall a. ToJSON a => a -> RestIO (ReqBodyJson Value)
convert InteractionCallbackMessages
i) Option 'Https
forall a. Monoid a => a
mempty
  (DeleteOriginalInteractionResponse InteractionId
aid InteractionToken
it) ->
    Url 'Https -> Option 'Https -> JsonRequest
Delete (InteractionId -> InteractionToken -> Url 'Https
interaction InteractionId
aid InteractionToken
it Url 'Https -> InteractionToken -> Url 'Https
forall (scheme :: Scheme).
Url scheme -> InteractionToken -> Url scheme
/: InteractionToken
"@original") Option 'Https
forall a. Monoid a => a
mempty
  (CreateFollowupInteractionMessage InteractionId
aid InteractionToken
it InteractionCallbackMessages
i) ->
    Url 'Https
-> RestIO (ReqBodyJson Value) -> Option 'Https -> JsonRequest
forall a.
HttpBody a =>
Url 'Https -> RestIO a -> Option 'Https -> JsonRequest
Post (Url 'Https
baseUrl Url 'Https -> InteractionToken -> Url 'Https
forall (scheme :: Scheme).
Url scheme -> InteractionToken -> Url scheme
/: InteractionToken
"webhooks" Url 'Https -> InteractionId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// InteractionId
aid Url 'Https -> InteractionToken -> Url 'Https
forall (scheme :: Scheme).
Url scheme -> InteractionToken -> Url scheme
/: InteractionToken
it) (InteractionCallbackMessages -> RestIO (ReqBodyJson Value)
forall a. ToJSON a => a -> RestIO (ReqBodyJson Value)
convert InteractionCallbackMessages
i) Option 'Https
forall a. Monoid a => a
mempty
  (GetFollowupInteractionMessage InteractionId
aid InteractionToken
it InteractionId
mid) ->
    Url 'Https -> Option 'Https -> JsonRequest
Get (InteractionId -> InteractionToken -> Url 'Https
interaction InteractionId
aid InteractionToken
it Url 'Https -> InteractionId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// InteractionId
mid) Option 'Https
forall a. Monoid a => a
mempty
  (EditFollowupInteractionMessage InteractionId
aid InteractionToken
it InteractionId
mid InteractionResponse
i) ->
    Url 'Https
-> RestIO (ReqBodyJson Value) -> Option 'Https -> JsonRequest
forall a.
HttpBody a =>
Url 'Https -> RestIO a -> Option 'Https -> JsonRequest
Patch (InteractionId -> InteractionToken -> Url 'Https
interaction InteractionId
aid InteractionToken
it Url 'Https -> InteractionId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// InteractionId
mid) (InteractionResponse -> RestIO (ReqBodyJson Value)
forall a. ToJSON a => a -> RestIO (ReqBodyJson Value)
convert InteractionResponse
i) Option 'Https
forall a. Monoid a => a
mempty
  (DeleteFollowupInteractionMessage InteractionId
aid InteractionToken
it InteractionId
mid) ->
    Url 'Https -> Option 'Https -> JsonRequest
Delete (InteractionId -> InteractionToken -> Url 'Https
interaction InteractionId
aid InteractionToken
it Url 'Https -> InteractionId -> Url 'Https
forall a (scheme :: Scheme).
Show a =>
Url scheme -> a -> Url scheme
// InteractionId
mid) Option 'Https
forall a. Monoid a => a
mempty
  where
    convert :: (ToJSON a) => a -> RestIO (ReqBodyJson Value)
    convert :: a -> RestIO (ReqBodyJson Value)
convert = (forall a. Applicative RestIO => a -> RestIO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure @RestIO) (ReqBodyJson Value -> RestIO (ReqBodyJson Value))
-> (a -> ReqBodyJson Value) -> a -> RestIO (ReqBodyJson Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> ReqBodyJson Value
forall a. a -> ReqBodyJson a
R.ReqBodyJson (Value -> ReqBodyJson Value)
-> (a -> Value) -> a -> ReqBodyJson Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Value
forall a. ToJSON a => a -> Value
toJSON