{-# 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.ConnectParticipant.CompleteAttachmentUpload
-- 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)
--
-- Allows you to confirm that the attachment has been uploaded using the
-- pre-signed URL provided in StartAttachmentUpload API.
module Amazonka.ConnectParticipant.CompleteAttachmentUpload
  ( -- * Creating a Request
    CompleteAttachmentUpload (..),
    newCompleteAttachmentUpload,

    -- * Request Lenses
    completeAttachmentUpload_attachmentIds,
    completeAttachmentUpload_clientToken,
    completeAttachmentUpload_connectionToken,

    -- * Destructuring the Response
    CompleteAttachmentUploadResponse (..),
    newCompleteAttachmentUploadResponse,

    -- * Response Lenses
    completeAttachmentUploadResponse_httpStatus,
  )
where

import Amazonka.ConnectParticipant.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:/ 'newCompleteAttachmentUpload' smart constructor.
data CompleteAttachmentUpload = CompleteAttachmentUpload'
  { -- | A list of unique identifiers for the attachments.
    CompleteAttachmentUpload -> NonEmpty Text
attachmentIds :: Prelude.NonEmpty Prelude.Text,
    -- | A unique, case-sensitive identifier that you provide to ensure the
    -- idempotency of the request.
    CompleteAttachmentUpload -> Text
clientToken :: Prelude.Text,
    -- | The authentication token associated with the participant\'s connection.
    CompleteAttachmentUpload -> Text
connectionToken :: Prelude.Text
  }
  deriving (CompleteAttachmentUpload -> CompleteAttachmentUpload -> Bool
(CompleteAttachmentUpload -> CompleteAttachmentUpload -> Bool)
-> (CompleteAttachmentUpload -> CompleteAttachmentUpload -> Bool)
-> Eq CompleteAttachmentUpload
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CompleteAttachmentUpload -> CompleteAttachmentUpload -> Bool
$c/= :: CompleteAttachmentUpload -> CompleteAttachmentUpload -> Bool
== :: CompleteAttachmentUpload -> CompleteAttachmentUpload -> Bool
$c== :: CompleteAttachmentUpload -> CompleteAttachmentUpload -> Bool
Prelude.Eq, ReadPrec [CompleteAttachmentUpload]
ReadPrec CompleteAttachmentUpload
Int -> ReadS CompleteAttachmentUpload
ReadS [CompleteAttachmentUpload]
(Int -> ReadS CompleteAttachmentUpload)
-> ReadS [CompleteAttachmentUpload]
-> ReadPrec CompleteAttachmentUpload
-> ReadPrec [CompleteAttachmentUpload]
-> Read CompleteAttachmentUpload
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CompleteAttachmentUpload]
$creadListPrec :: ReadPrec [CompleteAttachmentUpload]
readPrec :: ReadPrec CompleteAttachmentUpload
$creadPrec :: ReadPrec CompleteAttachmentUpload
readList :: ReadS [CompleteAttachmentUpload]
$creadList :: ReadS [CompleteAttachmentUpload]
readsPrec :: Int -> ReadS CompleteAttachmentUpload
$creadsPrec :: Int -> ReadS CompleteAttachmentUpload
Prelude.Read, Int -> CompleteAttachmentUpload -> ShowS
[CompleteAttachmentUpload] -> ShowS
CompleteAttachmentUpload -> String
(Int -> CompleteAttachmentUpload -> ShowS)
-> (CompleteAttachmentUpload -> String)
-> ([CompleteAttachmentUpload] -> ShowS)
-> Show CompleteAttachmentUpload
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CompleteAttachmentUpload] -> ShowS
$cshowList :: [CompleteAttachmentUpload] -> ShowS
show :: CompleteAttachmentUpload -> String
$cshow :: CompleteAttachmentUpload -> String
showsPrec :: Int -> CompleteAttachmentUpload -> ShowS
$cshowsPrec :: Int -> CompleteAttachmentUpload -> ShowS
Prelude.Show, (forall x.
 CompleteAttachmentUpload -> Rep CompleteAttachmentUpload x)
-> (forall x.
    Rep CompleteAttachmentUpload x -> CompleteAttachmentUpload)
-> Generic CompleteAttachmentUpload
forall x.
Rep CompleteAttachmentUpload x -> CompleteAttachmentUpload
forall x.
CompleteAttachmentUpload -> Rep CompleteAttachmentUpload x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CompleteAttachmentUpload x -> CompleteAttachmentUpload
$cfrom :: forall x.
CompleteAttachmentUpload -> Rep CompleteAttachmentUpload x
Prelude.Generic)

