{-# 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.S3.GetBucketRequestPayment
-- 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 request payment configuration of a bucket. To use this
-- version of the operation, you must be the bucket owner. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/RequesterPaysBuckets.html Requester Pays Buckets>.
--
-- The following operations are related to @GetBucketRequestPayment@:
--
-- -   <https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjects.html ListObjects>
module Amazonka.S3.GetBucketRequestPayment
  ( -- * Creating a Request
    GetBucketRequestPayment (..),
    newGetBucketRequestPayment,

    -- * Request Lenses
    getBucketRequestPayment_expectedBucketOwner,
    getBucketRequestPayment_bucket,

    -- * Destructuring the Response
    GetBucketRequestPaymentResponse (..),
    newGetBucketRequestPaymentResponse,

    -- * Response Lenses
    getBucketRequestPaymentResponse_payer,
    getBucketRequestPaymentResponse_httpStatus,
  )
where

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
import Amazonka.S3.Types

-- | /See:/ 'newGetBucketRequestPayment' smart constructor.
data GetBucketRequestPayment = GetBucketRequestPayment'
  { -- | The account ID of the expected bucket owner. If the bucket is owned by a
    -- different account, the request will fail with an HTTP
    -- @403 (Access Denied)@ error.
    GetBucketRequestPayment -> Maybe Text
expectedBucketOwner :: Prelude.Maybe Prelude.Text,
    -- | The name of the bucket for which to get the payment request
    -- configuration
    GetBucketRequestPayment -> BucketName
bucket :: BucketName
  }
  deriving (GetBucketRequestPayment -> GetBucketRequestPayment -> Bool
(GetBucketRequestPayment -> GetBucketRequestPayment -> Bool)
-> (GetBucketRequestPayment -> GetBucketRequestPayment -> Bool)
-> Eq GetBucketRequestPayment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetBucketRequestPayment -> GetBucketRequestPayment -> Bool
$c/= :: GetBucketRequestPayment -> GetBucketRequestPayment -> Bool
== :: GetBucketRequestPayment -> GetBucketRequestPayment -> Bool
$c== :: GetBucketRequestPayment -> GetBucketRequestPayment -> Bool
Prelude.Eq, ReadPrec [GetBucketRequestPayment]
ReadPrec GetBucketRequestPayment
Int -> ReadS GetBucketRequestPayment
ReadS [GetBucketRequestPayment]
(Int -> ReadS GetBucketRequestPayment)
-> ReadS [GetBucketRequestPayment]
-> ReadPrec GetBucketRequestPayment
-> ReadPrec [GetBucketRequestPayment]
-> Read GetBucketRequestPayment
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetBucketRequestPayment]
$creadListPrec :: ReadPrec [GetBucketRequestPayment]
readPrec :: ReadPrec GetBucketRequestPayment
$creadPrec :: ReadPrec GetBucketRequestPayment
readList :: ReadS [GetBucketRequestPayment]
$creadList :: ReadS [GetBucketRequestPayment]
readsPrec :: Int -> ReadS GetBucketRequestPayment
$creadsPrec :: Int -> ReadS GetBucketRequestPayment
Prelude.Read, Int -> GetBucketRequestPayment -> ShowS
[GetBucketRequestPayment] -> ShowS
GetBucketRequestPayment -> String
(Int -> GetBucketRequestPayment -> ShowS)
-> (GetBucketRequestPayment -> String)
-> ([GetBucketRequestPayment] -> ShowS)
-> Show GetBucketRequestPayment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetBucketRequestPayment] -> ShowS
$cshowList :: [GetBucketRequestPayment] -> ShowS
show :: GetBucketRequestPayment -> String
$cshow :: GetBucketRequestPayment -> String
showsPrec :: Int -> GetBucketRequestPayment -> ShowS
$cshowsPrec :: Int -> GetBucketRequestPayment -> ShowS
Prelude.Show, (forall x.
 GetBucketRequestPayment -> Rep GetBucketRequestPayment x)
-> (forall x.
    Rep GetBucketRequestPayment x -> GetBucketRequestPayment)
-> Generic GetBucketRequestPayment
forall x. Rep GetBucketRequestPayment x -> GetBucketRequestPayment
forall x. GetBucketRequestPayment -> Rep GetBucketRequestPayment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetBucketRequestPayment x -> GetBucketRequestPayment
$cfrom :: forall x. GetBucketRequestPayment -> Rep GetBucketRequestPayment x
Prelude.Generic)

