{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.CodeCommit.GetComment
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Returns the content of a comment made on a change, file, or commit in a
-- repository.
--
-- Reaction counts might include numbers from user identities who were
-- deleted after the reaction was made. For a count of reactions from
-- active identities, use GetCommentReactions.
module Amazonka.CodeCommit.GetComment
  ( -- * Creating a Request
    GetComment (..),
    newGetComment,

    -- * Request Lenses
    getComment_commentId,

    -- * Destructuring the Response
    GetCommentResponse (..),
    newGetCommentResponse,

    -- * Response Lenses
    getCommentResponse_comment,
    getCommentResponse_httpStatus,
  )
where

import Amazonka.CodeCommit.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newGetComment' smart constructor.
data GetComment = GetComment'
  { -- | The unique, system-generated ID of the comment. To get this ID, use
    -- GetCommentsForComparedCommit or GetCommentsForPullRequest.
    GetComment -> Text
commentId :: Prelude.Text
  }
  deriving (GetComment -> GetComment -> Bool
(GetComment -> GetComment -> Bool)
-> (GetComment -> GetComment -> Bool) -> Eq GetComment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetComment -> GetComment -> Bool
$c/= :: GetComment -> GetComment -> Bool
== :: GetComment -> GetComment -> Bool
$c== :: GetComment -> GetComment -> Bool
Prelude.Eq, ReadPrec [GetComment]
ReadPrec GetComment
Int -> ReadS GetComment
ReadS [GetComment]
(Int -> ReadS GetComment)
-> ReadS [GetComment]
-> ReadPrec GetComment
-> ReadPrec [GetComment]
-> Read GetComment
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetComment]
$creadListPrec :: ReadPrec [GetComment]
readPrec :: ReadPrec GetComment
$creadPrec :: ReadPrec GetComment
readList :: ReadS [GetComment]
$creadList :: ReadS [GetComment]
readsPrec :: Int -> ReadS GetComment
$creadsPrec :: Int -> ReadS GetComment
Prelude.Read, Int -> GetComment -> ShowS
[GetComment] -> ShowS
GetComment -> String
(Int -> GetComment -> ShowS)
-> (GetComment -> String)
-> ([GetComment] -> ShowS)
-> Show GetComment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetComment] -> ShowS
$cshowList :: [GetComment] -> ShowS
show :: GetComment -> String
$cshow :: GetComment -> String
showsPrec :: Int -> GetComment -> ShowS
$cshowsPrec :: Int -> GetComment -> ShowS
Prelude.Show, (forall x. GetComment -> Rep GetComment x)
-> (forall x. Rep GetComment x -> GetComment) -> Generic GetComment
forall x. Rep GetComment x -> GetComment
forall x. GetComment -> Rep GetComment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetComment x -> GetComment
$cfrom :: forall x. GetComment -> Rep GetComment x
Prelude.Generic)

-- |
-- Create a value of 'GetComment' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'commentId', 'getComment_commentId' - The unique, system-generated ID of the comment. To get this ID, use
-- GetCommentsForComparedCommit or GetCommentsForPullRequest.
newGetComment ::
  -- | 'commentId'
  Prelude.Text ->
  GetComment
newGetComment :: Text -> GetComment
newGetComment Text
pCommentId_ =
  GetComment' :: Text -> GetComment
GetComment' {$sel:commentId:GetComment' :: Text
commentId = Text
pCommentId_}

-- | The unique, system-generated ID of the comment. To get this ID, use
-- GetCommentsForComparedCommit or GetCommentsForPullRequest.
getComment_commentId :: Lens.Lens' GetComment Prelude.Text
getComment_commentId :: (Text -> f Text) -> GetComment -> f GetComment
getComment_commentId = (GetComment -> Text)
-> (GetComment -> Text -> GetComment)
-> Lens GetComment GetComment Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetComment' {Text
commentId :: Text
$sel:commentId:GetComment' :: GetComment -> Text
commentId} -> Text
commentId) (\s :: GetComment
s@GetComment' {} Text
a -> GetComment
s {$sel:commentId:GetComment' :: Text
commentId = Text
a} :: GetComment)

instance Core.AWSRequest GetComment where
  type AWSResponse GetComment = GetCommentResponse
  request :: GetComment -> Request GetComment
request = Service -> GetComment -> Request GetComment
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetComment
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetComment)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetComment))
-> Logger
-> Service
-> Proxy GetComment
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetComment)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Comment -> Int -> GetCommentResponse
GetCommentResponse'
            (Maybe Comment -> Int -> GetCommentResponse)
-> Either String (Maybe Comment)
-> Either String (Int -> GetCommentResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Comment)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"comment")
            Either String (Int -> GetCommentResponse)
-> Either String Int -> Either String GetCommentResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable GetComment

instance Prelude.NFData GetComment

instance Core.ToHeaders GetComment where
  toHeaders :: GetComment -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetComment -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"CodeCommit_20150413.GetComment" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON GetComment where
  toJSON :: GetComment -> Value
toJSON GetComment' {Text
commentId :: Text
$sel:commentId:GetComment' :: GetComment -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"commentId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
commentId)]
      )

instance Core.ToPath GetComment where
  toPath :: GetComment -> ByteString
