{-# 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.CertificateManager.PutAccountConfiguration
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Adds or modifies account-level configurations in ACM.
--
-- The supported configuration option is @DaysBeforeExpiry@. This option
-- specifies the number of days prior to certificate expiration when ACM
-- starts generating @EventBridge@ events. ACM sends one event per day per
-- certificate until the certificate expires. By default, accounts receive
-- events starting 45 days before certificate expiration.
module Amazonka.CertificateManager.PutAccountConfiguration
  ( -- * Creating a Request
    PutAccountConfiguration (..),
    newPutAccountConfiguration,

    -- * Request Lenses
    putAccountConfiguration_expiryEvents,
    putAccountConfiguration_idempotencyToken,

    -- * Destructuring the Response
    PutAccountConfigurationResponse (..),
    newPutAccountConfigurationResponse,
  )
where

import Amazonka.CertificateManager.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:/ 'newPutAccountConfiguration' smart constructor.
data PutAccountConfiguration = PutAccountConfiguration'
  { -- | Specifies expiration events associated with an account.
    PutAccountConfiguration -> Maybe ExpiryEventsConfiguration
expiryEvents :: Prelude.Maybe ExpiryEventsConfiguration,
    -- | Customer-chosen string used to distinguish between calls to
    -- @PutAccountConfiguration@. Idempotency tokens time out after one hour.
    -- If you call @PutAccountConfiguration@ multiple times with the same
    -- unexpired idempotency token, ACM treats it as the same request and
    -- returns the original result. If you change the idempotency token for
    -- each call, ACM treats each call as a new request.
    PutAccountConfiguration -> Text
idempotencyToken :: Prelude.Text
  }
  deriving (PutAccountConfiguration -> PutAccountConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutAccountConfiguration -> PutAccountConfiguration -> Bool
$c/= :: PutAccountConfiguration -> PutAccountConfiguration -> Bool
== :: PutAccountConfiguration -> PutAccountConfiguration -> Bool
$c== :: PutAccountConfiguration -> PutAccountConfiguration -> Bool
Prelude.Eq, ReadPrec [PutAccountConfiguration]
ReadPrec PutAccountConfiguration
Int -> ReadS PutAccountConfiguration
ReadS [PutAccountConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutAccountConfiguration]
$creadListPrec :: ReadPrec [PutAccountConfiguration]
readPrec :: ReadPrec PutAccountConfiguration
$creadPrec :: ReadPrec PutAccountConfiguration
readList :: ReadS [PutAccountConfiguration]
$creadList :: ReadS [PutAccountConfiguration]
readsPrec :: Int -> ReadS PutAccountConfiguration
$creadsPrec :: Int -> ReadS PutAccountConfiguration
Prelude.Read, Int -> PutAccountConfiguration -> ShowS
[PutAccountConfiguration] -> ShowS
PutAccountConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutAccountConfiguration] -> ShowS
$cshowList :: [PutAccountConfiguration] -> ShowS
show :: PutAccountConfiguration -> String
$cshow :: PutAccountConfiguration -> String
showsPrec :: Int -> PutAccountConfiguration -> ShowS
$cshowsPrec :: Int -> PutAccountConfiguration -> ShowS
Prelude.Show, forall x. Rep PutAccountConfiguration x -> PutAccountConfiguration
forall x. PutAccountConfiguration -> Rep PutAccountConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutAccountConfiguration x -> PutAccountConfiguration
$cfrom :: forall x. PutAccountConfiguration -> Rep PutAccountConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'PutAccountConfiguration' 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:
--
-- 'expiryEvents', 'putAccountConfiguration_expiryEvents' - Specifies expiration events associated with an account.
--
-- 'idempotencyToken', 'putAccountConfiguration_idempotencyToken' - Customer-chosen string used to distinguish between calls to
-- @PutAccountConfiguration@. Idempotency tokens time out after one hour.
-- If you call @PutAccountConfiguration@ multiple times with the same
-- unexpired idempotency token, ACM treats it as the same request and
-- returns the original result. If you change the idempotency token for
-- each call, ACM treats each call as a new request.
newPutAccountConfiguration ::
  -- | 'idempotencyToken'
  Prelude.Text ->
  PutAccountConfiguration
newPutAccountConfiguration :: Text -> PutAccountConfiguration
newPutAccountConfiguration Text
pIdempotencyToken_ =
  PutAccountConfiguration'
    { $sel:expiryEvents:PutAccountConfiguration' :: Maybe ExpiryEventsConfiguration
expiryEvents =
        forall a. Maybe a
Prelude.Nothing,
      $sel:idempotencyToken:PutAccountConfiguration' :: Text
idempotencyToken = Text
pIdempotencyToken_
    }

-- | Specifies expiration events associated with an account.
putAccountConfiguration_expiryEvents :: Lens.Lens' PutAccountConfiguration (Prelude.Maybe ExpiryEventsConfiguration)
putAccountConfiguration_expiryEvents :: Lens' PutAccountConfiguration (Maybe ExpiryEventsConfiguration)
putAccountConfiguration_expiryEvents = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutAccountConfiguration' {Maybe ExpiryEventsConfiguration
expiryEvents :: Maybe ExpiryEventsConfiguration
$sel:expiryEvents:PutAccountConfiguration' :: PutAccountConfiguration -> Maybe ExpiryEventsConfiguration
expiryEvents} -> Maybe ExpiryEventsConfiguration
expiryEvents) (\s :: PutAccountConfiguration
s@PutAccountConfiguration' {} Maybe ExpiryEventsConfiguration
a -> PutAccountConfiguration
s {$sel:expiryEvents:PutAccountConfiguration' :: Maybe ExpiryEventsConfiguration
expiryEvents = Maybe ExpiryEventsConfiguration
a} :: PutAccountConfiguration)

-- | Customer-chosen string used to distinguish between calls to
-- @PutAccountConfiguration@. Idempotency tokens time out after one hour.
-- If you call @PutAccountConfiguration@ multiple times with the same
-- unexpired idempotency token, ACM treats it as the same request and
-- returns the original result. If you change the idempotency token for
-- each call, ACM treats each call as a new request.
putAccountConfiguration_idempotencyToken :: Lens.Lens' PutAccountConfiguration Prelude.Text
putAccountConfiguration_idempotencyToken :: Lens' PutAccountConfiguration Text
putAccountConfiguration_idempotencyToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutAccountConfiguration' {Text
idempotencyToken :: Text
$sel:idempotencyToken:PutAccountConfiguration' :: PutAccountConfiguration -> Text
idempotencyToken} -> Text
idempotencyToken) (\s :: PutAccountConfiguration
s@PutAccountConfiguration' {} Text
a -> PutAccountConfiguration
s {$sel:idempotencyToken:PutAccountConfiguration' :: Text
idempotencyToken = Text
a} :: PutAccountConfiguration)

instance Core.AWSRequest PutAccountConfiguration where
  type
    AWSResponse PutAccountConfiguration =
      PutAccountConfigurationResponse
  request :: (Service -> Service)
-> PutAccountConfiguration -> Request PutAccountConfiguration
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 PutAccountConfiguration
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutAccountConfiguration)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull
      PutAccountConfigurationResponse
PutAccountConfigurationResponse'

instance Prelude.Hashable PutAccountConfiguration where
  hashWithSalt :: Int -> PutAccountConfiguration -> Int
hashWithSalt Int
_salt PutAccountConfiguration' {Maybe ExpiryEventsConfiguration
Text
idempotencyToken :: Text
expiryEvents :: Maybe ExpiryEventsConfiguration
$sel:idempotencyToken:PutAccountConfiguration' :: PutAccountConfiguration -> Text
$sel:expiryEvents:PutAccountConfiguration' :: PutAccountConfiguration -> Maybe ExpiryEventsConfiguration
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ExpiryEventsConfiguration
expiryEvents
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
idempotencyToken

instance Prelude.NFData PutAccountConfiguration where
  rnf :: PutAccountConfiguration -> ()
rnf PutAccountConfiguration' {Maybe ExpiryEventsConfiguration
Text
idempotencyToken :: Text
expiryEvents :: Maybe ExpiryEventsConfiguration
$sel:idempotencyToken:PutAccountConfiguration' :: PutAccountConfiguration -> Text
$sel:expiryEvents:PutAccountConfiguration' :: PutAccountConfiguration -> Maybe ExpiryEventsConfiguration
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ExpiryEventsConfiguration
expiryEvents
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
idempotencyToken

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

instance Data.ToJSON PutAccountConfiguration where
  toJSON :: PutAccountConfiguration -> Value
toJSON PutAccountConfiguration' {Maybe ExpiryEventsConfiguration
Text
idempotencyToken :: Text
expiryEvents :: Maybe ExpiryEventsConfiguration
$sel:idempotencyToken:PutAccountConfiguration' :: PutAccountConfiguration -> Text
$sel:expiryEvents:PutAccountConfiguration' :: PutAccountConfiguration -> Maybe ExpiryEventsConfiguration
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ExpiryEvents" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ExpiryEventsConfiguration
expiryEvents,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"IdempotencyToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
idempotencyToken)
          ]
      )

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

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

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

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

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