{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.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

-- | 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
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]
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
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. 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'
    { $sel:identityPoolId:SetCognitoEvents' :: Text
identityPoolId =
        Text
pIdentityPoolId_,
      $sel:events:SetCognitoEvents' :: HashMap Text Text
events = 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 :: Lens' SetCognitoEvents Text
setCognitoEvents_identityPoolId = 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 :: Lens' SetCognitoEvents (HashMap Text Text)
setCognitoEvents_events = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 :: (Service -> Service)
-> SetCognitoEvents -> Request SetCognitoEvents
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy SetCognitoEvents
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse SetCognitoEvents)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull SetCognitoEventsResponse
SetCognitoEventsResponse'

instance Prelude.Hashable SetCognitoEvents where
  hashWithSalt :: Int -> SetCognitoEvents -> Int
hashWithSalt Int
_salt SetCognitoEvents' {Text
HashMap Text Text
events :: HashMap Text Text
identityPoolId :: Text
$sel:events:SetCognitoEvents' :: SetCognitoEvents -> HashMap Text Text
$sel:identityPoolId:SetCognitoEvents' :: SetCognitoEvents -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
identityPoolId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` HashMap Text Text
events

instance Prelude.NFData SetCognitoEvents where
  rnf :: SetCognitoEvents -> ()
rnf SetCognitoEvents' {Text
HashMap Text Text
events :: HashMap Text Text
identityPoolId :: Text
$sel:events:SetCognitoEvents' :: SetCognitoEvents -> HashMap Text Text
$sel:identityPoolId:SetCognitoEvents' :: SetCognitoEvents -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
identityPoolId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf HashMap Text Text
events

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

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"Events" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= HashMap Text Text
events)]
      )

instance Data.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
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/identitypools/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
identityPoolId,
        ByteString
"/events"
      ]

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

-- | /See:/ 'newSetCognitoEventsResponse' smart constructor.
data SetCognitoEventsResponse = SetCognitoEventsResponse'
  {
  }
  deriving (SetCognitoEventsResponse -> SetCognitoEventsResponse -> Bool
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]
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
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.
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 where
  rnf :: SetCognitoEventsResponse -> ()
rnf SetCognitoEventsResponse
_ = ()