{-# 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.CreateRule
-- 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.CreateRule where

import qualified Amazonka.Core as Core
import Amazonka.DLM.Types.IntervalUnitValues
import Amazonka.DLM.Types.LocationValues
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Specifies when to create snapshots of EBS volumes.
--
-- You must specify either a Cron expression or an interval, interval unit,
-- and start time. You cannot specify both.
--
-- /See:/ 'newCreateRule' smart constructor.
data CreateRule = CreateRule'
  { -- | Specifies the destination for snapshots created by the policy. To create
    -- snapshots in the same Region as the source resource, specify @CLOUD@. To
    -- create snapshots on the same Outpost as the source resource, specify
    -- @OUTPOST_LOCAL@. If you omit this parameter, @CLOUD@ is used by default.
    --
    -- If the policy targets resources in an Amazon Web Services Region, then
    -- you must create snapshots in the same Region as the source resource.
    --
    -- If the policy targets resources on an Outpost, then you can create
    -- snapshots on the same Outpost as the source resource, or in the Region
    -- of that Outpost.
    CreateRule -> Maybe LocationValues
location :: Prelude.Maybe LocationValues,
    -- | The interval between snapshots. The supported values are 1, 2, 3, 4, 6,
    -- 8, 12, and 24.
    CreateRule -> Maybe Natural
interval :: Prelude.Maybe Prelude.Natural,
    -- | The schedule, as a Cron expression. The schedule interval must be
    -- between 1 hour and 1 year. For more information, see
    -- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html#CronExpressions Cron expressions>
    -- in the /Amazon CloudWatch User Guide/.
    CreateRule -> Maybe Text
cronExpression :: Prelude.Maybe Prelude.Text,
    -- | The time, in UTC, to start the operation. The supported format is hh:mm.
    --
    -- The operation occurs within a one-hour window following the specified
    -- time. If you do not specify a time, Amazon DLM selects a time within the
    -- next 24 hours.
    CreateRule -> Maybe [Text]
times :: Prelude.Maybe [Prelude.Text],
    -- | The interval unit.
    CreateRule -> Maybe IntervalUnitValues
intervalUnit :: Prelude.Maybe IntervalUnitValues
  }
  deriving (CreateRule -> CreateRule -> Bool
(CreateRule -> CreateRule -> Bool)
-> (CreateRule -> CreateRule -> Bool) -> Eq CreateRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateRule -> CreateRule -> Bool
$c/= :: CreateRule -> CreateRule -> Bool
== :: CreateRule -> CreateRule -> Bool
$c== :: CreateRule -> CreateRule -> Bool
Prelude.Eq, ReadPrec [CreateRule]
ReadPrec CreateRule
Int -> ReadS CreateRule
ReadS [CreateRule]
(Int -> ReadS CreateRule)
-> ReadS [CreateRule]
-> ReadPrec CreateRule
-> ReadPrec [CreateRule]
-> Read CreateRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateRule]
$creadListPrec :: ReadPrec [CreateRule]
readPrec :: ReadPrec CreateRule
$creadPrec :: ReadPrec CreateRule
readList :: ReadS [CreateRule]
$creadList :: ReadS [CreateRule]
readsPrec :: Int -> ReadS CreateRule
$creadsPrec :: Int -> ReadS CreateRule
Prelude.Read, Int -> CreateRule -> ShowS
[CreateRule] -> ShowS
CreateRule -> String
(Int -> CreateRule -> ShowS)
-> (CreateRule -> String)
-> ([CreateRule] -> ShowS)
-> Show CreateRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateRule] -> ShowS
$cshowList :: [CreateRule] -> ShowS
show :: CreateRule -> String
$cshow :: CreateRule -> String
showsPrec :: Int -> CreateRule -> ShowS
$cshowsPrec :: Int -> CreateRule -> ShowS
Prelude.Show, (forall x. CreateRule -> Rep CreateRule x)
-> (forall x. Rep CreateRule x -> CreateRule) -> Generic CreateRule
forall x. Rep CreateRule x -> CreateRule
forall x. CreateRule -> Rep CreateRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateRule x -> CreateRule
$cfrom :: forall x. CreateRule -> Rep CreateRule x
Prelude.Generic)

-- |
-- Create a value of 'CreateRule' 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:
--
-- 'location', 'createRule_location' - Specifies the destination for snapshots created by the policy. To create
-- snapshots in the same Region as the source resource, specify @CLOUD@. To
-- create snapshots on the same Outpost as the source resource, specify
-- @OUTPOST_LOCAL@. If you omit this parameter, @CLOUD@ is used by default.
--
-- If the policy targets resources in an Amazon Web Services Region, then
-- you must create snapshots in the same Region as the source resource.
--
-- If the policy targets resources on an Outpost, then you can create
-- snapshots on the same Outpost as the source resource, or in the Region
-- of that Outpost.
--
-- 'interval', 'createRule_interval' - The interval between snapshots. The supported values are 1, 2, 3, 4, 6,
-- 8, 12, and 24.
--
-- 'cronExpression', 'createRule_cronExpression' - The schedule, as a Cron expression. The schedule interval must be
-- between 1 hour and 1 year. For more information, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html#CronExpressions Cron expressions>
-- in the /Amazon CloudWatch User Guide/.
--
-- 'times', 'createRule_times' - The time, in UTC, to start the operation. The supported format is hh:mm.
--
-- The operation occurs within a one-hour window following the specified
-- time. If you do not specify a time, Amazon DLM selects a time within the
-- next 24 hours.
--
-- 'intervalUnit', 'createRule_intervalUnit' - The interval unit.
newCreateRule ::
  CreateRule
