{-# 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.CrossRegionCopyDeprecateRule
-- 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.CrossRegionCopyDeprecateRule 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 an AMI deprecation rule for cross-Region AMI copies created by
-- a cross-Region copy rule.
--
-- /See:/ 'newCrossRegionCopyDeprecateRule' smart constructor.
data CrossRegionCopyDeprecateRule = CrossRegionCopyDeprecateRule'
  { -- | The period after which to deprecate the cross-Region AMI copies. The
    -- period must be less than or equal to the cross-Region AMI copy retention
    -- period, and it can\'t be greater than 10 years. This is equivalent to
    -- 120 months, 520 weeks, or 3650 days.
    CrossRegionCopyDeprecateRule -> Maybe Natural
interval :: Prelude.Maybe Prelude.Natural,
    -- | The unit of time in which to measure the __Interval__.
    CrossRegionCopyDeprecateRule -> Maybe RetentionIntervalUnitValues
intervalUnit :: Prelude.Maybe RetentionIntervalUnitValues
  }
  deriving (CrossRegionCopyDeprecateRule
-> CrossRegionCopyDeprecateRule -> Bool
(CrossRegionCopyDeprecateRule
 -> CrossRegionCopyDeprecateRule -> Bool)
-> (CrossRegionCopyDeprecateRule
    -> CrossRegionCopyDeprecateRule -> Bool)
-> Eq CrossRegionCopyDeprecateRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CrossRegionCopyDeprecateRule
-> CrossRegionCopyDeprecateRule -> Bool
$c/= :: CrossRegionCopyDeprecateRule
-> CrossRegionCopyDeprecateRule -> Bool
== :: CrossRegionCopyDeprecateRule
-> CrossRegionCopyDeprecateRule -> Bool
$c== :: CrossRegionCopyDeprecateRule
-> CrossRegionCopyDeprecateRule -> Bool
Prelude.Eq, ReadPrec [CrossRegionCopyDeprecateRule]
ReadPrec CrossRegionCopyDeprecateRule
Int -> ReadS CrossRegionCopyDeprecateRule
ReadS [CrossRegionCopyDeprecateRule]
(Int -> ReadS CrossRegionCopyDeprecateRule)
-> ReadS [CrossRegionCopyDeprecateRule]
-> ReadPrec CrossRegionCopyDeprecateRule
-> ReadPrec [CrossRegionCopyDeprecateRule]
-> Read CrossRegionCopyDeprecateRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CrossRegionCopyDeprecateRule]
$creadListPrec :: ReadPrec [CrossRegionCopyDeprecateRule]
readPrec :: ReadPrec CrossRegionCopyDeprecateRule
$creadPrec :: ReadPrec CrossRegionCopyDeprecateRule
readList :: ReadS [CrossRegionCopyDeprecateRule]
$creadList :: ReadS [CrossRegionCopyDeprecateRule]
readsPrec :: Int -> ReadS CrossRegionCopyDeprecateRule
$creadsPrec :: Int -> ReadS CrossRegionCopyDeprecateRule
Prelude.Read, Int -> CrossRegionCopyDeprecateRule -> ShowS
[CrossRegionCopyDeprecateRule] -> ShowS
CrossRegionCopyDeprecateRule -> String
(Int -> CrossRegionCopyDeprecateRule -> ShowS)
-> (CrossRegionCopyDeprecateRule -> String)
-> ([CrossRegionCopyDeprecateRule] -> ShowS)
-> Show CrossRegionCopyDeprecateRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CrossRegionCopyDeprecateRule] -> ShowS
$cshowList :: [CrossRegionCopyDeprecateRule] -> ShowS
show :: CrossRegionCopyDeprecateRule -> String
$cshow :: CrossRegionCopyDeprecateRule -> String
showsPrec :: Int -> CrossRegionCopyDeprecateRule -> ShowS
$cshowsPrec :: Int -> CrossRegionCopyDeprecateRule -> ShowS
Prelude.Show, (forall x.
 CrossRegionCopyDeprecateRule -> Rep CrossRegionCopyDeprecateRule x)
-> (forall x.
    Rep CrossRegionCopyDeprecateRule x -> CrossRegionCopyDeprecateRule)
-> Generic CrossRegionCopyDeprecateRule
forall x.
Rep CrossRegionCopyDeprecateRule x -> CrossRegionCopyDeprecateRule
forall x.
CrossRegionCopyDeprecateRule -> Rep CrossRegionCopyDeprecateRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CrossRegionCopyDeprecateRule x -> CrossRegionCopyDeprecateRule
$cfrom :: forall x.
CrossRegionCopyDeprecateRule -> Rep CrossRegionCopyDeprecateRule x
Prelude.Generic)

-- |
-- Create a value of 'CrossRegionCopyDeprecateRule' 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', 'crossRegionCopyDeprecateRule_interval' - The period after which to deprecate the cross-Region AMI copies. The
-- period must be less than or equal to the cross-Region AMI copy retention
-- period, and it can\'t be greater than 10 years. This is equivalent to
-- 120 months, 520 weeks, or 3650 days.
--
-- 'intervalUnit', 'crossRegionCopyDeprecateRule_intervalUnit' - The unit of time in which to measure the __Interval__.
newCrossRegionCopyDeprecateRule ::
  CrossRegionCopyDeprecateRule
newCrossRegionCopyDeprecateRule :: CrossRegionCopyDeprecateRule
newCrossRegionCopyDeprecateRule =
  CrossRegionCopyDeprecateRule' :: Maybe Natural
-> Maybe RetentionIntervalUnitValues
-> CrossRegionCopyDeprecateRule
CrossRegionCopyDeprecateRule'
    { $sel:interval:CrossRegionCopyDeprecateRule' :: Maybe Natural
interval =
        Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:intervalUnit:CrossRegionCopyDeprecateRule' :: Maybe RetentionIntervalUnitValues
intervalUnit = Maybe RetentionIntervalUnitValues
forall a. Maybe a
Prelude.Nothing
    }

-- | The period after which to deprecate the cross-Region AMI copies. The
-- period must be less than or equal to the cross-Region AMI copy retention
-- period, and it can\'t be greater than 10 years. This is equivalent to
-- 120 months, 520 weeks, or 3650 days.
crossRegionCopyDeprecateRule_interval :: Lens.Lens' CrossRegionCopyDeprecateRule (Prelude.Maybe Prelude.Natural)
crossRegionCopyDeprecateRule_interval :: (Maybe Natural -> f (Maybe Natural))
-> CrossRegionCopyDeprecateRule -> f CrossRegionCopyDeprecateRule
crossRegionCopyDeprecateRule_interval = (CrossRegionCopyDeprecateRule -> Maybe Natural)
-> (CrossRegionCopyDeprecateRule
    -> Maybe Natural -> CrossRegionCopyDeprecateRule)
-> Lens
     CrossRegionCopyDeprecateRule
     CrossRegionCopyDeprecateRule
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CrossRegionCopyDeprecateRule' {Maybe Natural
interval :: Maybe Natural
$sel:interval:CrossRegionCopyDeprecateRule' :: CrossRegionCopyDeprecateRule -> Maybe Natural
interval} -> Maybe Natural
interval) (\s :: CrossRegionCopyDeprecateRule
s@CrossRegionCopyDeprecateRule' {} Maybe Natural
a -> CrossRegionCopyDeprecateRule
s {$sel:interval:CrossRegionCopyDeprecateRule' :: Maybe Natural
interval = Maybe Natural
a} :: CrossRegionCopyDeprecateRule)

-- | The unit of time in which to measure the __Interval__.
crossRegionCopyDeprecateRule_intervalUnit :: Lens.Lens' CrossRegionCopyDeprecateRule (Prelude.Maybe RetentionIntervalUnitValues)
crossRegionCopyDeprecateRule_intervalUnit :: (Maybe RetentionIntervalUnitValues
 -> f (Maybe RetentionIntervalUnitValues))
-> CrossRegionCopyDeprecateRule -> f CrossRegionCopyDeprecateRule
crossRegionCopyDeprecateRule_intervalUnit = (CrossRegionCopyDeprecateRule -> Maybe RetentionIntervalUnitValues)
-> (CrossRegionCopyDeprecateRule
    -> Maybe RetentionIntervalUnitValues
    -> CrossRegionCopyDeprecateRule)
-> Lens
     CrossRegionCopyDeprecateRule
     CrossRegionCopyDeprecateRule
     (Maybe RetentionIntervalUnitValues)
     (Maybe RetentionIntervalUnitValues)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CrossRegionCopyDeprecateRule' {Maybe RetentionIntervalUnitValues
intervalUnit :: Maybe RetentionIntervalUnitValues
$sel:intervalUnit:CrossRegionCopyDeprecateRule' :: CrossRegionCopyDeprecateRule -> Maybe RetentionIntervalUnitValues
intervalUnit} -> Maybe RetentionIntervalUnitValues
intervalUnit) (\s :: CrossRegionCopyDeprecateRule
s@CrossRegionCopyDeprecateRule' {} Maybe RetentionIntervalUnitValues
a -> CrossRegionCopyDeprecateRule
s {$sel:intervalUnit:CrossRegionCopyDeprecateRule' :: Maybe RetentionIntervalUnitValues
intervalUnit = Maybe RetentionIntervalUnitValues
a} :: CrossRegionCopyDeprecateRule)

instance Core.FromJSON CrossRegionCopyDeprecateRule where
  parseJSON :: Value -> Parser CrossRegionCopyDeprecateRule
parseJSON =
    String
-> (Object -> Parser CrossRegionCopyDeprecateRule)
-> Value
-> Parser CrossRegionCopyDeprecateRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CrossRegionCopyDeprecateRule"
      ( \Object
x ->
          Maybe Natural
-> Maybe RetentionIntervalUnitValues
-> CrossRegionCopyDeprecateRule
CrossRegionCopyDeprecateRule'
            (Maybe Natural
 -> Maybe RetentionIntervalUnitValues
 -> CrossRegionCopyDeprecateRule)
-> Parser (Maybe Natural)
-> Parser
     (Maybe RetentionIntervalUnitValues -> CrossRegionCopyDeprecateRule)
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 -> CrossRegionCopyDeprecateRule)
-> Parser (Maybe RetentionIntervalUnitValues)
-> Parser CrossRegionCopyDeprecateRule
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
    CrossRegionCopyDeprecateRule

instance Prelude.NFData CrossRegionCopyDeprecateRule

instance Core.ToJSON CrossRegionCopyDeprecateRule where
  toJSON :: CrossRegionCopyDeprecateRule -> Value
toJSON CrossRegionCopyDeprecateRule' {Maybe Natural
Maybe RetentionIntervalUnitValues
intervalUnit :: Maybe RetentionIntervalUnitValues
interval :: Maybe Natural
$sel:intervalUnit:CrossRegionCopyDeprecateRule' :: CrossRegionCopyDeprecateRule -> Maybe RetentionIntervalUnitValues
$sel:interval:CrossRegionCopyDeprecateRule' :: CrossRegionCopyDeprecateRule -> 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
          ]
      )