-- |
-- Create a value of 'CompleteAttachmentUpload' 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:
--
-- 'attachmentIds', 'completeAttachmentUpload_attachmentIds' - A list of unique identifiers for the attachments.
--
-- 'clientToken', 'completeAttachmentUpload_clientToken' - A unique, case-sensitive identifier that you provide to ensure the
-- idempotency of the request.
--
-- 'connectionToken', 'completeAttachmentUpload_connectionToken' - The authentication token associated with the participant\'s connection.
newCompleteAttachmentUpload ::
  -- | 'attachmentIds'
  Prelude.NonEmpty Prelude.Text ->
  -- | 'clientToken'
  Prelude.Text ->
  -- | 'connectionToken'
  Prelude.Text ->
  CompleteAttachmentUpload
newCompleteAttachmentUpload :: NonEmpty Text -> Text -> Text -> CompleteAttachmentUpload
newCompleteAttachmentUpload
  NonEmpty Text
pAttachmentIds_
  Text
pClientToken_
  Text
pConnectionToken_ =
    CompleteAttachmentUpload' :: NonEmpty Text -> Text -> Text -> CompleteAttachmentUpload
CompleteAttachmentUpload'
      { $sel:attachmentIds:CompleteAttachmentUpload' :: NonEmpty Text
attachmentIds =
          Tagged (NonEmpty Text) (Identity (NonEmpty Text))
-> Tagged (NonEmpty Text) (Identity (NonEmpty Text))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Text) (Identity (NonEmpty Text))
 -> Tagged (NonEmpty Text) (Identity (NonEmpty Text)))
-> NonEmpty Text -> NonEmpty Text
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pAttachmentIds_,
        $sel:clientToken:CompleteAttachmentUpload' :: Text
clientToken = Text
pClientToken_,
        $sel:connectionToken:CompleteAttachmentUpload' :: Text
connectionToken = Text
pConnectionToken_
      }

-- | A list of unique identifiers for the attachments.
completeAttachmentUpload_attachmentIds :: Lens.Lens' CompleteAttachmentUpload (Prelude.NonEmpty Prelude.Text)
completeAttachmentUpload_attachmentIds :: (NonEmpty Text -> f (NonEmpty Text))
-> CompleteAttachmentUpload -> f CompleteAttachmentUpload
completeAttachmentUpload_attachmentIds = (CompleteAttachmentUpload -> NonEmpty Text)
-> (CompleteAttachmentUpload
    -> NonEmpty Text -> CompleteAttachmentUpload)
-> Lens
     CompleteAttachmentUpload
     CompleteAttachmentUpload
     (NonEmpty Text)
     (NonEmpty Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CompleteAttachmentUpload' {NonEmpty Text
attachmentIds :: NonEmpty Text
$sel:attachmentIds:CompleteAttachmentUpload' :: CompleteAttachmentUpload -> NonEmpty Text
attachmentIds} -> NonEmpty Text
attachmentIds) (\s :: CompleteAttachmentUpload
s@CompleteAttachmentUpload' {} NonEmpty Text
a -> CompleteAttachmentUpload
s {$sel:attachmentIds:CompleteAttachmentUpload' :: NonEmpty Text
attachmentIds = NonEmpty Text
a} :: CompleteAttachmentUpload) ((NonEmpty Text -> f (NonEmpty Text))
 -> CompleteAttachmentUpload -> f CompleteAttachmentUpload)
-> ((NonEmpty Text -> f (NonEmpty Text))
    -> NonEmpty Text -> f (NonEmpty Text))
-> (NonEmpty Text -> f (NonEmpty Text))
-> CompleteAttachmentUpload
-> f CompleteAttachmentUpload
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Text -> f (NonEmpty Text))
-> NonEmpty Text -> f (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A unique, case-sensitive identifier that you provide to ensure the
-- idempotency of the request.
completeAttachmentUpload_clientToken :: Lens.Lens' CompleteAttachmentUpload Prelude.Text
completeAttachmentUpload_clientToken :: (Text -> f Text)
-> CompleteAttachmentUpload -> f CompleteAttachmentUpload
completeAttachmentUpload_clientToken = (CompleteAttachmentUpload -> Text)
-> (CompleteAttachmentUpload -> Text -> CompleteAttachmentUpload)
-> Lens CompleteAttachmentUpload CompleteAttachmentUpload Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CompleteAttachmentUpload' {Text
clientToken :: Text
$sel:clientToken:CompleteAttachmentUpload' :: CompleteAttachmentUpload -> Text
clientToken} -> Text
clientToken) (\s :: CompleteAttachmentUpload
s@CompleteAttachmentUpload' {} Text
a -> CompleteAttachmentUpload
s {$sel:clientToken:CompleteAttachmentUpload' :: Text
clientToken = Text
a} :: CompleteAttachmentUpload)

