{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.SecretsManager.Types.RotationRulesType
-- 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)
module Amazonka.SecretsManager.Types.RotationRulesType where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A structure that defines the rotation configuration for the secret.
--
-- /See:/ 'newRotationRulesType' smart constructor.
data RotationRulesType = RotationRulesType'
  { -- | Specifies the number of days between automatic scheduled rotations of
    -- the secret.
    --
    -- Secrets Manager schedules the next rotation when the previous one is
    -- complete. Secrets Manager schedules the date by adding the rotation
    -- interval (number of days) to the actual date of the last rotation. The
    -- service chooses the hour within that 24-hour date window randomly. The
    -- minute is also chosen somewhat randomly, but weighted towards the top of
    -- the hour and influenced by a variety of factors that help distribute
    -- load.
    RotationRulesType -> Maybe Natural
automaticallyAfterDays :: Prelude.Maybe Prelude.Natural
  }
  deriving (RotationRulesType -> RotationRulesType -> Bool
(RotationRulesType -> RotationRulesType -> Bool)
-> (RotationRulesType -> RotationRulesType -> Bool)
-> Eq RotationRulesType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RotationRulesType -> RotationRulesType -> Bool
$c/= :: RotationRulesType -> RotationRulesType -> Bool
== :: RotationRulesType -> RotationRulesType -> Bool
$c== :: RotationRulesType -> RotationRulesType -> Bool
Prelude.Eq, ReadPrec [RotationRulesType]
ReadPrec RotationRulesType
Int -> ReadS RotationRulesType
ReadS [RotationRulesType]
(Int -> ReadS RotationRulesType)
-> ReadS [RotationRulesType]
-> ReadPrec RotationRulesType
-> ReadPrec [RotationRulesType]
-> Read RotationRulesType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RotationRulesType]
$creadListPrec :: ReadPrec [RotationRulesType]
readPrec :: ReadPrec RotationRulesType
$creadPrec :: ReadPrec RotationRulesType
readList :: ReadS [RotationRulesType]
$creadList :: ReadS [RotationRulesType]
readsPrec :: Int -> ReadS RotationRulesType
$creadsPrec :: Int -> ReadS RotationRulesType
Prelude.Read, Int -> RotationRulesType -> ShowS
[RotationRulesType] -> ShowS
RotationRulesType -> String
(Int -> RotationRulesType -> ShowS)
-> (RotationRulesType -> String)
-> ([RotationRulesType] -> ShowS)
-> Show RotationRulesType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RotationRulesType] -> ShowS
$cshowList :: [RotationRulesType] -> ShowS
show :: RotationRulesType -> String
$cshow :: RotationRulesType -> String
showsPrec :: Int -> RotationRulesType -> ShowS
$cshowsPrec :: Int -> RotationRulesType -> ShowS
Prelude.Show, (forall x. RotationRulesType -> Rep RotationRulesType x)
-> (forall x. Rep RotationRulesType x -> RotationRulesType)
-> Generic RotationRulesType
forall x. Rep RotationRulesType x -> RotationRulesType
forall x. RotationRulesType -> Rep RotationRulesType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RotationRulesType x -> RotationRulesType
$cfrom :: forall x. RotationRulesType -> Rep RotationRulesType x
Prelude.Generic)

-- |
-- Create a value of 'RotationRulesType' 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:
--
-- 'automaticallyAfterDays', 'rotationRulesType_automaticallyAfterDays' - Specifies the number of days between automatic scheduled rotations of
-- the secret.
--
-- Secrets Manager schedules the next rotation when the previous one is
-- complete. Secrets Manager schedules the date by adding the rotation
-- interval (number of days) to the actual date of the last rotation. The
-- service chooses the hour within that 24-hour date window randomly. The
-- minute is also chosen somewhat randomly, but weighted towards the top of
-- the hour and influenced by a variety of factors that help distribute
-- load.
newRotationRulesType ::
  RotationRulesType
newRotationRulesType :: RotationRulesType
newRotationRulesType =
  RotationRulesType' :: Maybe Natural -> RotationRulesType
RotationRulesType'
    { $sel:automaticallyAfterDays:RotationRulesType' :: Maybe Natural
automaticallyAfterDays =
        Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | Specifies the number of days between automatic scheduled rotations of
-- the secret.
--
-- Secrets Manager schedules the next rotation when the previous one is
-- complete. Secrets Manager schedules the date by adding the rotation
-- interval (number of days) to the actual date of the last rotation. The
-- service chooses the hour within that 24-hour date window randomly. The
-- minute is also chosen somewhat randomly, but weighted towards the top of
-- the hour and influenced by a variety of factors that help distribute
-- load.
rotationRulesType_automaticallyAfterDays :: Lens.Lens' RotationRulesType (Prelude.Maybe Prelude.Natural)
rotationRulesType_automaticallyAfterDays :: (Maybe Natural -> f (Maybe Natural))
-> RotationRulesType -> f RotationRulesType
rotationRulesType_automaticallyAfterDays = (RotationRulesType -> Maybe Natural)
-> (RotationRulesType -> Maybe Natural -> RotationRulesType)
-> Lens
     RotationRulesType RotationRulesType (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RotationRulesType' {Maybe Natural
automaticallyAfterDays :: Maybe Natural
$sel:automaticallyAfterDays:RotationRulesType' :: RotationRulesType -> Maybe Natural
automaticallyAfterDays} -> Maybe Natural
automaticallyAfterDays) (\s :: RotationRulesType
s@RotationRulesType' {} Maybe Natural
a -> RotationRulesType
s {$sel:automaticallyAfterDays:RotationRulesType' :: Maybe Natural
automaticallyAfterDays = Maybe Natural
a} :: RotationRulesType)

instance Core.FromJSON RotationRulesType where
  parseJSON :: Value -> Parser RotationRulesType
parseJSON =
    String
-> (Object -> Parser RotationRulesType)
-> Value
-> Parser RotationRulesType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RotationRulesType"
      ( \Object
x ->
          Maybe Natural -> RotationRulesType
RotationRulesType'
            (Maybe Natural -> RotationRulesType)
-> Parser (Maybe Natural) -> Parser RotationRulesType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"AutomaticallyAfterDays")
      )

instance Prelude.Hashable RotationRulesType

instance Prelude.NFData RotationRulesType

instance Core.ToJSON RotationRulesType where
  toJSON :: RotationRulesType -> Value
toJSON RotationRulesType' {Maybe Natural
automaticallyAfterDays :: Maybe Natural
$sel:automaticallyAfterDays:RotationRulesType' :: RotationRulesType -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"AutomaticallyAfterDays" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
automaticallyAfterDays
          ]
      )