{-# 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.FastRestoreRule
-- 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.FastRestoreRule 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 a rule for enabling fast snapshot restore. You can enable fast
-- snapshot restore based on either a count or a time interval.
--
-- /See:/ 'newFastRestoreRule' smart constructor.
data FastRestoreRule = FastRestoreRule'
  { -- | The number of snapshots to be enabled with fast snapshot restore.
    FastRestoreRule -> Maybe Natural
count :: Prelude.Maybe Prelude.Natural,
    -- | The amount of time to enable fast snapshot restore. The maximum is 100
    -- years. This is equivalent to 1200 months, 5200 weeks, or 36500 days.
    FastRestoreRule -> Maybe Natural
interval :: Prelude.Maybe Prelude.Natural,
    -- | The unit of time for enabling fast snapshot restore.
    FastRestoreRule -> Maybe RetentionIntervalUnitValues
intervalUnit :: Prelude.Maybe RetentionIntervalUnitValues,
    -- | The Availability Zones in which to enable fast snapshot restore.
    FastRestoreRule -> NonEmpty Text
availabilityZones :: Prelude.NonEmpty Prelude.Text
  }
  deriving (FastRestoreRule -> FastRestoreRule -> Bool
(FastRestoreRule -> FastRestoreRule -> Bool)
-> (FastRestoreRule -> FastRestoreRule -> Bool)
-> Eq FastRestoreRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FastRestoreRule -> FastRestoreRule -> Bool
$c/= :: FastRestoreRule -> FastRestoreRule -> Bool
== :: FastRestoreRule -> FastRestoreRule -> Bool
$c== :: FastRestoreRule -> FastRestoreRule -> Bool
Prelude.Eq, ReadPrec [FastRestoreRule]
ReadPrec FastRestoreRule
Int -> ReadS FastRestoreRule
ReadS [FastRestoreRule]
(Int -> ReadS FastRestoreRule)
-> ReadS [FastRestoreRule]
-> ReadPrec FastRestoreRule
-> ReadPrec [FastRestoreRule]
-> Read FastRestoreRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FastRestoreRule]
$creadListPrec :: ReadPrec [FastRestoreRule]
readPrec :: ReadPrec FastRestoreRule
$creadPrec :: ReadPrec FastRestoreRule
readList :: ReadS [FastRestoreRule]
$creadList :: ReadS [FastRestoreRule]
readsPrec :: Int -> ReadS FastRestoreRule
$creadsPrec :: Int -> ReadS FastRestoreRule
Prelude.Read, Int -> FastRestoreRule -> ShowS
[FastRestoreRule] -> ShowS
FastRestoreRule -> String
(Int -> FastRestoreRule -> ShowS)
-> (FastRestoreRule -> String)
-> ([FastRestoreRule] -> ShowS)
-> Show FastRestoreRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FastRestoreRule] -> ShowS
$cshowList :: [FastRestoreRule] -> ShowS
show :: FastRestoreRule -> String
$cshow :: FastRestoreRule -> String
showsPrec :: Int -> FastRestoreRule -> ShowS
$cshowsPrec :: Int -> FastRestoreRule -> ShowS
Prelude.Show, (forall x. FastRestoreRule -> Rep FastRestoreRule x)
-> (forall x. Rep FastRestoreRule x -> FastRestoreRule)
-> Generic FastRestoreRule
forall x. Rep FastRestoreRule x -> FastRestoreRule
forall x. FastRestoreRule -> Rep FastRestoreRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FastRestoreRule x -> FastRestoreRule
$cfrom :: forall x. FastRestoreRule -> Rep FastRestoreRule x
Prelude.Generic)

-- |
-- Create a value of 'FastRestoreRule' 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:
--
-- 'count', 'fastRestoreRule_count' - The number of snapshots to be enabled with fast snapshot restore.
--
-- 'interval', 'fastRestoreRule_interval' - The amount of time to enable fast snapshot restore. The maximum is 100
-- years. This is equivalent to 1200 months, 5200 weeks, or 36500 days.
--
-- 'intervalUnit', 'fastRestoreRule_intervalUnit' - The unit of time for enabling fast snapshot restore.
--
-- 'availabilityZones', 'fastRestoreRule_availabilityZones' - The Availability Zones in which to enable fast snapshot restore.
newFastRestoreRule ::
  -- | 'availabilityZones'
  Prelude.NonEmpty Prelude.Text ->
  FastRestoreRule
