{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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' {$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 :: Lens' GetComment Text
getComment_commentId = 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 :: (Service -> Service) -> GetComment -> Request GetComment
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetComment
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetComment)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Comment -> Int -> GetCommentResponse
GetCommentResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"comment")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable GetComment where
  hashWithSalt :: Int -> GetComment -> Int
hashWithSalt Int
_salt GetComment' {Text
commentId :: Text
$sel:commentId:GetComment' :: GetComment -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
commentId

instance Prelude.NFData GetComment where
  rnf :: GetComment -> ()
rnf GetComment' {Text
commentId :: Text
$sel:commentId:GetComment' :: GetComment -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
commentId

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

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

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

instance Data.ToQuery GetComment where
  toQuery :: GetComment -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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. 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'
    { $sel:comment:GetCommentResponse' :: Maybe Comment
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 :: Lens' GetCommentResponse (Maybe Comment)
getCommentResponse_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 :: Lens' GetCommentResponse Int
getCommentResponse_httpStatus = 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 where
  rnf :: GetCommentResponse -> ()
rnf GetCommentResponse' {Int
Maybe Comment
httpStatus :: Int
comment :: Maybe Comment
$sel:httpStatus:GetCommentResponse' :: GetCommentResponse -> Int
$sel:comment:GetCommentResponse' :: GetCommentResponse -> Maybe Comment
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Comment
comment
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus