{-# 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.DLM.Types.CrossRegionCopyRetainRule
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.DLM.Types.CrossRegionCopyRetainRule where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import Amazonka.DLM.Types.RetentionIntervalUnitValues
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Specifies a retention rule for cross-Region snapshot copies created by
-- snapshot or event-based policies, or cross-Region AMI copies created by
-- AMI policies. After the retention period expires, the cross-Region copy
-- is deleted.
--
-- /See:/ 'newCrossRegionCopyRetainRule' smart constructor.
data CrossRegionCopyRetainRule = CrossRegionCopyRetainRule'
  { -- | The amount of time to retain a cross-Region snapshot or AMI copy. The
    -- maximum is 100 years. This is equivalent to 1200 months, 5200 weeks, or
    -- 36500 days.
    CrossRegionCopyRetainRule -> Maybe Natural
interval :: Prelude.Maybe Prelude.Natural,
    -- | The unit of time for time-based retention. For example, to retain a
    -- cross-Region copy for 3 months, specify @Interval=3@ and
    -- @IntervalUnit=MONTHS@.
    CrossRegionCopyRetainRule -> Maybe RetentionIntervalUnitValues
intervalUnit :: Prelude.Maybe RetentionIntervalUnitValues
  }
  deriving (CrossRegionCopyRetainRule -> CrossRegionCopyRetainRule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CrossRegionCopyRetainRule -> CrossRegionCopyRetainRule -> Bool
$c/= :: CrossRegionCopyRetainRule -> CrossRegionCopyRetainRule -> Bool
== :: CrossRegionCopyRetainRule -> CrossRegionCopyRetainRule -> Bool
$c== :: CrossRegionCopyRetainRule -> CrossRegionCopyRetainRule -> Bool
Prelude.Eq, ReadPrec [CrossRegionCopyRetainRule]
ReadPrec CrossRegionCopyRetainRule
Int -> ReadS CrossRegionCopyRetainRule
ReadS [CrossRegionCopyRetainRule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CrossRegionCopyRetainRule]
$creadListPrec :: ReadPrec [CrossRegionCopyRetainRule]
readPrec :: ReadPrec CrossRegionCopyRetainRule
$creadPrec :: ReadPrec CrossRegionCopyRetainRule
readList :: ReadS [CrossRegionCopyRetainRule]
$creadList :: ReadS [CrossRegionCopyRetainRule]
readsPrec :: Int -> ReadS CrossRegionCopyRetainRule
$creadsPrec :: Int -> ReadS CrossRegionCopyRetainRule
Prelude.Read, Int -> CrossRegionCopyRetainRule -> ShowS
[CrossRegionCopyRetainRule] -> ShowS
CrossRegionCopyRetainRule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CrossRegionCopyRetainRule] -> ShowS
$cshowList :: [CrossRegionCopyRetainRule] -> ShowS
show :: CrossRegionCopyRetainRule -> String
$cshow :: CrossRegionCopyRetainRule -> String
showsPrec :: Int -> CrossRegionCopyRetainRule -> ShowS
$cshowsPrec :: Int -> CrossRegionCopyRetainRule -> ShowS
Prelude.Show, forall x.
Rep CrossRegionCopyRetainRule x -> CrossRegionCopyRetainRule
forall x.
CrossRegionCopyRetainRule -> Rep CrossRegionCopyRetainRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CrossRegionCopyRetainRule x -> CrossRegionCopyRetainRule
$cfrom :: forall x.
CrossRegionCopyRetainRule -> Rep CrossRegionCopyRetainRule x
Prelude.Generic)

-- |
-- Create a value of 'CrossRegionCopyRetainRule' 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:
--
-- 'interval', 'crossRegionCopyRetainRule_interval' - The amount of time to retain a cross-Region snapshot or AMI copy. The
-- maximum is 100 years. This is equivalent to 1200 months, 5200 weeks, or
-- 36500 days.
--
-- 'intervalUnit', 'crossRegionCopyRetainRule_intervalUnit' - The unit of time for time-based retention. For example, to retain a
-- cross-Region copy for 3 months, specify @Interval=3@ and
-- @IntervalUnit=MONTHS@.
newCrossRegionCopyRetainRule ::
  CrossRegionCopyRetainRule
newCrossRegionCopyRetainRule :: CrossRegionCopyRetainRule
newCrossRegionCopyRetainRule =
  CrossRegionCopyRetainRule'
    { $sel:interval:CrossRegionCopyRetainRule' :: Maybe Natural
interval =
        forall a. Maybe a
Prelude.Nothing,
      $sel:intervalUnit:CrossRegionCopyRetainRule' :: Maybe RetentionIntervalUnitValues
intervalUnit = forall a. Maybe a
Prelude.Nothing
    }

-- | The amount of time to retain a cross-Region snapshot or AMI copy. The
-- maximum is 100 years. This is equivalent to 1200 months, 5200 weeks, or
-- 36500 days.
crossRegionCopyRetainRule_interval :: Lens.Lens' CrossRegionCopyRetainRule (Prelude.Maybe Prelude.Natural)
crossRegionCopyRetainRule_interval :: Lens' CrossRegionCopyRetainRule (Maybe Natural)
crossRegionCopyRetainRule_interval = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CrossRegionCopyRetainRule' {Maybe Natural
interval :: Maybe Natural
$sel:interval:CrossRegionCopyRetainRule' :: CrossRegionCopyRetainRule -> Maybe Natural
interval} -> Maybe Natural
interval) (\s :: CrossRegionCopyRetainRule
s@CrossRegionCopyRetainRule' {} Maybe Natural
a -> CrossRegionCopyRetainRule
s {$sel:interval:CrossRegionCopyRetainRule' :: Maybe Natural
interval = Maybe Natural
a} :: CrossRegionCopyRetainRule)

-- | The unit of time for time-based retention. For example, to retain a
-- cross-Region copy for 3 months, specify @Interval=3@ and
-- @IntervalUnit=MONTHS@.
crossRegionCopyRetainRule_intervalUnit :: Lens.Lens' CrossRegionCopyRetainRule (Prelude.Maybe RetentionIntervalUnitValues)
crossRegionCopyRetainRule_intervalUnit :: Lens' CrossRegionCopyRetainRule (Maybe RetentionIntervalUnitValues)
crossRegionCopyRetainRule_intervalUnit = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CrossRegionCopyRetainRule' {Maybe RetentionIntervalUnitValues
intervalUnit :: Maybe RetentionIntervalUnitValues
$sel:intervalUnit:CrossRegionCopyRetainRule' :: CrossRegionCopyRetainRule -> Maybe RetentionIntervalUnitValues
intervalUnit} -> Maybe RetentionIntervalUnitValues
intervalUnit) (\s :: CrossRegionCopyRetainRule
s@CrossRegionCopyRetainRule' {} Maybe RetentionIntervalUnitValues
a -> CrossRegionCopyRetainRule
s {$sel:intervalUnit:CrossRegionCopyRetainRule' :: Maybe RetentionIntervalUnitValues
intervalUnit = Maybe RetentionIntervalUnitValues
a} :: CrossRegionCopyRetainRule)

instance Data.FromJSON CrossRegionCopyRetainRule where
  parseJSON :: Value -> Parser CrossRegionCopyRetainRule
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CrossRegionCopyRetainRule"
      ( \Object
x ->
          Maybe Natural
-> Maybe RetentionIntervalUnitValues -> CrossRegionCopyRetainRule
CrossRegionCopyRetainRule'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Interval")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"IntervalUnit")
      )

instance Prelude.Hashable CrossRegionCopyRetainRule where
  hashWithSalt :: Int -> CrossRegionCopyRetainRule -> Int
hashWithSalt Int
_salt CrossRegionCopyRetainRule' {Maybe Natural
Maybe RetentionIntervalUnitValues
intervalUnit :: Maybe RetentionIntervalUnitValues
interval :: Maybe Natural
$sel:intervalUnit:CrossRegionCopyRetainRule' :: CrossRegionCopyRetainRule -> Maybe RetentionIntervalUnitValues
$sel:interval:CrossRegionCopyRetainRule' :: CrossRegionCopyRetainRule -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
interval
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe RetentionIntervalUnitValues
intervalUnit

instance Prelude.NFData CrossRegionCopyRetainRule where
  rnf :: CrossRegionCopyRetainRule -> ()
rnf CrossRegionCopyRetainRule' {Maybe Natural
Maybe RetentionIntervalUnitValues
intervalUnit :: Maybe RetentionIntervalUnitValues
interval :: Maybe Natural
$sel:intervalUnit:CrossRegionCopyRetainRule' :: CrossRegionCopyRetainRule -> Maybe RetentionIntervalUnitValues
$sel:interval:CrossRegionCopyRetainRule' :: CrossRegionCopyRetainRule -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
interval
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe RetentionIntervalUnitValues
intervalUnit

instance Data.ToJSON CrossRegionCopyRetainRule where
  toJSON :: CrossRegionCopyRetainRule -> Value
toJSON CrossRegionCopyRetainRule' {Maybe Natural
Maybe RetentionIntervalUnitValues
intervalUnit :: Maybe RetentionIntervalUnitValues
interval :: Maybe Natural
$sel:intervalUnit:CrossRegionCopyRetainRule' :: CrossRegionCopyRetainRule -> Maybe RetentionIntervalUnitValues
$sel:interval:CrossRegionCopyRetainRule' :: CrossRegionCopyRetainRule -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Interval" 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 Natural
interval,
            (Key
"IntervalUnit" 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 RetentionIntervalUnitValues
intervalUnit
          ]
      )