newCreateRule :: CreateRule
newCreateRule =
  CreateRule' :: Maybe LocationValues
-> Maybe Natural
-> Maybe Text
-> Maybe [Text]
-> Maybe IntervalUnitValues
-> CreateRule
CreateRule'
    { $sel:location:CreateRule' :: Maybe LocationValues
location = Maybe LocationValues
forall a. Maybe a
Prelude.Nothing,
      $sel:interval:CreateRule' :: Maybe Natural
interval = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:cronExpression:CreateRule' :: Maybe Text
cronExpression = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:times:CreateRule' :: Maybe [Text]
times = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:intervalUnit:CreateRule' :: Maybe IntervalUnitValues
intervalUnit = Maybe IntervalUnitValues
forall a. Maybe a
Prelude.Nothing
    }

-- | Specifies the destination for snapshots created by the policy. To create
-- snapshots in the same Region as the source resource, specify @CLOUD@. To
-- create snapshots on the same Outpost as the source resource, specify
-- @OUTPOST_LOCAL@. If you omit this parameter, @CLOUD@ is used by default.
--
-- If the policy targets resources in an Amazon Web Services Region, then
-- you must create snapshots in the same Region as the source resource.
--
-- If the policy targets resources on an Outpost, then you can create
-- snapshots on the same Outpost as the source resource, or in the Region
-- of that Outpost.
createRule_location :: Lens.Lens' CreateRule (Prelude.Maybe LocationValues)
createRule_location :: (Maybe LocationValues -> f (Maybe LocationValues))
-> CreateRule -> f CreateRule
createRule_location = (CreateRule -> Maybe LocationValues)
-> (CreateRule -> Maybe LocationValues -> CreateRule)
-> Lens
     CreateRule CreateRule (Maybe LocationValues) (Maybe LocationValues)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateRule' {Maybe LocationValues
location :: Maybe LocationValues
$sel:location:CreateRule' :: CreateRule -> Maybe LocationValues
location} -> Maybe LocationValues
location) (\s :: CreateRule
s@CreateRule' {} Maybe LocationValues
a -> CreateRule
s {$sel:location:CreateRule' :: Maybe LocationValues
location = Maybe LocationValues
a} :: CreateRule)

-- | The interval between snapshots. The supported values are 1, 2, 3, 4, 6,
-- 8, 12, and 24.
createRule_interval :: Lens.Lens' CreateRule (Prelude.Maybe Prelude.Natural)
createRule_interval :: (Maybe Natural -> f (Maybe Natural)) -> CreateRule -> f CreateRule
createRule_interval = (CreateRule -> Maybe Natural)
-> (CreateRule -> Maybe Natural -> CreateRule)
-> Lens CreateRule CreateRule (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateRule' {Maybe Natural
interval :: Maybe Natural
$sel:interval:CreateRule' :: CreateRule -> Maybe Natural
interval} -> Maybe Natural
interval) (\s :: CreateRule
s@CreateRule' {} Maybe Natural
a -> CreateRule
s {$sel:interval:CreateRule' :: Maybe Natural
interval = Maybe Natural
a} :: CreateRule)

-- | The schedule, as a Cron expression. The schedule interval must be
-- between 1 hour and 1 year. For more information, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html#CronExpressions Cron expressions>
-- in the /Amazon CloudWatch User Guide/.
createRule_cronExpression :: Lens.Lens' CreateRule (Prelude.Maybe Prelude.Text)
createRule_cronExpression :: (Maybe Text -> f (Maybe Text)) -> CreateRule -> f CreateRule
createRule_cronExpression = (CreateRule -> Maybe Text)
-> (CreateRule -> Maybe Text -> CreateRule)
-> Lens CreateRule CreateRule (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateRule' {Maybe Text
cronExpression :: Maybe Text
$sel:cronExpression:CreateRule' :: CreateRule -> Maybe Text
cronExpression} -> Maybe Text
cronExpression) (\s :: CreateRule
s@CreateRule' {} Maybe Text
a -> CreateRule
s {$sel:cronExpression:CreateRule' :: Maybe Text
cronExpression = Maybe Text
a} :: CreateRule)