-- |
-- Create a value of 'GetBucketRequestPayment' 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:
--
-- 'expectedBucketOwner', 'getBucketRequestPayment_expectedBucketOwner' - The account ID of the expected bucket owner. If the bucket is owned by a
-- different account, the request will fail with an HTTP
-- @403 (Access Denied)@ error.
--
-- 'bucket', 'getBucketRequestPayment_bucket' - The name of the bucket for which to get the payment request
-- configuration
newGetBucketRequestPayment ::
  -- | 'bucket'
  BucketName ->
  GetBucketRequestPayment
newGetBucketRequestPayment :: BucketName -> GetBucketRequestPayment
newGetBucketRequestPayment BucketName
pBucket_ =
  GetBucketRequestPayment' :: Maybe Text -> BucketName -> GetBucketRequestPayment
GetBucketRequestPayment'
    { $sel:expectedBucketOwner:GetBucketRequestPayment' :: Maybe Text
expectedBucketOwner =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:bucket:GetBucketRequestPayment' :: BucketName
bucket = BucketName
pBucket_
    }

-- | The account ID of the expected bucket owner. If the bucket is owned by a
-- different account, the request will fail with an HTTP
-- @403 (Access Denied)@ error.
getBucketRequestPayment_expectedBucketOwner :: Lens.Lens' GetBucketRequestPayment (Prelude.Maybe Prelude.Text)
getBucketRequestPayment_expectedBucketOwner :: (Maybe Text -> f (Maybe Text))
-> GetBucketRequestPayment -> f GetBucketRequestPayment
getBucketRequestPayment_expectedBucketOwner = (GetBucketRequestPayment -> Maybe Text)
-> (GetBucketRequestPayment
    -> Maybe Text -> GetBucketRequestPayment)
-> Lens
     GetBucketRequestPayment
     GetBucketRequestPayment
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketRequestPayment' {Maybe Text
expectedBucketOwner :: Maybe Text
$sel:expectedBucketOwner:GetBucketRequestPayment' :: GetBucketRequestPayment -> Maybe Text
expectedBucketOwner} -> Maybe Text
expectedBucketOwner) (\s :: GetBucketRequestPayment
s@GetBucketRequestPayment' {} Maybe Text
a -> GetBucketRequestPayment
s {$sel:expectedBucketOwner:GetBucketRequestPayment' :: Maybe Text
expectedBucketOwner = Maybe Text
a} :: GetBucketRequestPayment)

-- | The name of the bucket for which to get the payment request
-- configuration
getBucketRequestPayment_bucket :: Lens.Lens' GetBucketRequestPayment BucketName
getBucketRequestPayment_bucket :: (BucketName -> f BucketName)
-> GetBucketRequestPayment -> f GetBucketRequestPayment
getBucketRequestPayment_bucket = (GetBucketRequestPayment -> BucketName)
-> (GetBucketRequestPayment
    -> BucketName -> GetBucketRequestPayment)
-> Lens
     GetBucketRequestPayment
     GetBucketRequestPayment
     BucketName
     BucketName
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketRequestPayment' {BucketName
bucket :: BucketName
$sel:bucket:GetBucketRequestPayment' :: GetBucketRequestPayment -> BucketName
bucket} -> BucketName
bucket) (\s :: GetBucketRequestPayment
s@GetBucketRequestPayment' {} BucketName
a -> GetBucketRequestPayment
s {$sel:bucket:GetBucketRequestPayment' :: BucketName
bucket = BucketName
a} :: GetBucketRequestPayment)

instance Core.AWSRequest GetBucketRequestPayment where
  type
    AWSResponse GetBucketRequestPayment =
      GetBucketRequestPaymentResponse
  request :: GetBucketRequestPayment -> Request GetBucketRequestPayment
request =
    Request GetBucketRequestPayment -> Request GetBucketRequestPayment
forall a. Request a -> Request a
Request.s3vhost
      (Request GetBucketRequestPayment
 -> Request GetBucketRequestPayment)
