{-# 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.Redshift.AssociateDataShareConsumer
-- 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)
--
-- From a datashare consumer account, associates a datashare with the
-- account (AssociateEntireAccount) or the specified namespace
-- (ConsumerArn). If you make this association, the consumer can consume
-- the datashare.
module Amazonka.Redshift.AssociateDataShareConsumer
  ( -- * Creating a Request
    AssociateDataShareConsumer (..),
    newAssociateDataShareConsumer,

    -- * Request Lenses
    associateDataShareConsumer_associateEntireAccount,
    associateDataShareConsumer_consumerArn,
    associateDataShareConsumer_dataShareArn,

    -- * Destructuring the Response
    DataShare (..),
    newDataShare,

    -- * Response Lenses
    dataShare_producerArn,
    dataShare_dataShareAssociations,
    dataShare_dataShareArn,
    dataShare_allowPubliclyAccessibleConsumers,
  )
where

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

-- | /See:/ 'newAssociateDataShareConsumer' smart constructor.
data AssociateDataShareConsumer = AssociateDataShareConsumer'
  { -- | A value that specifies whether the datashare is associated with the
    -- entire account.
    AssociateDataShareConsumer -> Maybe Bool
associateEntireAccount :: Prelude.Maybe Prelude.Bool,
    -- | The Amazon Resource Name (ARN) of the consumer that is associated with
    -- the datashare.
    AssociateDataShareConsumer -> Maybe Text
consumerArn :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the datashare that the consumer is to
    -- use with the account or the namespace.
    AssociateDataShareConsumer -> Text
dataShareArn :: Prelude.Text
  }
  deriving (AssociateDataShareConsumer -> AssociateDataShareConsumer -> Bool
(AssociateDataShareConsumer -> AssociateDataShareConsumer -> Bool)
-> (AssociateDataShareConsumer
    -> AssociateDataShareConsumer -> Bool)
-> Eq AssociateDataShareConsumer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateDataShareConsumer -> AssociateDataShareConsumer -> Bool
$c/= :: AssociateDataShareConsumer -> AssociateDataShareConsumer -> Bool
== :: AssociateDataShareConsumer -> AssociateDataShareConsumer -> Bool
$c== :: AssociateDataShareConsumer -> AssociateDataShareConsumer -> Bool
Prelude.Eq, ReadPrec [AssociateDataShareConsumer]
ReadPrec AssociateDataShareConsumer
Int -> ReadS AssociateDataShareConsumer
ReadS [AssociateDataShareConsumer]
(Int -> ReadS AssociateDataShareConsumer)
-> ReadS [AssociateDataShareConsumer]
-> ReadPrec AssociateDataShareConsumer
-> ReadPrec [AssociateDataShareConsumer]
-> Read AssociateDataShareConsumer
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateDataShareConsumer]
$creadListPrec :: ReadPrec [AssociateDataShareConsumer]
readPrec :: ReadPrec AssociateDataShareConsumer
$creadPrec :: ReadPrec AssociateDataShareConsumer
readList :: ReadS [AssociateDataShareConsumer]
$creadList :: ReadS [AssociateDataShareConsumer]
readsPrec :: Int -> ReadS AssociateDataShareConsumer
$creadsPrec :: Int -> ReadS AssociateDataShareConsumer
Prelude.Read, Int -> AssociateDataShareConsumer -> ShowS
[AssociateDataShareConsumer] -> ShowS
AssociateDataShareConsumer -> String
(Int -> AssociateDataShareConsumer -> ShowS)
-> (AssociateDataShareConsumer -> String)
-> ([AssociateDataShareConsumer] -> ShowS)
-> Show AssociateDataShareConsumer
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateDataShareConsumer] -> ShowS
$cshowList :: [AssociateDataShareConsumer] -> ShowS
show :: AssociateDataShareConsumer -> String
$cshow :: AssociateDataShareConsumer -> String
showsPrec :: Int -> AssociateDataShareConsumer -> ShowS
$cshowsPrec :: Int -> AssociateDataShareConsumer -> ShowS
Prelude.Show, (forall x.
 AssociateDataShareConsumer -> Rep AssociateDataShareConsumer x)