-- | The time, in UTC, to start the operation. The supported format is hh:mm.
--
-- The operation occurs within a one-hour window following the specified
-- time. If you do not specify a time, Amazon DLM selects a time within the
-- next 24 hours.
createRule_times :: Lens.Lens' CreateRule (Prelude.Maybe [Prelude.Text])
createRule_times :: (Maybe [Text] -> f (Maybe [Text])) -> CreateRule -> f CreateRule
createRule_times = (CreateRule -> Maybe [Text])
-> (CreateRule -> Maybe [Text] -> CreateRule)
-> Lens CreateRule CreateRule (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateRule' {Maybe [Text]
times :: Maybe [Text]
$sel:times:CreateRule' :: CreateRule -> Maybe [Text]
times} -> Maybe [Text]
times) (\s :: CreateRule
s@CreateRule' {} Maybe [Text]
a -> CreateRule
s {$sel:times:CreateRule' :: Maybe [Text]
times = Maybe [Text]
a} :: CreateRule) ((Maybe [Text] -> f (Maybe [Text])) -> CreateRule -> f CreateRule)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> CreateRule
-> f CreateRule
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The interval unit.
createRule_intervalUnit :: Lens.Lens' CreateRule (Prelude.Maybe IntervalUnitValues)
createRule_intervalUnit :: (Maybe IntervalUnitValues -> f (Maybe IntervalUnitValues))
-> CreateRule -> f CreateRule
createRule_intervalUnit = (CreateRule -> Maybe IntervalUnitValues)
-> (CreateRule -> Maybe IntervalUnitValues -> CreateRule)
-> Lens
     CreateRule
     CreateRule
     (Maybe IntervalUnitValues)
     (Maybe IntervalUnitValues)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateRule' {Maybe IntervalUnitValues
intervalUnit :: Maybe IntervalUnitValues
$sel:intervalUnit:CreateRule' :: CreateRule -> Maybe IntervalUnitValues
intervalUnit} -> Maybe IntervalUnitValues
intervalUnit) (\s :: CreateRule
s@CreateRule' {} Maybe IntervalUnitValues
a -> CreateRule
s {$sel:intervalUnit:CreateRule' :: Maybe IntervalUnitValues
intervalUnit = Maybe IntervalUnitValues
a} :: CreateRule)

instance Core.FromJSON CreateRule where
  parseJSON :: Value -> Parser CreateRule
parseJSON =
    String
-> (Object -> Parser CreateRule) -> Value -> Parser CreateRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CreateRule"
      ( \Object
x ->
          Maybe LocationValues
-> Maybe Natural
-> Maybe Text
-> Maybe [Text]
-> Maybe IntervalUnitValues
-> CreateRule
CreateRule'
            (Maybe LocationValues
 -> Maybe Natural
 -> Maybe Text
 -> Maybe [Text]
 -> Maybe IntervalUnitValues
 -> CreateRule)
-> Parser (Maybe LocationValues)
-> Parser
     (Maybe Natural
      -> Maybe Text
      -> Maybe [Text]
      -> Maybe IntervalUnitValues
      -> CreateRule)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe LocationValues)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Location")
            Parser
  (Maybe Natural
   -> Maybe Text
   -> Maybe [Text]
   -> Maybe IntervalUnitValues
   -> CreateRule)
-> Parser (Maybe Natural)
-> Parser
     (Maybe Text
      -> Maybe [Text] -> Maybe IntervalUnitValues -> CreateRule)
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 Text
   -> Maybe [Text] -> Maybe IntervalUnitValues -> CreateRule)
-> Parser (Maybe Text)
-> Parser (Maybe [Text] -> Maybe IntervalUnitValues -> CreateRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"CronExpression")
            Parser (Maybe [Text] -> Maybe IntervalUnitValues -> CreateRule)
-> Parser (Maybe [Text])
-> Parser (Maybe IntervalUnitValues -> CreateRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Times" Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe IntervalUnitValues -> CreateRule)
-> Parser (Maybe IntervalUnitValues) -> Parser CreateRule
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe IntervalUnitValues)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"IntervalUnit")
      )

instance Prelude.Hashable CreateRule

instance Prelude.NFData CreateRule

instance Core.ToJSON CreateRule where
  toJSON :: CreateRule -> Value
toJSON CreateRule' {Maybe Natural
Maybe [Text]
Maybe Text
Maybe IntervalUnitValues
Maybe LocationValues
intervalUnit :: Maybe IntervalUnitValues
times :: Maybe [Text]
cronExpression :: Maybe Text
interval :: Maybe Natural
location :: Maybe LocationValues
$sel:intervalUnit:CreateRule' :: CreateRule -> Maybe IntervalUnitValues
$sel:times:CreateRule' :: CreateRule -> Maybe [Text]
$sel:cronExpression:CreateRule' :: CreateRule -> Maybe Text
$sel:interval:CreateRule' :: CreateRule -> Maybe Natural
$sel:location:CreateRule' :: CreateRule -> Maybe LocationValues
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Location" Text -> LocationValues -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (LocationValues -> Pair) -> Maybe LocationValues -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe LocationValues
location,
            (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
"CronExpression" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
cronExpression,
            (Text
"Times" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Text] -> Pair) -> Maybe [Text] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
times,
            (Text
"IntervalUnit" Text -> IntervalUnitValues -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (IntervalUnitValues -> Pair)
-> Maybe IntervalUnitValues -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe IntervalUnitValues
intervalUnit
          ]
      )