{-# 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.ChimeSDKMessaging.AssociateChannelFlow
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Associates a channel flow with a channel. Once associated, all messages
-- to that channel go through channel flow processors. To stop processing,
-- use the @DisassociateChannelFlow@ API.
--
-- Only administrators or channel moderators can associate a channel flow.
-- The @x-amz-chime-bearer@ request header is mandatory. Use the
-- @AppInstanceUserArn@ of the user that makes the API call as the value in
-- the header.
module Amazonka.ChimeSDKMessaging.AssociateChannelFlow
  ( -- * Creating a Request
    AssociateChannelFlow (..),
    newAssociateChannelFlow,

    -- * Request Lenses
    associateChannelFlow_channelArn,
    associateChannelFlow_channelFlowArn,
    associateChannelFlow_chimeBearer,

    -- * Destructuring the Response
    AssociateChannelFlowResponse (..),
    newAssociateChannelFlowResponse,
  )
where

import Amazonka.ChimeSDKMessaging.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:/ 'newAssociateChannelFlow' smart constructor.
data AssociateChannelFlow = AssociateChannelFlow'
  { -- | The ARN of the channel.
    AssociateChannelFlow -> Text
channelArn :: Prelude.Text,
    -- | The ARN of the channel flow.
    AssociateChannelFlow -> Text
channelFlowArn :: Prelude.Text,
    -- | The @AppInstanceUserArn@ of the user making the API call.
    AssociateChannelFlow -> Text
chimeBearer :: Prelude.Text
  }
  deriving (AssociateChannelFlow -> AssociateChannelFlow -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateChannelFlow -> AssociateChannelFlow -> Bool
$c/= :: AssociateChannelFlow -> AssociateChannelFlow -> Bool
== :: AssociateChannelFlow -> AssociateChannelFlow -> Bool
$c== :: AssociateChannelFlow -> AssociateChannelFlow -> Bool
Prelude.Eq, ReadPrec [AssociateChannelFlow]
ReadPrec AssociateChannelFlow
Int -> ReadS AssociateChannelFlow
ReadS [AssociateChannelFlow]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateChannelFlow]
$creadListPrec :: ReadPrec [AssociateChannelFlow]
readPrec :: ReadPrec AssociateChannelFlow
$creadPrec :: ReadPrec AssociateChannelFlow
readList :: ReadS [AssociateChannelFlow]
$creadList :: ReadS [AssociateChannelFlow]
readsPrec :: Int -> ReadS AssociateChannelFlow
$creadsPrec :: Int -> ReadS AssociateChannelFlow
Prelude.Read, Int -> AssociateChannelFlow -> ShowS
[AssociateChannelFlow] -> ShowS
AssociateChannelFlow -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateChannelFlow] -> ShowS
$cshowList :: [AssociateChannelFlow] -> ShowS
show :: AssociateChannelFlow -> String
$cshow :: AssociateChannelFlow -> String
showsPrec :: Int -> AssociateChannelFlow -> ShowS
$cshowsPrec :: Int -> AssociateChannelFlow -> ShowS
Prelude.Show, forall x. Rep AssociateChannelFlow x -> AssociateChannelFlow
forall x. AssociateChannelFlow -> Rep AssociateChannelFlow x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssociateChannelFlow x -> AssociateChannelFlow
$cfrom :: forall x. AssociateChannelFlow -> Rep AssociateChannelFlow x
Prelude.Generic)

-- |
-- Create a value of 'AssociateChannelFlow' 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:
--
-- 'channelArn', 'associateChannelFlow_channelArn' - The ARN of the channel.
--
-- 'channelFlowArn', 'associateChannelFlow_channelFlowArn' - The ARN of the channel flow.
--
-- 'chimeBearer', 'associateChannelFlow_chimeBearer' - The @AppInstanceUserArn@ of the user making the API call.
newAssociateChannelFlow ::
  -- | 'channelArn'
  Prelude.Text ->
  -- | 'channelFlowArn'
  Prelude.Text ->
  -- | 'chimeBearer'
  Prelude.Text ->
  AssociateChannelFlow
newAssociateChannelFlow :: Text -> Text -> Text -> AssociateChannelFlow
newAssociateChannelFlow
  Text
pChannelArn_
  Text
pChannelFlowArn_
  Text
pChimeBearer_ =
    AssociateChannelFlow'
      { $sel:channelArn:AssociateChannelFlow' :: Text
channelArn = Text
pChannelArn_,
        $sel:channelFlowArn:AssociateChannelFlow' :: Text
channelFlowArn = Text
pChannelFlowArn_,
        $sel:chimeBearer:AssociateChannelFlow' :: Text
chimeBearer = Text
pChimeBearer_
      }

-- | The ARN of the channel.
associateChannelFlow_channelArn :: Lens.Lens' AssociateChannelFlow Prelude.Text
associateChannelFlow_channelArn :: Lens' AssociateChannelFlow Text
associateChannelFlow_channelArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateChannelFlow' {Text
channelArn :: Text
$sel:channelArn:AssociateChannelFlow' :: AssociateChannelFlow -> Text
channelArn} -> Text
channelArn) (\s :: AssociateChannelFlow
s@AssociateChannelFlow' {} Text
a -> AssociateChannelFlow
s {$sel:channelArn:AssociateChannelFlow' :: Text
channelArn = Text
a} :: AssociateChannelFlow)

