{-# 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.Config.PutRetentionConfiguration
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates and updates the retention configuration with details about
-- retention period (number of days) that Config stores your historical
-- information. The API creates the @RetentionConfiguration@ object and
-- names the object as __default__. When you have a
-- @RetentionConfiguration@ object named __default__, calling the API
-- modifies the default object.
--
-- Currently, Config supports only one retention configuration per region
-- in your account.
module Amazonka.Config.PutRetentionConfiguration
  ( -- * Creating a Request
    PutRetentionConfiguration (..),
    newPutRetentionConfiguration,

    -- * Request Lenses
    putRetentionConfiguration_retentionPeriodInDays,

    -- * Destructuring the Response
    PutRetentionConfigurationResponse (..),
    newPutRetentionConfigurationResponse,

    -- * Response Lenses
    putRetentionConfigurationResponse_retentionConfiguration,
    putRetentionConfigurationResponse_httpStatus,
  )
where

import Amazonka.Config.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:/ 'newPutRetentionConfiguration' smart constructor.
data PutRetentionConfiguration = PutRetentionConfiguration'
  { -- | Number of days Config stores your historical information.
    --
    -- Currently, only applicable to the configuration item history.
    PutRetentionConfiguration -> Natural
retentionPeriodInDays :: Prelude.Natural
  }
  deriving (PutRetentionConfiguration -> PutRetentionConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutRetentionConfiguration -> PutRetentionConfiguration -> Bool
$c/= :: PutRetentionConfiguration -> PutRetentionConfiguration -> Bool
== :: PutRetentionConfiguration -> PutRetentionConfiguration -> Bool
$c== :: PutRetentionConfiguration -> PutRetentionConfiguration -> Bool
Prelude.Eq, ReadPrec [PutRetentionConfiguration]
ReadPrec PutRetentionConfiguration
Int -> ReadS PutRetentionConfiguration
ReadS [PutRetentionConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutRetentionConfiguration]
$creadListPrec :: ReadPrec [PutRetentionConfiguration]
readPrec :: ReadPrec PutRetentionConfiguration
$creadPrec :: ReadPrec PutRetentionConfiguration
readList :: ReadS [PutRetentionConfiguration]
$creadList :: ReadS [PutRetentionConfiguration]
readsPrec :: Int -> ReadS PutRetentionConfiguration
$creadsPrec :: Int -> ReadS PutRetentionConfiguration
Prelude.Read, Int -> PutRetentionConfiguration -> ShowS
[PutRetentionConfiguration] -> ShowS
PutRetentionConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutRetentionConfiguration] -> ShowS
$cshowList :: [PutRetentionConfiguration] -> ShowS
show :: PutRetentionConfiguration -> String
$cshow :: PutRetentionConfiguration -> String
showsPrec :: Int -> PutRetentionConfiguration -> ShowS
$cshowsPrec :: Int -> PutRetentionConfiguration -> ShowS
Prelude.Show, forall x.
Rep PutRetentionConfiguration x -> PutRetentionConfiguration
forall x.
PutRetentionConfiguration -> Rep PutRetentionConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PutRetentionConfiguration x -> PutRetentionConfiguration
$cfrom :: forall x.
PutRetentionConfiguration -> Rep PutRetentionConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'PutRetentionConfiguration' 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:
--
-- 'retentionPeriodInDays', 'putRetentionConfiguration_retentionPeriodInDays' - Number of days Config stores your historical information.
--
-- Currently, only applicable to the configuration item history.
newPutRetentionConfiguration ::
  -- | 'retentionPeriodInDays'
  Prelude.Natural ->
  PutRetentionConfiguration
newPutRetentionConfiguration :: Natural -> PutRetentionConfiguration
newPutRetentionConfiguration Natural
pRetentionPeriodInDays_ =
  PutRetentionConfiguration'
    { $sel:retentionPeriodInDays:PutRetentionConfiguration' :: Natural
retentionPeriodInDays =
        Natural
pRetentionPeriodInDays_
    }

-- | Number of days Config stores your historical information.
--
-- Currently, only applicable to the configuration item history.
putRetentionConfiguration_retentionPeriodInDays :: Lens.Lens' PutRetentionConfiguration Prelude.Natural
putRetentionConfiguration_retentionPeriodInDays :: Lens' PutRetentionConfiguration Natural
putRetentionConfiguration_retentionPeriodInDays = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRetentionConfiguration' {Natural
retentionPeriodInDays :: Natural
$sel:retentionPeriodInDays:PutRetentionConfiguration' :: PutRetentionConfiguration -> Natural
retentionPeriodInDays} -> Natural
retentionPeriodInDays) (\s :: PutRetentionConfiguration
s@PutRetentionConfiguration' {} Natural
a -> PutRetentionConfiguration
s {$sel:retentionPeriodInDays:PutRetentionConfiguration' :: Natural
retentionPeriodInDays = Natural
a} :: PutRetentionConfiguration)