toPath = ByteString -> GetComment -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery GetComment where
  toQuery :: GetComment -> QueryString
toQuery = QueryString -> GetComment -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newGetCommentResponse' smart constructor.
data GetCommentResponse = GetCommentResponse'
  { -- | The contents of the comment.
    GetCommentResponse -> Maybe Comment
comment :: Prelude.Maybe Comment,
    -- | The response's http status code.
    GetCommentResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetCommentResponse -> GetCommentResponse -> Bool
(GetCommentResponse -> GetCommentResponse -> Bool)
-> (GetCommentResponse -> GetCommentResponse -> Bool)
-> Eq GetCommentResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetCommentResponse -> GetCommentResponse -> Bool
$c/= :: GetCommentResponse -> GetCommentResponse -> Bool
== :: GetCommentResponse -> GetCommentResponse -> Bool
$c== :: GetCommentResponse -> GetCommentResponse -> Bool
Prelude.Eq, ReadPrec [GetCommentResponse]
ReadPrec GetCommentResponse
Int -> ReadS GetCommentResponse
ReadS [GetCommentResponse]
(Int -> ReadS GetCommentResponse)
-> ReadS [GetCommentResponse]
-> ReadPrec GetCommentResponse
-> ReadPrec [GetCommentResponse]
-> Read GetCommentResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetCommentResponse]
$creadListPrec :: ReadPrec [GetCommentResponse]
readPrec :: ReadPrec GetCommentResponse
$creadPrec :: ReadPrec GetCommentResponse
readList :: ReadS [GetCommentResponse]
$creadList :: ReadS [GetCommentResponse]
readsPrec :: Int -> ReadS GetCommentResponse
$creadsPrec :: Int -> ReadS GetCommentResponse
Prelude.Read, Int -> GetCommentResponse -> ShowS
[GetCommentResponse] -> ShowS
GetCommentResponse -> String
(Int -> GetCommentResponse -> ShowS)
-> (GetCommentResponse -> String)
-> ([GetCommentResponse] -> ShowS)
-> Show GetCommentResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetCommentResponse] -> ShowS
$cshowList :: [GetCommentResponse] -> ShowS
show :: GetCommentResponse -> String
$cshow :: GetCommentResponse -> String
showsPrec :: Int -> GetCommentResponse -> ShowS
$cshowsPrec :: Int -> GetCommentResponse -> ShowS
Prelude.Show, (forall x. GetCommentResponse -> Rep GetCommentResponse x)
-> (forall x. Rep GetCommentResponse x -> GetCommentResponse)
-> Generic GetCommentResponse
forall x. Rep GetCommentResponse x -> GetCommentResponse
forall x. GetCommentResponse -> Rep GetCommentResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetCommentResponse x -> GetCommentResponse
$cfrom :: forall x. GetCommentResponse -> Rep GetCommentResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetCommentResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'comment', 'getCommentResponse_comment' - The contents of the comment.
--
-- 'httpStatus', 'getCommentResponse_httpStatus' - The response's http status code.
newGetCommentResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetCommentResponse
newGetCommentResponse :: Int -> GetCommentResponse
newGetCommentResponse Int
pHttpStatus_ =
  GetCommentResponse' :: Maybe Comment -> Int -> GetCommentResponse
GetCommentResponse'
    { $sel:comment:GetCommentResponse' :: Maybe Comment
comment = Maybe Comment
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetCommentResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The contents of the comment.
getCommentResponse_comment :: Lens.Lens' GetCommentResponse (Prelude.Maybe Comment)
getCommentResponse_comment :: (Maybe Comment -> f (Maybe Comment))
-> GetCommentResponse -> f GetCommentResponse
getCommentResponse_comment = (GetCommentResponse -> Maybe Comment)
-> (GetCommentResponse -> Maybe Comment -> GetCommentResponse)
-> Lens
     GetCommentResponse
     GetCommentResponse
     (Maybe Comment)
     (Maybe Comment)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCommentResponse' {Maybe Comment
comment :: Maybe Comment
$sel:comment:GetCommentResponse' :: GetCommentResponse -> Maybe Comment
comment} -> Maybe Comment
comment) (\s :: GetCommentResponse
s@GetCommentResponse' {} Maybe Comment
a -> GetCommentResponse
s {$sel:comment:GetCommentResponse' :: Maybe Comment
comment = Maybe Comment
a} :: GetCommentResponse)

-- | The response's http status code.
getCommentResponse_httpStatus :: Lens.Lens' GetCommentResponse Prelude.Int
getCommentResponse_httpStatus :: (Int -> f Int) -> GetCommentResponse -> f GetCommentResponse
getCommentResponse_httpStatus = (GetCommentResponse -> Int)
-> (GetCommentResponse -> Int -> GetCommentResponse)
-> Lens GetCommentResponse GetCommentResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCommentResponse' {Int
httpStatus :: Int
$sel:httpStatus:GetCommentResponse' :: GetCommentResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: GetCommentResponse
s@GetCommentResponse' {} Int
a -> GetCommentResponse
s {$sel:httpStatus:GetCommentResponse' :: Int
httpStatus = Int
a} :: GetCommentResponse)

instance Prelude.NFData GetCommentResponse