{-# 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-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.DLM.Types.CrossRegionCopyRetainRule where

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

-- | Specifies the retention rule for cross-Region snapshot copies.
--
-- /See:/ 'newCrossRegionCopyRetainRule' smart constructor.
data CrossRegionCopyRetainRule = CrossRegionCopyRetainRule'
  { -- | The amount of time to retain each snapshot. 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.
    CrossRegionCopyRetainRule -> Maybe RetentionIntervalUnitValues
intervalUnit :: Prelude.Maybe RetentionIntervalUnitValues
  }
  deriving (CrossRegionCopyRetainRule -> CrossRegionCopyRetainRule -> Bool
(CrossRegionCopyRetainRule -> CrossRegionCopyRetainRule -> Bool)
-> (CrossRegionCopyRetainRule -> CrossRegionCopyRetainRule -> Bool)
-> Eq CrossRegionCopyRetainRule
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]
(Int -> ReadS CrossRegionCopyRetainRule)
-> ReadS [CrossRegionCopyRetainRule]
-> ReadPrec CrossRegionCopyRetainRule
-> ReadPrec [CrossRegionCopyRetainRule]
-> Read 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
(Int -> CrossRegionCopyRetainRule -> ShowS)
-> (CrossRegionCopyRetainRule -> String)
-> ([CrossRegionCopyRetainRule] -> ShowS)
-> Show CrossRegionCopyRetainRule
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.
 CrossRegionCopyRetainRule -> Rep CrossRegionCopyRetainRule x)
-> (forall x.
    Rep CrossRegionCopyRetainRule x -> CrossRegionCopyRetainRule)
-> Generic CrossRegionCopyRetainRule
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 each snapshot. 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.
newCrossRegionCopyRetainRule ::
  CrossRegionCopyRetainRule
newCrossRegionCopyRetainRule :: CrossRegionCopyRetainRule
newCrossRegionCopyRetainRule =
  CrossRegionCopyRetainRule' :: Maybe Natural
-> Maybe RetentionIntervalUnitValues -> CrossRegionCopyRetainRule
CrossRegionCopyRetainRule'
    { $sel:interval:CrossRegionCopyRetainRule' :: Maybe Natural
interval =
        Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:intervalUnit:CrossRegionCopyRetainRule' :: Maybe RetentionIntervalUnitValues
intervalUnit = Maybe RetentionIntervalUnitValues
forall a. Maybe a
Prelude.Nothing
    }

-- | The amount of time to retain each snapshot. 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 :: (Maybe Natural -> f (Maybe Natural))
-> CrossRegionCopyRetainRule -> f CrossRegionCopyRetainRule
crossRegionCopyRetainRule_interval = (CrossRegionCopyRetainRule -> Maybe Natural)
-> (CrossRegionCopyRetainRule
    -> Maybe Natural -> CrossRegionCopyRetainRule)
-> Lens
     CrossRegionCopyRetainRule
     CrossRegionCopyRetainRule
     (Maybe Natural)
     (Maybe Natural)
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.
crossRegionCopyRetainRule_intervalUnit :: Lens.Lens' CrossRegionCopyRetainRule (Prelude.Maybe RetentionIntervalUnitValues)
crossRegionCopyRetainRule_intervalUnit :: (Maybe RetentionIntervalUnitValues
 -> f (Maybe RetentionIntervalUnitValues))
-> CrossRegionCopyRetainRule -> f CrossRegionCopyRetainRule
crossRegionCopyRetainRule_intervalUnit = (CrossRegionCopyRetainRule -> Maybe RetentionIntervalUnitValues)
-> (CrossRegionCopyRetainRule
    -> Maybe RetentionIntervalUnitValues -> CrossRegionCopyRetainRule)
-> Lens
     CrossRegionCopyRetainRule
     CrossRegionCopyRetainRule
     (Maybe RetentionIntervalUnitValues)
     (Maybe RetentionIntervalUnitValues)
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 Core.FromJSON CrossRegionCopyRetainRule where
  parseJSON :: Value -> Parser CrossRegionCopyRetainRule
parseJSON =
    String
-> (Object -> Parser CrossRegionCopyRetainRule)
-> Value
-> Parser CrossRegionCopyRetainRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CrossRegionCopyRetainRule"
      ( \Object
x ->
          Maybe Natural
-> Maybe RetentionIntervalUnitValues -> CrossRegionCopyRetainRule
CrossRegionCopyRetainRule'
            (Maybe Natural
 -> Maybe RetentionIntervalUnitValues -> CrossRegionCopyRetainRule)
-> Parser (Maybe Natural)
-> Parser
     (Maybe RetentionIntervalUnitValues -> CrossRegionCopyRetainRule)
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
"Interval")
            Parser
  (Maybe RetentionIntervalUnitValues -> CrossRegionCopyRetainRule)
-> Parser (Maybe RetentionIntervalUnitValues)
-> Parser CrossRegionCopyRetainRule
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe RetentionIntervalUnitValues)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"IntervalUnit")
      )

instance Prelude.Hashable CrossRegionCopyRetainRule

instance Prelude.NFData CrossRegionCopyRetainRule

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Interval" 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
interval,
            (Text
"IntervalUnit" Text -> RetentionIntervalUnitValues -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (RetentionIntervalUnitValues -> Pair)
-> Maybe RetentionIntervalUnitValues -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe RetentionIntervalUnitValues
intervalUnit
          ]
      )