instance Core.AWSRequest PutRetentionConfiguration where
  type
    AWSResponse PutRetentionConfiguration =
      PutRetentionConfigurationResponse
  request :: (Service -> Service)
-> PutRetentionConfiguration -> Request PutRetentionConfiguration
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 PutRetentionConfiguration
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutRetentionConfiguration)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe RetentionConfiguration
-> Int -> PutRetentionConfigurationResponse
PutRetentionConfigurationResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"RetentionConfiguration")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable PutRetentionConfiguration where
  hashWithSalt :: Int -> PutRetentionConfiguration -> Int
hashWithSalt Int
_salt PutRetentionConfiguration' {Natural
retentionPeriodInDays :: Natural
$sel:retentionPeriodInDays:PutRetentionConfiguration' :: PutRetentionConfiguration -> Natural
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
retentionPeriodInDays

instance Prelude.NFData PutRetentionConfiguration where
  rnf :: PutRetentionConfiguration -> ()
rnf PutRetentionConfiguration' {Natural
retentionPeriodInDays :: Natural
$sel:retentionPeriodInDays:PutRetentionConfiguration' :: PutRetentionConfiguration -> Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Natural
retentionPeriodInDays

instance Data.ToHeaders PutRetentionConfiguration where
  toHeaders :: PutRetentionConfiguration -> ResponseHeaders
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 -> ResponseHeaders
Data.=# ( ByteString
"StarlingDoveService.PutRetentionConfiguration" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON PutRetentionConfiguration where
  toJSON :: PutRetentionConfiguration -> Value
toJSON PutRetentionConfiguration' {Natural
retentionPeriodInDays :: Natural
$sel:retentionPeriodInDays:PutRetentionConfiguration' :: PutRetentionConfiguration -> Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              ( Key
"RetentionPeriodInDays"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
retentionPeriodInDays
              )
          ]
      )

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

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

-- | /See:/ 'newPutRetentionConfigurationResponse' smart constructor.
data PutRetentionConfigurationResponse = PutRetentionConfigurationResponse'
  { -- | Returns a retention configuration object.
    PutRetentionConfigurationResponse -> Maybe RetentionConfiguration
retentionConfiguration :: Prelude.Maybe RetentionConfiguration,
    -- | The response's http status code.
    PutRetentionConfigurationResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (PutRetentionConfigurationResponse
-> PutRetentionConfigurationResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutRetentionConfigurationResponse
-> PutRetentionConfigurationResponse -> Bool
$c/= :: PutRetentionConfigurationResponse
-> PutRetentionConfigurationResponse -> Bool
== :: PutRetentionConfigurationResponse
-> PutRetentionConfigurationResponse -> Bool
$c== :: PutRetentionConfigurationResponse
-> PutRetentionConfigurationResponse -> Bool
Prelude.Eq, ReadPrec [PutRetentionConfigurationResponse]
ReadPrec PutRetentionConfigurationResponse
Int -> ReadS PutRetentionConfigurationResponse
ReadS [PutRetentionConfigurationResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutRetentionConfigurationResponse]
$creadListPrec :: ReadPrec [PutRetentionConfigurationResponse]
readPrec :: ReadPrec PutRetentionConfigurationResponse
$creadPrec :: ReadPrec PutRetentionConfigurationResponse
readList :: ReadS [PutRetentionConfigurationResponse]
$creadList :: ReadS [PutRetentionConfigurationResponse]
readsPrec :: Int -> ReadS PutRetentionConfigurationResponse
$creadsPrec :: Int -> ReadS PutRetentionConfigurationResponse
Prelude.Read, Int -> PutRetentionConfigurationResponse -> ShowS
[PutRetentionConfigurationResponse] -> ShowS
PutRetentionConfigurationResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutRetentionConfigurationResponse] -> ShowS
$cshowList :: [PutRetentionConfigurationResponse] -> ShowS
show :: PutRetentionConfigurationResponse -> String
$cshow :: PutRetentionConfigurationResponse -> String
showsPrec :: Int -> PutRetentionConfigurationResponse -> ShowS
$cshowsPrec :: Int -> PutRetentionConfigurationResponse -> ShowS
Prelude.Show, forall x.
Rep PutRetentionConfigurationResponse x
-> PutRetentionConfigurationResponse
forall x.
PutRetentionConfigurationResponse
-> Rep PutRetentionConfigurationResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PutRetentionConfigurationResponse x
-> PutRetentionConfigurationResponse
$cfrom :: forall x.
PutRetentionConfigurationResponse
-> Rep PutRetentionConfigurationResponse x
Prelude.Generic)