-- | The ARN of the channel flow.
associateChannelFlow_channelFlowArn :: Lens.Lens' AssociateChannelFlow Prelude.Text
associateChannelFlow_channelFlowArn :: Lens' AssociateChannelFlow Text
associateChannelFlow_channelFlowArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateChannelFlow' {Text
channelFlowArn :: Text
$sel:channelFlowArn:AssociateChannelFlow' :: AssociateChannelFlow -> Text
channelFlowArn} -> Text
channelFlowArn) (\s :: AssociateChannelFlow
s@AssociateChannelFlow' {} Text
a -> AssociateChannelFlow
s {$sel:channelFlowArn:AssociateChannelFlow' :: Text
channelFlowArn = Text
a} :: AssociateChannelFlow)

-- | The @AppInstanceUserArn@ of the user making the API call.
associateChannelFlow_chimeBearer :: Lens.Lens' AssociateChannelFlow Prelude.Text
associateChannelFlow_chimeBearer :: Lens' AssociateChannelFlow Text
associateChannelFlow_chimeBearer = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateChannelFlow' {Text
chimeBearer :: Text
$sel:chimeBearer:AssociateChannelFlow' :: AssociateChannelFlow -> Text
chimeBearer} -> Text
chimeBearer) (\s :: AssociateChannelFlow
s@AssociateChannelFlow' {} Text
a -> AssociateChannelFlow
s {$sel:chimeBearer:AssociateChannelFlow' :: Text
chimeBearer = Text
a} :: AssociateChannelFlow)

instance Core.AWSRequest AssociateChannelFlow where
  type
    AWSResponse AssociateChannelFlow =
      AssociateChannelFlowResponse
  request :: (Service -> Service)
-> AssociateChannelFlow -> Request AssociateChannelFlow
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy AssociateChannelFlow
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AssociateChannelFlow)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AssociateChannelFlowResponse
AssociateChannelFlowResponse'

instance Prelude.Hashable AssociateChannelFlow where
  hashWithSalt :: Int -> AssociateChannelFlow -> Int
hashWithSalt Int
_salt AssociateChannelFlow' {Text
chimeBearer :: Text
channelFlowArn :: Text
channelArn :: Text
$sel:chimeBearer:AssociateChannelFlow' :: AssociateChannelFlow -> Text
$sel:channelFlowArn:AssociateChannelFlow' :: AssociateChannelFlow -> Text
$sel:channelArn:AssociateChannelFlow' :: AssociateChannelFlow -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
channelArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
channelFlowArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
chimeBearer

instance Prelude.NFData AssociateChannelFlow where
  rnf :: AssociateChannelFlow -> ()
rnf AssociateChannelFlow' {Text
chimeBearer :: Text
channelFlowArn :: Text
channelArn :: Text
$sel:chimeBearer:AssociateChannelFlow' :: AssociateChannelFlow -> Text
$sel:channelFlowArn:AssociateChannelFlow' :: AssociateChannelFlow -> Text
$sel:channelArn:AssociateChannelFlow' :: AssociateChannelFlow -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
channelArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
channelFlowArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
chimeBearer

instance Data.ToHeaders AssociateChannelFlow where
  toHeaders :: AssociateChannelFlow -> [Header]
toHeaders AssociateChannelFlow' {Text
chimeBearer :: Text
channelFlowArn :: Text
channelArn :: Text
$sel:chimeBearer:AssociateChannelFlow' :: AssociateChannelFlow -> Text
$sel:channelFlowArn:AssociateChannelFlow' :: AssociateChannelFlow -> Text
$sel:channelArn:AssociateChannelFlow' :: AssociateChannelFlow -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [HeaderName
"x-amz-chime-bearer" forall a. ToHeader a => HeaderName -> a -> [Header]
Data.=# Text
chimeBearer]

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

instance Data.ToPath AssociateChannelFlow where
  toPath :: AssociateChannelFlow -> ByteString
toPath AssociateChannelFlow' {Text
chimeBearer :: Text
channelFlowArn :: Text
channelArn :: Text
$sel:chimeBearer:AssociateChannelFlow' :: AssociateChannelFlow -> Text
$sel:channelFlowArn:AssociateChannelFlow' :: AssociateChannelFlow -> Text
$sel:channelArn:AssociateChannelFlow' :: AssociateChannelFlow -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/channels/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
channelArn, ByteString
"/channel-flow"]

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

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

-- |
-- Create a value of 'AssociateChannelFlowResponse' 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.
newAssociateChannelFlowResponse ::
  AssociateChannelFlowResponse
newAssociateChannelFlowResponse :: AssociateChannelFlowResponse
newAssociateChannelFlowResponse =
  AssociateChannelFlowResponse
AssociateChannelFlowResponse'

instance Prelude.NFData AssociateChannelFlowResponse where
  rnf :: AssociateChannelFlowResponse -> ()
rnf AssociateChannelFlowResponse
_ = ()