-> (forall x.
    Rep AssociateDataShareConsumer x -> AssociateDataShareConsumer)
-> Generic AssociateDataShareConsumer
forall x.
Rep AssociateDataShareConsumer x -> AssociateDataShareConsumer
forall x.
AssociateDataShareConsumer -> Rep AssociateDataShareConsumer x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AssociateDataShareConsumer x -> AssociateDataShareConsumer
$cfrom :: forall x.
AssociateDataShareConsumer -> Rep AssociateDataShareConsumer x
Prelude.Generic)

-- |
-- Create a value of 'AssociateDataShareConsumer' 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:
--
-- 'associateEntireAccount', 'associateDataShareConsumer_associateEntireAccount' - A value that specifies whether the datashare is associated with the
-- entire account.
--
-- 'consumerArn', 'associateDataShareConsumer_consumerArn' - The Amazon Resource Name (ARN) of the consumer that is associated with
-- the datashare.
--
-- 'dataShareArn', 'associateDataShareConsumer_dataShareArn' - The Amazon Resource Name (ARN) of the datashare that the consumer is to
-- use with the account or the namespace.
newAssociateDataShareConsumer ::
  -- | 'dataShareArn'
  Prelude.Text ->
  AssociateDataShareConsumer
newAssociateDataShareConsumer :: Text -> AssociateDataShareConsumer
newAssociateDataShareConsumer Text
pDataShareArn_ =
  AssociateDataShareConsumer' :: Maybe Bool -> Maybe Text -> Text -> AssociateDataShareConsumer
AssociateDataShareConsumer'
    { $sel:associateEntireAccount:AssociateDataShareConsumer' :: Maybe Bool
associateEntireAccount =
        Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:consumerArn:AssociateDataShareConsumer' :: Maybe Text
consumerArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:dataShareArn:AssociateDataShareConsumer' :: Text
dataShareArn = Text
pDataShareArn_
    }

-- | A value that specifies whether the datashare is associated with the
-- entire account.
associateDataShareConsumer_associateEntireAccount :: Lens.Lens' AssociateDataShareConsumer (Prelude.Maybe Prelude.Bool)
associateDataShareConsumer_associateEntireAccount :: (Maybe Bool -> f (Maybe Bool))
-> AssociateDataShareConsumer -> f AssociateDataShareConsumer
associateDataShareConsumer_associateEntireAccount = (AssociateDataShareConsumer -> Maybe Bool)
-> (AssociateDataShareConsumer
    -> Maybe Bool -> AssociateDataShareConsumer)
-> Lens
     AssociateDataShareConsumer
     AssociateDataShareConsumer
     (Maybe Bool)
     (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateDataShareConsumer' {Maybe Bool
associateEntireAccount :: Maybe Bool
$sel:associateEntireAccount:AssociateDataShareConsumer' :: AssociateDataShareConsumer -> Maybe Bool
associateEntireAccount} -> Maybe Bool
associateEntireAccount) (\s :: AssociateDataShareConsumer
s@AssociateDataShareConsumer' {} Maybe Bool
a -> AssociateDataShareConsumer
s {$sel:associateEntireAccount:AssociateDataShareConsumer' :: Maybe Bool
associateEntireAccount = Maybe Bool
a} :: AssociateDataShareConsumer)

-- | The Amazon Resource Name (ARN) of the consumer that is associated with
-- the datashare.
associateDataShareConsumer_consumerArn :: Lens.Lens' AssociateDataShareConsumer (Prelude.Maybe Prelude.Text)
associateDataShareConsumer_consumerArn :: (Maybe Text -> f (Maybe Text))
-> AssociateDataShareConsumer -> f AssociateDataShareConsumer
associateDataShareConsumer_consumerArn = (AssociateDataShareConsumer -> Maybe Text)
-> (AssociateDataShareConsumer
    -> Maybe Text -> AssociateDataShareConsumer)