-- |
-- Create a value of 'PutRetentionConfigurationResponse' 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:
--
-- 'retentionConfiguration', 'putRetentionConfigurationResponse_retentionConfiguration' - Returns a retention configuration object.
--
-- 'httpStatus', 'putRetentionConfigurationResponse_httpStatus' - The response's http status code.
newPutRetentionConfigurationResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutRetentionConfigurationResponse
newPutRetentionConfigurationResponse :: Int -> PutRetentionConfigurationResponse
newPutRetentionConfigurationResponse Int
pHttpStatus_ =
  PutRetentionConfigurationResponse'
    { $sel:retentionConfiguration:PutRetentionConfigurationResponse' :: Maybe RetentionConfiguration
retentionConfiguration =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PutRetentionConfigurationResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Returns a retention configuration object.
putRetentionConfigurationResponse_retentionConfiguration :: Lens.Lens' PutRetentionConfigurationResponse (Prelude.Maybe RetentionConfiguration)
putRetentionConfigurationResponse_retentionConfiguration :: Lens'
  PutRetentionConfigurationResponse (Maybe RetentionConfiguration)
putRetentionConfigurationResponse_retentionConfiguration = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRetentionConfigurationResponse' {Maybe RetentionConfiguration
retentionConfiguration :: Maybe RetentionConfiguration
$sel:retentionConfiguration:PutRetentionConfigurationResponse' :: PutRetentionConfigurationResponse -> Maybe RetentionConfiguration
retentionConfiguration} -> Maybe RetentionConfiguration
retentionConfiguration) (\s :: PutRetentionConfigurationResponse
s@PutRetentionConfigurationResponse' {} Maybe RetentionConfiguration
a -> PutRetentionConfigurationResponse
s {$sel:retentionConfiguration:PutRetentionConfigurationResponse' :: Maybe RetentionConfiguration
retentionConfiguration = Maybe RetentionConfiguration
a} :: PutRetentionConfigurationResponse)

-- | The response's http status code.
putRetentionConfigurationResponse_httpStatus :: Lens.Lens' PutRetentionConfigurationResponse Prelude.Int
putRetentionConfigurationResponse_httpStatus :: Lens' PutRetentionConfigurationResponse Int
putRetentionConfigurationResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRetentionConfigurationResponse' {Int
httpStatus :: Int
$sel:httpStatus:PutRetentionConfigurationResponse' :: PutRetentionConfigurationResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: PutRetentionConfigurationResponse
s@PutRetentionConfigurationResponse' {} Int
a -> PutRetentionConfigurationResponse
s {$sel:httpStatus:PutRetentionConfigurationResponse' :: Int
httpStatus = Int
a} :: PutRetentionConfigurationResponse)

instance
  Prelude.NFData
    PutRetentionConfigurationResponse
  where
  rnf :: PutRetentionConfigurationResponse -> ()
rnf PutRetentionConfigurationResponse' {Int
Maybe RetentionConfiguration
httpStatus :: Int
retentionConfiguration :: Maybe RetentionConfiguration
$sel:httpStatus:PutRetentionConfigurationResponse' :: PutRetentionConfigurationResponse -> Int
$sel:retentionConfiguration:PutRetentionConfigurationResponse' :: PutRetentionConfigurationResponse -> Maybe RetentionConfiguration
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe RetentionConfiguration
retentionConfiguration
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus