{-# 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.CognitoSync.SetCognitoEvents
-- 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)
--
-- Sets the AWS Lambda function for a given event type for an identity
-- pool. This request only updates the key\/value pair specified. Other
-- key\/values pairs are not updated. To remove a key value pair, pass a
-- empty value for the particular key.
--
-- This API can only be called with developer credentials. You cannot call
-- this API with the temporary user credentials provided by Cognito
-- Identity.
module Amazonka.CognitoSync.SetCognitoEvents
  ( -- * Creating a Request
    SetCognitoEvents (..),
    newSetCognitoEvents,

    -- * Request Lenses
    setCognitoEvents_identityPoolId,
    setCognitoEvents_events,

    -- * Destructuring the Response
    SetCognitoEventsResponse (..),
    newSetCognitoEventsResponse,
  )
where

import Amazonka.CognitoSync.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

-- | A request to configure Cognito Events\"
--
-- \"
--
-- /See:/ 'newSetCognitoEvents' smart constructor.
data SetCognitoEvents = SetCognitoEvents'
  { -- | The Cognito Identity Pool to use when configuring Cognito Events
    SetCognitoEvents -> Text
identityPoolId :: Prelude.Text,
    -- | The events to configure
    SetCognitoEvents -> HashMap Text Text
events :: Prelude.HashMap Prelude.Text Prelude.Text
  }
  deriving (SetCognitoEvents -> SetCognitoEvents -> Bool
(SetCognitoEvents -> SetCognitoEvents -> Bool)
-> (SetCognitoEvents -> SetCognitoEvents -> Bool)
-> Eq SetCognitoEvents
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SetCognitoEvents -> SetCognitoEvents -> Bool
$c/= :: SetCognitoEvents -> SetCognitoEvents -> Bool
== :: SetCognitoEvents -> SetCognitoEvents -> Bool
$c== :: SetCognitoEvents -> SetCognitoEvents -> Bool
Prelude.Eq, ReadPrec [SetCognitoEvents]
ReadPrec SetCognitoEvents
Int -> ReadS SetCognitoEvents
ReadS [SetCognitoEvents]
(Int -> ReadS SetCognitoEvents)
-> ReadS [SetCognitoEvents]
-> ReadPrec SetCognitoEvents
-> ReadPrec [SetCognitoEvents]
-> Read SetCognitoEvents
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SetCognitoEvents]
$creadListPrec :: ReadPrec [SetCognitoEvents]
readPrec :: ReadPrec SetCognitoEvents
$creadPrec :: ReadPrec SetCognitoEvents
readList :: ReadS [SetCognitoEvents]
$creadList :: ReadS [SetCognitoEvents]
readsPrec :: Int -> ReadS SetCognitoEvents
$creadsPrec :: Int -> ReadS SetCognitoEvents
Prelude.Read, Int -> SetCognitoEvents -> ShowS
[SetCognitoEvents] -> ShowS
SetCognitoEvents -> String
(Int -> SetCognitoEvents -> ShowS)
-> (SetCognitoEvents -> String)
-> ([SetCognitoEvents] -> ShowS)
-> Show SetCognitoEvents
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SetCognitoEvents] -> ShowS
$cshowList :: [SetCognitoEvents] -> ShowS
show :: SetCognitoEvents -> String
$cshow :: SetCognitoEvents -> String
showsPrec :: Int -> SetCognitoEvents -> ShowS
$cshowsPrec :: Int -> SetCognitoEvents -> ShowS
Prelude.Show, (forall x. SetCognitoEvents -> Rep SetCognitoEvents x)
-> (forall x. Rep SetCognitoEvents x -> SetCognitoEvents)
-> Generic SetCognitoEvents
forall x. Rep SetCognitoEvents x -> SetCognitoEvents
forall x. SetCognitoEvents -> Rep SetCognitoEvents x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SetCognitoEvents x -> SetCognitoEvents
$cfrom :: forall x. SetCognitoEvents -> Rep SetCognitoEvents x
Prelude.Generic)

-- |
-- Create a value of 'SetCognitoEvents' 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:
--
-- 'identityPoolId', 'setCognitoEvents_identityPoolId' - The Cognito Identity Pool to use when configuring Cognito Events
--
-- 'events', 'setCognitoEvents_events' - The events to configure
newSetCognitoEvents ::
  -- | 'identityPoolId'
  Prelude.Text ->
  SetCognitoEvents
newSetCognitoEvents :: Text -> SetCognitoEvents
newSetCognitoEvents Text
pIdentityPoolId_ =
  SetCognitoEvents' :: Text -> HashMap Text Text -> SetCognitoEvents
SetCognitoEvents'
    { $sel:identityPoolId:SetCognitoEvents' :: Text
identityPoolId =
        Text
pIdentityPoolId_,
      $sel:events:SetCognitoEvents' :: HashMap Text Text
events = HashMap Text Text
forall a. Monoid a => a
Prelude.mempty
    }

-- | The Cognito Identity Pool to use when configuring Cognito Events
setCognitoEvents_identityPoolId :: Lens.Lens' SetCognitoEvents Prelude.Text
setCognitoEvents_identityPoolId :: (Text -> f Text) -> SetCognitoEvents -> f SetCognitoEvents
setCognitoEvents_identityPoolId = (SetCognitoEvents -> Text)
-> (SetCognitoEvents -> Text -> SetCognitoEvents)
-> Lens SetCognitoEvents SetCognitoEvents Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SetCognitoEvents' {Text
identityPoolId :: Text
$sel:identityPoolId:SetCognitoEvents' :: SetCognitoEvents -> Text
identityPoolId} -> Text
identityPoolId) (\s :: SetCognitoEvents
s@SetCognitoEvents' {} Text
a -> SetCognitoEvents
s {$sel:identityPoolId:SetCognitoEvents' :: Text
identityPoolId = Text
a} :: SetCognitoEvents)

-- | The events to configure
setCognitoEvents_events :: Lens.Lens' SetCognitoEvents (Prelude.HashMap Prelude.Text Prelude.Text)
setCognitoEvents_events :: (HashMap Text Text -> f (HashMap Text Text))
-> SetCognitoEvents -> f SetCognitoEvents
setCognitoEvents_events = (SetCognitoEvents -> HashMap Text Text)
-> (SetCognitoEvents -> HashMap Text Text -> SetCognitoEvents)
-> Lens
     SetCognitoEvents
     SetCognitoEvents
     (HashMap Text Text)
     (HashMap Text Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SetCognitoEvents' {HashMap Text Text
events :: HashMap Text Text
$sel:events:SetCognitoEvents' :: SetCognitoEvents -> HashMap Text Text
events} -> HashMap Text Text
events) (\s :: SetCognitoEvents
s@SetCognitoEvents' {} HashMap Text Text
a -> SetCognitoEvents
s {$sel:events:SetCognitoEvents' :: HashMap Text Text
events = HashMap Text Text
a} :: SetCognitoEvents) ((HashMap Text Text -> f (HashMap Text Text))
 -> SetCognitoEvents -> f SetCognitoEvents)
-> ((HashMap Text Text -> f (HashMap Text Text))
    -> HashMap Text Text -> f (HashMap Text Text))
-> (HashMap Text Text -> f (HashMap Text Text))
-> SetCognitoEvents
-> f SetCognitoEvents
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (HashMap Text Text -> f (HashMap Text Text))
-> HashMap Text Text -> f (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest SetCognitoEvents where
  type
    AWSResponse SetCognitoEvents =
      SetCognitoEventsResponse
  request :: SetCognitoEvents -> Request SetCognitoEvents
request = Service -> SetCognitoEvents -> Request SetCognitoEvents
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy SetCognitoEvents
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse SetCognitoEvents)))
response =
    AWSResponse SetCognitoEvents
-> Logger
-> Service
-> Proxy SetCognitoEvents
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse SetCognitoEvents)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse SetCognitoEvents
SetCognitoEventsResponse
SetCognitoEventsResponse'

instance Prelude.Hashable SetCognitoEvents

instance Prelude.NFData SetCognitoEvents

instance Core.ToHeaders SetCognitoEvents where
  toHeaders :: SetCognitoEvents -> [Header]
toHeaders =
    [Header] -> SetCognitoEvents -> [Header]
forall a b. a -> b -> a
Prelude.const
      ( [[Header]] -> [Header]
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              HeaderName -> ByteString -> [Header]
forall a. ToHeader a => HeaderName -> a -> [Header]
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON SetCognitoEvents where
  toJSON :: SetCognitoEvents -> Value
toJSON SetCognitoEvents' {Text
HashMap Text Text
events :: HashMap Text Text
identityPoolId :: Text
$sel:events:SetCognitoEvents' :: SetCognitoEvents -> HashMap Text Text
$sel:identityPoolId:SetCognitoEvents' :: SetCognitoEvents -> 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
"Events" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HashMap Text Text
events)]
      )

instance Core.ToPath SetCognitoEvents where
  toPath :: SetCognitoEvents -> ByteString
toPath SetCognitoEvents' {Text
HashMap Text Text
events :: HashMap Text Text
identityPoolId :: Text
$sel:events:SetCognitoEvents' :: SetCognitoEvents -> HashMap Text Text
$sel:identityPoolId:SetCognitoEvents' :: SetCognitoEvents -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/identitypools/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
identityPoolId,
        ByteString
"/events"
      ]

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

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

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

instance Prelude.NFData SetCognitoEventsResponse