-- | The authentication token associated with the participant\'s connection.
completeAttachmentUpload_connectionToken :: Lens.Lens' CompleteAttachmentUpload Prelude.Text
completeAttachmentUpload_connectionToken :: (Text -> f Text)
-> CompleteAttachmentUpload -> f CompleteAttachmentUpload
completeAttachmentUpload_connectionToken = (CompleteAttachmentUpload -> Text)
-> (CompleteAttachmentUpload -> Text -> CompleteAttachmentUpload)
-> Lens CompleteAttachmentUpload CompleteAttachmentUpload Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CompleteAttachmentUpload' {Text
connectionToken :: Text
$sel:connectionToken:CompleteAttachmentUpload' :: CompleteAttachmentUpload -> Text
connectionToken} -> Text
connectionToken) (\s :: CompleteAttachmentUpload
s@CompleteAttachmentUpload' {} Text
a -> CompleteAttachmentUpload
s {$sel:connectionToken:CompleteAttachmentUpload' :: Text
connectionToken = Text
a} :: CompleteAttachmentUpload)

instance Core.AWSRequest CompleteAttachmentUpload where
  type
    AWSResponse CompleteAttachmentUpload =
      CompleteAttachmentUploadResponse
  request :: CompleteAttachmentUpload -> Request CompleteAttachmentUpload
request = Service
-> CompleteAttachmentUpload -> Request CompleteAttachmentUpload
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CompleteAttachmentUpload
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CompleteAttachmentUpload)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse CompleteAttachmentUpload))
-> Logger
-> Service
-> Proxy CompleteAttachmentUpload
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CompleteAttachmentUpload)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> CompleteAttachmentUploadResponse
CompleteAttachmentUploadResponse'
            (Int -> CompleteAttachmentUploadResponse)
-> Either String Int
-> Either String CompleteAttachmentUploadResponse
forall (f :: * -> *) a b. Functor 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 CompleteAttachmentUpload

instance Prelude.NFData CompleteAttachmentUpload

instance Core.ToHeaders CompleteAttachmentUpload where
  toHeaders :: CompleteAttachmentUpload -> ResponseHeaders
toHeaders CompleteAttachmentUpload' {NonEmpty Text
Text
connectionToken :: Text
clientToken :: Text
attachmentIds :: NonEmpty Text
$sel:connectionToken:CompleteAttachmentUpload' :: CompleteAttachmentUpload -> Text
$sel:clientToken:CompleteAttachmentUpload' :: CompleteAttachmentUpload -> Text
$sel:attachmentIds:CompleteAttachmentUpload' :: CompleteAttachmentUpload -> NonEmpty Text
..} =
    [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ HeaderName
"X-Amz-Bearer" HeaderName -> Text -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# Text
connectionToken,
        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 CompleteAttachmentUpload where
  toJSON :: CompleteAttachmentUpload -> Value
toJSON CompleteAttachmentUpload' {NonEmpty Text
Text
connectionToken :: Text
clientToken :: Text
attachmentIds :: NonEmpty Text
$sel:connectionToken:CompleteAttachmentUpload' :: CompleteAttachmentUpload -> Text
$sel:clientToken:CompleteAttachmentUpload' :: CompleteAttachmentUpload -> Text
$sel:attachmentIds:CompleteAttachmentUpload' :: CompleteAttachmentUpload -> NonEmpty 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
"AttachmentIds" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Text
attachmentIds),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ClientToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
clientToken)
          ]
      )

instance Core.ToPath CompleteAttachmentUpload where
  toPath :: CompleteAttachmentUpload -> ByteString
toPath =
    ByteString -> CompleteAttachmentUpload -> ByteString
forall a b. a -> b -> a
Prelude.const
      ByteString
"/participant/complete-attachment-upload"

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

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

-- |
-- Create a value of 'CompleteAttachmentUploadResponse' 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:
--
-- 'httpStatus', 'completeAttachmentUploadResponse_httpStatus' - The response's http status code.
newCompleteAttachmentUploadResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CompleteAttachmentUploadResponse
newCompleteAttachmentUploadResponse :: Int -> CompleteAttachmentUploadResponse
newCompleteAttachmentUploadResponse Int
pHttpStatus_ =
  CompleteAttachmentUploadResponse' :: Int -> CompleteAttachmentUploadResponse
CompleteAttachmentUploadResponse'
    { $sel:httpStatus:CompleteAttachmentUploadResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance
  Prelude.NFData
    CompleteAttachmentUploadResponse