-> Lens
     AssociateDataShareConsumer
     AssociateDataShareConsumer
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateDataShareConsumer' {Maybe Text
consumerArn :: Maybe Text
$sel:consumerArn:AssociateDataShareConsumer' :: AssociateDataShareConsumer -> Maybe Text
consumerArn} -> Maybe Text
consumerArn) (\s :: AssociateDataShareConsumer
s@AssociateDataShareConsumer' {} Maybe Text
a -> AssociateDataShareConsumer
s {$sel:consumerArn:AssociateDataShareConsumer' :: Maybe Text
consumerArn = Maybe Text
a} :: AssociateDataShareConsumer)

-- | The Amazon Resource Name (ARN) of the datashare that the consumer is to
-- use with the account or the namespace.
associateDataShareConsumer_dataShareArn :: Lens.Lens' AssociateDataShareConsumer Prelude.Text
associateDataShareConsumer_dataShareArn :: (Text -> f Text)
-> AssociateDataShareConsumer -> f AssociateDataShareConsumer
associateDataShareConsumer_dataShareArn = (AssociateDataShareConsumer -> Text)
-> (AssociateDataShareConsumer
    -> Text -> AssociateDataShareConsumer)
-> Lens
     AssociateDataShareConsumer AssociateDataShareConsumer Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateDataShareConsumer' {Text
dataShareArn :: Text
$sel:dataShareArn:AssociateDataShareConsumer' :: AssociateDataShareConsumer -> Text
dataShareArn} -> Text
dataShareArn) (\s :: AssociateDataShareConsumer
s@AssociateDataShareConsumer' {} Text
a -> AssociateDataShareConsumer
s {$sel:dataShareArn:AssociateDataShareConsumer' :: Text
dataShareArn = Text
a} :: AssociateDataShareConsumer)

instance Core.AWSRequest AssociateDataShareConsumer where
  type
    AWSResponse AssociateDataShareConsumer =
      DataShare
  request :: AssociateDataShareConsumer -> Request AssociateDataShareConsumer
request = Service
-> AssociateDataShareConsumer -> Request AssociateDataShareConsumer
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy AssociateDataShareConsumer
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AssociateDataShareConsumer)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse AssociateDataShareConsumer))
-> Logger
-> Service
-> Proxy AssociateDataShareConsumer
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AssociateDataShareConsumer)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"AssociateDataShareConsumerResult"
      (\Int
s ResponseHeaders
h [Node]
x -> [Node] -> Either String DataShare
forall a. FromXML a => [Node] -> Either String a
Core.parseXML [Node]
x)

instance Prelude.Hashable AssociateDataShareConsumer

instance Prelude.NFData AssociateDataShareConsumer

instance Core.ToHeaders AssociateDataShareConsumer where
  toHeaders :: AssociateDataShareConsumer -> ResponseHeaders
toHeaders = ResponseHeaders -> AssociateDataShareConsumer -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

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

instance Core.ToQuery AssociateDataShareConsumer where
  toQuery :: AssociateDataShareConsumer -> QueryString
toQuery AssociateDataShareConsumer' {Maybe Bool
Maybe Text
Text
dataShareArn :: Text
consumerArn :: Maybe Text
associateEntireAccount :: Maybe Bool
$sel:dataShareArn:AssociateDataShareConsumer' :: AssociateDataShareConsumer -> Text
$sel:consumerArn:AssociateDataShareConsumer' :: AssociateDataShareConsumer -> Maybe Text
$sel:associateEntireAccount:AssociateDataShareConsumer' :: AssociateDataShareConsumer -> Maybe Bool
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"AssociateDataShareConsumer" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2012-12-01" :: Prelude.ByteString),
        ByteString
"AssociateEntireAccount"
          ByteString -> Maybe Bool -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Bool
associateEntireAccount,
        ByteString
"ConsumerArn" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
consumerArn,
        ByteString
"DataShareArn" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
dataShareArn
      ]