newFastRestoreRule :: NonEmpty Text -> FastRestoreRule
newFastRestoreRule NonEmpty Text
pAvailabilityZones_ =
  FastRestoreRule' :: Maybe Natural
-> Maybe Natural
-> Maybe RetentionIntervalUnitValues
-> NonEmpty Text
-> FastRestoreRule
FastRestoreRule'
    { $sel:count:FastRestoreRule' :: Maybe Natural
count = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:interval:FastRestoreRule' :: Maybe Natural
interval = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:intervalUnit:FastRestoreRule' :: Maybe RetentionIntervalUnitValues
intervalUnit = Maybe RetentionIntervalUnitValues
forall a. Maybe a
Prelude.Nothing,
      $sel:availabilityZones:FastRestoreRule' :: NonEmpty Text
availabilityZones =
        Tagged (NonEmpty Text) (Identity (NonEmpty Text))
-> Tagged (NonEmpty Text) (Identity (NonEmpty Text))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Text) (Identity (NonEmpty Text))
 -> Tagged (NonEmpty Text) (Identity (NonEmpty Text)))
-> NonEmpty Text -> NonEmpty Text
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pAvailabilityZones_
    }

-- | The number of snapshots to be enabled with fast snapshot restore.
fastRestoreRule_count :: Lens.Lens' FastRestoreRule (Prelude.Maybe Prelude.Natural)
fastRestoreRule_count :: (Maybe Natural -> f (Maybe Natural))
-> FastRestoreRule -> f FastRestoreRule
fastRestoreRule_count = (FastRestoreRule -> Maybe Natural)
-> (FastRestoreRule -> Maybe Natural -> FastRestoreRule)
-> Lens
     FastRestoreRule FastRestoreRule (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FastRestoreRule' {Maybe Natural
count :: Maybe Natural
$sel:count:FastRestoreRule' :: FastRestoreRule -> Maybe Natural
count} -> Maybe Natural
count) (\s :: FastRestoreRule
s@FastRestoreRule' {} Maybe Natural
a -> FastRestoreRule
s {$sel:count:FastRestoreRule' :: Maybe Natural
count = Maybe Natural
a} :: FastRestoreRule)

-- | The amount of time to enable fast snapshot restore. The maximum is 100
-- years. This is equivalent to 1200 months, 5200 weeks, or 36500 days.
fastRestoreRule_interval :: Lens.Lens' FastRestoreRule (Prelude.Maybe Prelude.Natural)
fastRestoreRule_interval :: (Maybe Natural -> f (Maybe Natural))
-> FastRestoreRule -> f FastRestoreRule
fastRestoreRule_interval = (FastRestoreRule -> Maybe Natural)
-> (FastRestoreRule -> Maybe Natural -> FastRestoreRule)
-> Lens
     FastRestoreRule FastRestoreRule (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FastRestoreRule' {Maybe Natural
interval :: Maybe Natural
$sel:interval:FastRestoreRule' :: FastRestoreRule -> Maybe Natural
interval} -> Maybe Natural
interval) (\s :: FastRestoreRule
s@FastRestoreRule' {} Maybe Natural
a -> FastRestoreRule
s {$sel:interval:FastRestoreRule' :: Maybe Natural
interval = Maybe Natural
a} :: FastRestoreRule)

-- | The unit of time for enabling fast snapshot restore.
fastRestoreRule_intervalUnit :: Lens.Lens' FastRestoreRule (Prelude.Maybe RetentionIntervalUnitValues)
fastRestoreRule_intervalUnit :: (Maybe RetentionIntervalUnitValues
 -> f (Maybe RetentionIntervalUnitValues))
-> FastRestoreRule -> f FastRestoreRule
fastRestoreRule_intervalUnit = (FastRestoreRule -> Maybe RetentionIntervalUnitValues)
-> (FastRestoreRule
    -> Maybe RetentionIntervalUnitValues -> FastRestoreRule)
-> Lens
     FastRestoreRule
     FastRestoreRule
     (Maybe RetentionIntervalUnitValues)
     (Maybe RetentionIntervalUnitValues)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FastRestoreRule' {Maybe RetentionIntervalUnitValues
intervalUnit :: Maybe RetentionIntervalUnitValues
$sel:intervalUnit:FastRestoreRule' :: FastRestoreRule -> Maybe RetentionIntervalUnitValues
intervalUnit} -> Maybe RetentionIntervalUnitValues
intervalUnit) (\s :: FastRestoreRule
s@FastRestoreRule' {} Maybe RetentionIntervalUnitValues
a -> FastRestoreRule
s {$sel:intervalUnit:FastRestoreRule' :: Maybe RetentionIntervalUnitValues
intervalUnit = Maybe RetentionIntervalUnitValues
a} :: FastRestoreRule)

-- | The Availability Zones in which to enable fast snapshot restore.
fastRestoreRule_availabilityZones :: Lens.Lens' FastRestoreRule (Prelude.NonEmpty Prelude.Text)
fastRestoreRule_availabilityZones :: (NonEmpty Text -> f (NonEmpty Text))
-> FastRestoreRule -> f FastRestoreRule
fastRestoreRule_availabilityZones = (FastRestoreRule -> NonEmpty Text)
-> (FastRestoreRule -> NonEmpty Text -> FastRestoreRule)
-> Lens
     FastRestoreRule FastRestoreRule (NonEmpty Text) (NonEmpty Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FastRestoreRule' {NonEmpty Text
availabilityZones :: NonEmpty Text
$sel:availabilityZones:FastRestoreRule' :: FastRestoreRule -> NonEmpty Text
availabilityZones} -> NonEmpty Text
availabilityZones) (\s :: FastRestoreRule
s@FastRestoreRule' {} NonEmpty Text
a -> FastRestoreRule
s {$sel:availabilityZones:FastRestoreRule' :: NonEmpty Text
availabilityZones = NonEmpty Text
a} :: FastRestoreRule) ((NonEmpty Text -> f (NonEmpty Text))
 -> FastRestoreRule -> f FastRestoreRule)
-> ((NonEmpty Text -> f (NonEmpty Text))
    -> NonEmpty Text -> f (NonEmpty Text))
-> (NonEmpty Text -> f (NonEmpty Text))
-> FastRestoreRule
-> f FastRestoreRule
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Text -> f (NonEmpty Text))
-> NonEmpty Text -> f (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON FastRestoreRule where
  parseJSON :: Value -> Parser FastRestoreRule
parseJSON =
    String
-> (Object -> Parser FastRestoreRule)
-> Value
-> Parser FastRestoreRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"FastRestoreRule"
      ( \Object
x ->
          Maybe Natural
-> Maybe Natural
-> Maybe RetentionIntervalUnitValues
-> NonEmpty Text
-> FastRestoreRule
FastRestoreRule'
            (Maybe Natural
 -> Maybe Natural
 -> Maybe RetentionIntervalUnitValues
 -> NonEmpty Text
 -> FastRestoreRule)
-> Parser (Maybe Natural)
-> Parser
     (Maybe Natural
      -> Maybe RetentionIntervalUnitValues
      -> NonEmpty Text
      -> FastRestoreRule)
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
"Count")
            Parser
  (Maybe Natural
   -> Maybe RetentionIntervalUnitValues
   -> NonEmpty Text
   -> FastRestoreRule)
-> Parser (Maybe Natural)
-> Parser
     (Maybe RetentionIntervalUnitValues
      -> NonEmpty Text -> FastRestoreRule)
forall (f :: * -> *) a b. Applicative f => 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
   -> NonEmpty Text -> FastRestoreRule)
-> Parser (Maybe RetentionIntervalUnitValues)
-> Parser (NonEmpty Text -> FastRestoreRule)
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")
            Parser (NonEmpty Text -> FastRestoreRule)
-> Parser (NonEmpty Text) -> Parser FastRestoreRule
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (NonEmpty Text)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"AvailabilityZones")
      )

instance Prelude.Hashable FastRestoreRule

instance Prelude.NFData FastRestoreRule

instance Core.ToJSON FastRestoreRule where
  toJSON :: FastRestoreRule -> Value
toJSON FastRestoreRule' {Maybe Natural
Maybe RetentionIntervalUnitValues
NonEmpty Text
availabilityZones :: NonEmpty Text
intervalUnit :: Maybe RetentionIntervalUnitValues
interval :: Maybe Natural
count :: Maybe Natural
$sel:availabilityZones:FastRestoreRule' :: FastRestoreRule -> NonEmpty Text
$sel:intervalUnit:FastRestoreRule' :: FastRestoreRule -> Maybe RetentionIntervalUnitValues
$sel:interval:FastRestoreRule' :: FastRestoreRule -> Maybe Natural
$sel:count:FastRestoreRule' :: FastRestoreRule -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Count" 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
count,
            (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,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"AvailabilityZones" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Text
availabilityZones)
          ]
      )