-> (GetBucketRequestPayment -> Request GetBucketRequestPayment)
-> GetBucketRequestPayment
-> Request GetBucketRequestPayment
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. Service
-> GetBucketRequestPayment -> Request GetBucketRequestPayment
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetBucketRequestPayment
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetBucketRequestPayment)))
response =
    (Int
 -> ResponseHeaders
 -> [Node]
 -> Either String (AWSResponse GetBucketRequestPayment))
-> Logger
-> Service
-> Proxy GetBucketRequestPayment
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetBucketRequestPayment)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXML
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe Payer -> Int -> GetBucketRequestPaymentResponse
GetBucketRequestPaymentResponse'
            (Maybe Payer -> Int -> GetBucketRequestPaymentResponse)
-> Either String (Maybe Payer)
-> Either String (Int -> GetBucketRequestPaymentResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Payer)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Payer")
            Either String (Int -> GetBucketRequestPaymentResponse)
-> Either String Int
-> Either String GetBucketRequestPaymentResponse
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 GetBucketRequestPayment

instance Prelude.NFData GetBucketRequestPayment

instance Core.ToHeaders GetBucketRequestPayment where
  toHeaders :: GetBucketRequestPayment -> ResponseHeaders
toHeaders GetBucketRequestPayment' {Maybe Text
BucketName
bucket :: BucketName
expectedBucketOwner :: Maybe Text
$sel:bucket:GetBucketRequestPayment' :: GetBucketRequestPayment -> BucketName
$sel:expectedBucketOwner:GetBucketRequestPayment' :: GetBucketRequestPayment -> Maybe Text
..} =
    [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ HeaderName
"x-amz-expected-bucket-owner"
          HeaderName -> Maybe Text -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# Maybe Text
expectedBucketOwner
      ]

instance Core.ToPath GetBucketRequestPayment where
  toPath :: GetBucketRequestPayment -> ByteString
toPath GetBucketRequestPayment' {Maybe Text
BucketName
bucket :: BucketName
expectedBucketOwner :: Maybe Text
$sel:bucket:GetBucketRequestPayment' :: GetBucketRequestPayment -> BucketName
$sel:expectedBucketOwner:GetBucketRequestPayment' :: GetBucketRequestPayment -> Maybe Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"/", BucketName -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS BucketName
bucket]

instance Core.ToQuery GetBucketRequestPayment where
  toQuery :: GetBucketRequestPayment -> QueryString
toQuery =
    QueryString -> GetBucketRequestPayment -> QueryString
forall a b. a -> b -> a
Prelude.const ([QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat [QueryString
"requestPayment"])

-- | /See:/ 'newGetBucketRequestPaymentResponse' smart constructor.
data GetBucketRequestPaymentResponse = GetBucketRequestPaymentResponse'
  { -- | Specifies who pays for the download and request fees.
    GetBucketRequestPaymentResponse -> Maybe Payer
payer :: Prelude.Maybe Payer,
    -- | The response's http status code.
    GetBucketRequestPaymentResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetBucketRequestPaymentResponse
-> GetBucketRequestPaymentResponse -> Bool
(GetBucketRequestPaymentResponse
 -> GetBucketRequestPaymentResponse -> Bool)
-> (GetBucketRequestPaymentResponse
    -> GetBucketRequestPaymentResponse -> Bool)
-> Eq GetBucketRequestPaymentResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetBucketRequestPaymentResponse
-> GetBucketRequestPaymentResponse -> Bool
$c/= :: GetBucketRequestPaymentResponse
-> GetBucketRequestPaymentResponse -> Bool
== :: GetBucketRequestPaymentResponse
-> GetBucketRequestPaymentResponse -> Bool
$c== :: GetBucketRequestPaymentResponse
-> GetBucketRequestPaymentResponse -> Bool
Prelude.Eq, ReadPrec [GetBucketRequestPaymentResponse]
ReadPrec GetBucketRequestPaymentResponse
Int -> ReadS GetBucketRequestPaymentResponse
ReadS [GetBucketRequestPaymentResponse]
(Int -> ReadS GetBucketRequestPaymentResponse)
-> ReadS [GetBucketRequestPaymentResponse]
-> ReadPrec GetBucketRequestPaymentResponse
-> ReadPrec [GetBucketRequestPaymentResponse]
-> Read GetBucketRequestPaymentResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetBucketRequestPaymentResponse]
$creadListPrec :: ReadPrec [GetBucketRequestPaymentResponse]
readPrec :: ReadPrec GetBucketRequestPaymentResponse
$creadPrec :: ReadPrec GetBucketRequestPaymentResponse
readList :: ReadS [GetBucketRequestPaymentResponse]
$creadList :: ReadS [GetBucketRequestPaymentResponse]
readsPrec :: Int -> ReadS GetBucketRequestPaymentResponse
$creadsPrec :: Int -> ReadS GetBucketRequestPaymentResponse
Prelude.Read, Int -> GetBucketRequestPaymentResponse -> ShowS
[GetBucketRequestPaymentResponse] -> ShowS
GetBucketRequestPaymentResponse -> String
(Int -> GetBucketRequestPaymentResponse -> ShowS)
-> (GetBucketRequestPaymentResponse -> String)
-> ([GetBucketRequestPaymentResponse] -> ShowS)
-> Show GetBucketRequestPaymentResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetBucketRequestPaymentResponse] -> ShowS
$cshowList :: [GetBucketRequestPaymentResponse] -> ShowS
show :: GetBucketRequestPaymentResponse -> String
$cshow :: GetBucketRequestPaymentResponse -> String
showsPrec :: Int -> GetBucketRequestPaymentResponse -> ShowS
$cshowsPrec :: Int -> GetBucketRequestPaymentResponse -> ShowS
Prelude.Show, (forall x.
 GetBucketRequestPaymentResponse
 -> Rep GetBucketRequestPaymentResponse x)
