-- |
-- The Reactions API as described at
-- <https://docs.github.com/en/rest/reactions/reactions?apiVersion=2022-11-28>.
module GitHub.Endpoints.Reactions (
  issueReactionsR,
  createIssueReactionR,
  deleteIssueReactionR,
  commentReactionsR,
  createCommentReactionR,
  deleteCommentReactionR,
  module GitHub.Data,
) where

import GitHub.Data
import GitHub.Internal.Prelude
import Prelude ()

-- | List reactions for an issue.
-- See <https://docs.github.com/en/rest/reactions/reactions?apiVersion=2022-11-28#list-reactions-for-an-issue>
issueReactionsR :: Name Owner -> Name Repo -> Id Issue -> FetchCount -> Request k (Vector Reaction)
issueReactionsR :: forall (k :: RW).
Name Owner
-> Name Repo
-> Id Issue
-> FetchCount
-> Request k (Vector Reaction)
issueReactionsR Name Owner
owner Name Repo
repo Id Issue
iid =
  Paths -> QueryString -> FetchCount -> Request k (Vector Reaction)
forall a (mt :: RW).
FromJSON a =>
Paths -> QueryString -> FetchCount -> Request mt (Vector a)
pagedQuery [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
owner, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"issues", Id Issue -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Issue
iid, Text
"reactions"] []

-- | Create reaction for an issue comment.
-- See <https://docs.github.com/en/rest/reactions/reactions?apiVersion=2022-11-28#create-reaction-for-an-issue>
createIssueReactionR :: Name Owner -> Name Repo -> Id Issue -> ReactionContent -> Request 'RW Reaction
createIssueReactionR :: Name Owner
-> Name Repo -> Id Issue -> ReactionContent -> Request 'RW Reaction
createIssueReactionR Name Owner
owner Name Repo
repo Id Issue
iid ReactionContent
content =
    CommandMethod -> Paths -> ByteString -> Request 'RW Reaction
forall a. CommandMethod -> Paths -> ByteString -> Request 'RW a
command CommandMethod
Post Paths
parts (NewReaction -> ByteString
forall a. ToJSON a => a -> ByteString
encode (NewReaction -> ByteString) -> NewReaction -> ByteString
forall a b. (a -> b) -> a -> b
$ ReactionContent -> NewReaction
NewReaction ReactionContent
content)
  where
    parts :: Paths
parts = [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
owner, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"issues", Id Issue -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Issue
iid, Text
"reactions"]

-- | Delete an issue comment reaction.
-- See <https://docs.github.com/en/rest/reactions/reactions?apiVersion=2022-11-28#delete-an-issue-reaction>
deleteIssueReactionR :: Name Owner -> Name Repo -> Id Issue -> Id Reaction -> GenRequest 'MtUnit 'RW ()
deleteIssueReactionR :: Name Owner
-> Name Repo
-> Id Issue
-> Id Reaction
-> GenRequest 'MtUnit 'RW ()
deleteIssueReactionR Name Owner
owner Name Repo
repo Id Issue
iid Id Reaction
rid =
    CommandMethod -> Paths -> ByteString -> GenRequest 'MtUnit 'RW ()
forall (mt :: MediaType (*)) a.
CommandMethod -> Paths -> ByteString -> GenRequest mt 'RW a
Command CommandMethod
Delete Paths
parts ByteString
forall a. Monoid a => a
mempty
  where
    parts :: Paths
parts = [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
owner, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"issues", Id Issue -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Issue
iid, Text
"reactions", Id Reaction -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Reaction
rid]

-- | List reactions for an issue comment.
-- See <https://docs.github.com/en/rest/reactions/reactions?apiVersion=2022-11-28#list-reactions-for-an-issue-comment>
commentReactionsR :: Name Owner -> Name Repo -> Id Comment -> FetchCount -> Request k (Vector Reaction)
commentReactionsR :: forall (k :: RW).
Name Owner
-> Name Repo
-> Id Comment
-> FetchCount
-> Request k (Vector Reaction)
commentReactionsR Name Owner
owner Name Repo
repo Id Comment
cid =
  Paths -> QueryString -> FetchCount -> Request k (Vector Reaction)
forall a (mt :: RW).
FromJSON a =>
Paths -> QueryString -> FetchCount -> Request mt (Vector a)
pagedQuery [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
owner, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"issues", Text
"comments", Id Comment -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Comment
cid, Text
"reactions"] []

-- | Create reaction for an issue comment.
-- See https://docs.github.com/en/rest/reactions/reactions?apiVersion=2022-11-28#create-reaction-for-an-issue-comment
createCommentReactionR :: Name Owner -> Name Repo -> Id Comment -> ReactionContent -> Request 'RW Reaction
createCommentReactionR :: Name Owner
-> Name Repo
-> Id Comment
-> ReactionContent
-> Request 'RW Reaction
createCommentReactionR Name Owner
owner Name Repo
repo Id Comment
cid ReactionContent
content =
    CommandMethod -> Paths -> ByteString -> Request 'RW Reaction
forall a. CommandMethod -> Paths -> ByteString -> Request 'RW a
command CommandMethod
Post Paths
parts (NewReaction -> ByteString
forall a. ToJSON a => a -> ByteString
encode (NewReaction -> ByteString) -> NewReaction -> ByteString
forall a b. (a -> b) -> a -> b
$ ReactionContent -> NewReaction
NewReaction ReactionContent
content)
  where
    parts :: Paths
parts = [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
owner, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"issues", Text
"comments", Id Comment -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Comment
cid, Text
"reactions"]

-- | Delete an issue comment reaction.
-- See <https://docs.github.com/en/rest/reactions/reactions?apiVersion=2022-11-28#delete-an-issue-comment-reaction>
deleteCommentReactionR :: Name Owner -> Name Repo -> Id Comment -> Id Reaction -> GenRequest 'MtUnit 'RW ()
deleteCommentReactionR :: Name Owner
-> Name Repo
-> Id Comment
-> Id Reaction
-> GenRequest 'MtUnit 'RW ()
deleteCommentReactionR Name Owner
owner Name Repo
repo Id Comment
cid Id Reaction
rid =
    CommandMethod -> Paths -> ByteString -> GenRequest 'MtUnit 'RW ()
forall (mt :: MediaType (*)) a.
CommandMethod -> Paths -> ByteString -> GenRequest mt 'RW a
Command CommandMethod
Delete Paths
parts ByteString
forall a. Monoid a => a
mempty
  where
    parts :: Paths
parts = [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
owner, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"issues", Text
"comments", Id Comment -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Comment
cid, Text
"reactions", Id Reaction -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Reaction
rid]