{-# 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.CloudHSMV2.Types.BackupRetentionPolicy
-- 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.CloudHSMV2.Types.BackupRetentionPolicy where

import Amazonka.CloudHSMV2.Types.BackupRetentionType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A policy that defines the number of days to retain backups.
--
-- /See:/ 'newBackupRetentionPolicy' smart constructor.
data BackupRetentionPolicy = BackupRetentionPolicy'
  { -- | Use a value between 7 - 379.
    BackupRetentionPolicy -> Maybe Text
value :: Prelude.Maybe Prelude.Text,
    -- | The type of backup retention policy. For the @DAYS@ type, the value is
    -- the number of days to retain backups.
    BackupRetentionPolicy -> Maybe BackupRetentionType
type' :: Prelude.Maybe BackupRetentionType
  }
  deriving (BackupRetentionPolicy -> BackupRetentionPolicy -> Bool
(BackupRetentionPolicy -> BackupRetentionPolicy -> Bool)
-> (BackupRetentionPolicy -> BackupRetentionPolicy -> Bool)
-> Eq BackupRetentionPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BackupRetentionPolicy -> BackupRetentionPolicy -> Bool
$c/= :: BackupRetentionPolicy -> BackupRetentionPolicy -> Bool
== :: BackupRetentionPolicy -> BackupRetentionPolicy -> Bool
$c== :: BackupRetentionPolicy -> BackupRetentionPolicy -> Bool
Prelude.Eq, ReadPrec [BackupRetentionPolicy]
ReadPrec BackupRetentionPolicy
Int -> ReadS BackupRetentionPolicy
ReadS [BackupRetentionPolicy]
(Int -> ReadS BackupRetentionPolicy)
-> ReadS [BackupRetentionPolicy]
-> ReadPrec BackupRetentionPolicy
-> ReadPrec [BackupRetentionPolicy]
-> Read BackupRetentionPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BackupRetentionPolicy]
$creadListPrec :: ReadPrec [BackupRetentionPolicy]
readPrec :: ReadPrec BackupRetentionPolicy
$creadPrec :: ReadPrec BackupRetentionPolicy
readList :: ReadS [BackupRetentionPolicy]
$creadList :: ReadS [BackupRetentionPolicy]
readsPrec :: Int -> ReadS BackupRetentionPolicy
$creadsPrec :: Int -> ReadS BackupRetentionPolicy
Prelude.Read, Int -> BackupRetentionPolicy -> ShowS
[BackupRetentionPolicy] -> ShowS
BackupRetentionPolicy -> String
(Int -> BackupRetentionPolicy -> ShowS)
-> (BackupRetentionPolicy -> String)
-> ([BackupRetentionPolicy] -> ShowS)
-> Show BackupRetentionPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BackupRetentionPolicy] -> ShowS
$cshowList :: [BackupRetentionPolicy] -> ShowS
show :: BackupRetentionPolicy -> String
$cshow :: BackupRetentionPolicy -> String
showsPrec :: Int -> BackupRetentionPolicy -> ShowS
$cshowsPrec :: Int -> BackupRetentionPolicy -> ShowS
Prelude.Show, (forall x. BackupRetentionPolicy -> Rep BackupRetentionPolicy x)
-> (forall x. Rep BackupRetentionPolicy x -> BackupRetentionPolicy)
-> Generic BackupRetentionPolicy
forall x. Rep BackupRetentionPolicy x -> BackupRetentionPolicy
forall x. BackupRetentionPolicy -> Rep BackupRetentionPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BackupRetentionPolicy x -> BackupRetentionPolicy
$cfrom :: forall x. BackupRetentionPolicy -> Rep BackupRetentionPolicy x
Prelude.Generic)

-- |
-- Create a value of 'BackupRetentionPolicy' 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:
--
-- 'value', 'backupRetentionPolicy_value' - Use a value between 7 - 379.
--
-- 'type'', 'backupRetentionPolicy_type' - The type of backup retention policy. For the @DAYS@ type, the value is
-- the number of days to retain backups.
newBackupRetentionPolicy ::
  BackupRetentionPolicy
newBackupRetentionPolicy :: BackupRetentionPolicy
newBackupRetentionPolicy =
  BackupRetentionPolicy' :: Maybe Text -> Maybe BackupRetentionType -> BackupRetentionPolicy
BackupRetentionPolicy'
    { $sel:value:BackupRetentionPolicy' :: Maybe Text
value = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:type':BackupRetentionPolicy' :: Maybe BackupRetentionType
type' = Maybe BackupRetentionType
forall a. Maybe a
Prelude.Nothing
    }

-- | Use a value between 7 - 379.
backupRetentionPolicy_value :: Lens.Lens' BackupRetentionPolicy (Prelude.Maybe Prelude.Text)
backupRetentionPolicy_value :: (Maybe Text -> f (Maybe Text))
-> BackupRetentionPolicy -> f BackupRetentionPolicy
backupRetentionPolicy_value = (BackupRetentionPolicy -> Maybe Text)
-> (BackupRetentionPolicy -> Maybe Text -> BackupRetentionPolicy)
-> Lens
     BackupRetentionPolicy
     BackupRetentionPolicy
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BackupRetentionPolicy' {Maybe Text
value :: Maybe Text
$sel:value:BackupRetentionPolicy' :: BackupRetentionPolicy -> Maybe Text
value} -> Maybe Text
value) (\s :: BackupRetentionPolicy
s@BackupRetentionPolicy' {} Maybe Text
a -> BackupRetentionPolicy
s {$sel:value:BackupRetentionPolicy' :: Maybe Text
value = Maybe Text
a} :: BackupRetentionPolicy)

-- | The type of backup retention policy. For the @DAYS@ type, the value is
-- the number of days to retain backups.
backupRetentionPolicy_type :: Lens.Lens' BackupRetentionPolicy (Prelude.Maybe BackupRetentionType)
backupRetentionPolicy_type :: (Maybe BackupRetentionType -> f (Maybe BackupRetentionType))
-> BackupRetentionPolicy -> f BackupRetentionPolicy
backupRetentionPolicy_type = (BackupRetentionPolicy -> Maybe BackupRetentionType)
-> (BackupRetentionPolicy
    -> Maybe BackupRetentionType -> BackupRetentionPolicy)
-> Lens
     BackupRetentionPolicy
     BackupRetentionPolicy
     (Maybe BackupRetentionType)
     (Maybe BackupRetentionType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BackupRetentionPolicy' {Maybe BackupRetentionType
type' :: Maybe BackupRetentionType
$sel:type':BackupRetentionPolicy' :: BackupRetentionPolicy -> Maybe BackupRetentionType
type'} -> Maybe BackupRetentionType
type') (\s :: BackupRetentionPolicy
s@BackupRetentionPolicy' {} Maybe BackupRetentionType
a -> BackupRetentionPolicy
s {$sel:type':BackupRetentionPolicy' :: Maybe BackupRetentionType
type' = Maybe BackupRetentionType
a} :: BackupRetentionPolicy)

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

instance Prelude.Hashable BackupRetentionPolicy

instance Prelude.NFData BackupRetentionPolicy

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