-> (forall x.
    Rep GetBucketRequestPaymentResponse x
    -> GetBucketRequestPaymentResponse)
-> Generic GetBucketRequestPaymentResponse
forall x.
Rep GetBucketRequestPaymentResponse x
-> GetBucketRequestPaymentResponse
forall x.
GetBucketRequestPaymentResponse
-> Rep GetBucketRequestPaymentResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetBucketRequestPaymentResponse x
-> GetBucketRequestPaymentResponse
$cfrom :: forall x.
GetBucketRequestPaymentResponse
-> Rep GetBucketRequestPaymentResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetBucketRequestPaymentResponse' 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:
--
-- 'payer', 'getBucketRequestPaymentResponse_payer' - Specifies who pays for the download and request fees.
--
-- 'httpStatus', 'getBucketRequestPaymentResponse_httpStatus' - The response's http status code.
newGetBucketRequestPaymentResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetBucketRequestPaymentResponse
newGetBucketRequestPaymentResponse :: Int -> GetBucketRequestPaymentResponse
newGetBucketRequestPaymentResponse Int
pHttpStatus_ =
  GetBucketRequestPaymentResponse' :: Maybe Payer -> Int -> GetBucketRequestPaymentResponse
GetBucketRequestPaymentResponse'
    { $sel:payer:GetBucketRequestPaymentResponse' :: Maybe Payer
payer =
        Maybe Payer
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetBucketRequestPaymentResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Specifies who pays for the download and request fees.
getBucketRequestPaymentResponse_payer :: Lens.Lens' GetBucketRequestPaymentResponse (Prelude.Maybe Payer)
getBucketRequestPaymentResponse_payer :: (Maybe Payer -> f (Maybe Payer))
-> GetBucketRequestPaymentResponse
-> f GetBucketRequestPaymentResponse
getBucketRequestPaymentResponse_payer = (GetBucketRequestPaymentResponse -> Maybe Payer)
-> (GetBucketRequestPaymentResponse
    -> Maybe Payer -> GetBucketRequestPaymentResponse)
-> Lens
     GetBucketRequestPaymentResponse
     GetBucketRequestPaymentResponse
     (Maybe Payer)
     (Maybe Payer)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketRequestPaymentResponse' {Maybe Payer
payer :: Maybe Payer
$sel:payer:GetBucketRequestPaymentResponse' :: GetBucketRequestPaymentResponse -> Maybe Payer
payer} -> Maybe Payer
payer) (\s :: GetBucketRequestPaymentResponse
s@GetBucketRequestPaymentResponse' {} Maybe Payer
a -> GetBucketRequestPaymentResponse
s {$sel:payer:GetBucketRequestPaymentResponse' :: Maybe Payer
payer = Maybe Payer
a} :: GetBucketRequestPaymentResponse)

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

instance
  Prelude.NFData
    GetBucketRequestPaymentResponse