{-# 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-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.FastRestoreRule 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

-- | __[Snapshot policies only]__ Specifies a rule for enabling fast snapshot
-- restore for snapshots created by snapshot policies. 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
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]
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
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. 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'
    { $sel:count:FastRestoreRule' :: Maybe Natural
count = forall a. Maybe a
Prelude.Nothing,
      $sel:interval:FastRestoreRule' :: Maybe Natural
interval = forall a. Maybe a
Prelude.Nothing,
      $sel:intervalUnit:FastRestoreRule' :: Maybe RetentionIntervalUnitValues
intervalUnit = forall a. Maybe a
Prelude.Nothing,
      $sel:availabilityZones:FastRestoreRule' :: NonEmpty Text
availabilityZones =
        forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced 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 :: Lens' FastRestoreRule (Maybe Natural)
fastRestoreRule_count = 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 :: Lens' FastRestoreRule (Maybe Natural)
fastRestoreRule_interval = 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 :: Lens' FastRestoreRule (Maybe RetentionIntervalUnitValues)
fastRestoreRule_intervalUnit = 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 :: Lens' FastRestoreRule (NonEmpty Text)
fastRestoreRule_availabilityZones = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable FastRestoreRule where
  hashWithSalt :: Int -> FastRestoreRule -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
count
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
interval
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe RetentionIntervalUnitValues
intervalUnit
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
availabilityZones

instance Prelude.NFData FastRestoreRule where
  rnf :: FastRestoreRule -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
count
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Text
availabilityZones

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Count" 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
count,
            (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,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"AvailabilityZones" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
availabilityZones)
          ]
      )