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

import qualified Amazonka.Core as Core
import Amazonka.DLM.Types.CrossRegionCopyRetainRule
import Amazonka.DLM.Types.EncryptionConfiguration
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Specifies a rule for copying shared snapshots across Regions.
--
-- /See:/ 'newCrossRegionCopyAction' smart constructor.
data CrossRegionCopyAction = CrossRegionCopyAction'
  { CrossRegionCopyAction -> Maybe CrossRegionCopyRetainRule
retainRule :: Prelude.Maybe CrossRegionCopyRetainRule,
    -- | The target Region.
    CrossRegionCopyAction -> Text
target :: Prelude.Text,
    -- | The encryption settings for the copied snapshot.
    CrossRegionCopyAction -> EncryptionConfiguration
encryptionConfiguration :: EncryptionConfiguration
  }
  deriving (CrossRegionCopyAction -> CrossRegionCopyAction -> Bool
(CrossRegionCopyAction -> CrossRegionCopyAction -> Bool)
-> (CrossRegionCopyAction -> CrossRegionCopyAction -> Bool)
-> Eq CrossRegionCopyAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CrossRegionCopyAction -> CrossRegionCopyAction -> Bool
$c/= :: CrossRegionCopyAction -> CrossRegionCopyAction -> Bool
== :: CrossRegionCopyAction -> CrossRegionCopyAction -> Bool
$c== :: CrossRegionCopyAction -> CrossRegionCopyAction -> Bool
Prelude.Eq, ReadPrec [CrossRegionCopyAction]
ReadPrec CrossRegionCopyAction
Int -> ReadS CrossRegionCopyAction
ReadS [CrossRegionCopyAction]
(Int -> ReadS CrossRegionCopyAction)
-> ReadS [CrossRegionCopyAction]
-> ReadPrec CrossRegionCopyAction
-> ReadPrec [CrossRegionCopyAction]
-> Read CrossRegionCopyAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CrossRegionCopyAction]
$creadListPrec :: ReadPrec [CrossRegionCopyAction]
readPrec :: ReadPrec CrossRegionCopyAction
$creadPrec :: ReadPrec CrossRegionCopyAction
readList :: ReadS [CrossRegionCopyAction]
$creadList :: ReadS [CrossRegionCopyAction]
readsPrec :: Int -> ReadS CrossRegionCopyAction
$creadsPrec :: Int -> ReadS CrossRegionCopyAction
Prelude.Read, Int -> CrossRegionCopyAction -> ShowS
[CrossRegionCopyAction] -> ShowS
CrossRegionCopyAction -> String
(Int -> CrossRegionCopyAction -> ShowS)
-> (CrossRegionCopyAction -> String)
-> ([CrossRegionCopyAction] -> ShowS)
-> Show CrossRegionCopyAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CrossRegionCopyAction] -> ShowS
$cshowList :: [CrossRegionCopyAction] -> ShowS
show :: CrossRegionCopyAction -> String
$cshow :: CrossRegionCopyAction -> String
showsPrec :: Int -> CrossRegionCopyAction -> ShowS
$cshowsPrec :: Int -> CrossRegionCopyAction -> ShowS
Prelude.Show, (forall x. CrossRegionCopyAction -> Rep CrossRegionCopyAction x)
-> (forall x. Rep CrossRegionCopyAction x -> CrossRegionCopyAction)
-> Generic CrossRegionCopyAction
forall x. Rep CrossRegionCopyAction x -> CrossRegionCopyAction
forall x. CrossRegionCopyAction -> Rep CrossRegionCopyAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CrossRegionCopyAction x -> CrossRegionCopyAction
$cfrom :: forall x. CrossRegionCopyAction -> Rep CrossRegionCopyAction x
Prelude.Generic)

-- |
-- Create a value of 'CrossRegionCopyAction' 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:
--
-- 'retainRule', 'crossRegionCopyAction_retainRule' - Undocumented member.
--
-- 'target', 'crossRegionCopyAction_target' - The target Region.
--
-- 'encryptionConfiguration', 'crossRegionCopyAction_encryptionConfiguration' - The encryption settings for the copied snapshot.
newCrossRegionCopyAction ::
  -- | 'target'
  Prelude.Text ->
  -- | 'encryptionConfiguration'
  EncryptionConfiguration ->
  CrossRegionCopyAction
newCrossRegionCopyAction :: Text -> EncryptionConfiguration -> CrossRegionCopyAction
newCrossRegionCopyAction
  Text
pTarget_
  EncryptionConfiguration
pEncryptionConfiguration_ =
    CrossRegionCopyAction' :: Maybe CrossRegionCopyRetainRule
-> Text -> EncryptionConfiguration -> CrossRegionCopyAction
CrossRegionCopyAction'
      { $sel:retainRule:CrossRegionCopyAction' :: Maybe CrossRegionCopyRetainRule
retainRule =
          Maybe CrossRegionCopyRetainRule
forall a. Maybe a
Prelude.Nothing,
        $sel:target:CrossRegionCopyAction' :: Text
target = Text
pTarget_,
        $sel:encryptionConfiguration:CrossRegionCopyAction' :: EncryptionConfiguration
encryptionConfiguration = EncryptionConfiguration
pEncryptionConfiguration_
      }

-- | Undocumented member.
crossRegionCopyAction_retainRule :: Lens.Lens' CrossRegionCopyAction (Prelude.Maybe CrossRegionCopyRetainRule)
crossRegionCopyAction_retainRule :: (Maybe CrossRegionCopyRetainRule
 -> f (Maybe CrossRegionCopyRetainRule))
-> CrossRegionCopyAction -> f CrossRegionCopyAction
crossRegionCopyAction_retainRule = (CrossRegionCopyAction -> Maybe CrossRegionCopyRetainRule)
-> (CrossRegionCopyAction
    -> Maybe CrossRegionCopyRetainRule -> CrossRegionCopyAction)
-> Lens
     CrossRegionCopyAction
     CrossRegionCopyAction
     (Maybe CrossRegionCopyRetainRule)
     (Maybe CrossRegionCopyRetainRule)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CrossRegionCopyAction' {Maybe CrossRegionCopyRetainRule
retainRule :: Maybe CrossRegionCopyRetainRule
$sel:retainRule:CrossRegionCopyAction' :: CrossRegionCopyAction -> Maybe CrossRegionCopyRetainRule
retainRule} -> Maybe CrossRegionCopyRetainRule
retainRule) (\s :: CrossRegionCopyAction
s@CrossRegionCopyAction' {} Maybe CrossRegionCopyRetainRule
a -> CrossRegionCopyAction
s {$sel:retainRule:CrossRegionCopyAction' :: Maybe CrossRegionCopyRetainRule
retainRule = Maybe CrossRegionCopyRetainRule
a} :: CrossRegionCopyAction)

-- | The target Region.
crossRegionCopyAction_target :: Lens.Lens' CrossRegionCopyAction Prelude.Text
crossRegionCopyAction_target :: (Text -> f Text)
-> CrossRegionCopyAction -> f CrossRegionCopyAction
crossRegionCopyAction_target = (CrossRegionCopyAction -> Text)
-> (CrossRegionCopyAction -> Text -> CrossRegionCopyAction)
-> Lens CrossRegionCopyAction CrossRegionCopyAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CrossRegionCopyAction' {Text
target :: Text
$sel:target:CrossRegionCopyAction' :: CrossRegionCopyAction -> Text
target} -> Text
target) (\s :: CrossRegionCopyAction
s@CrossRegionCopyAction' {} Text
a -> CrossRegionCopyAction
s {$sel:target:CrossRegionCopyAction' :: Text
target = Text
a} :: CrossRegionCopyAction)

-- | The encryption settings for the copied snapshot.
crossRegionCopyAction_encryptionConfiguration :: Lens.Lens' CrossRegionCopyAction EncryptionConfiguration
crossRegionCopyAction_encryptionConfiguration :: (EncryptionConfiguration -> f EncryptionConfiguration)
-> CrossRegionCopyAction -> f CrossRegionCopyAction
crossRegionCopyAction_encryptionConfiguration = (CrossRegionCopyAction -> EncryptionConfiguration)
-> (CrossRegionCopyAction
    -> EncryptionConfiguration -> CrossRegionCopyAction)
-> Lens
     CrossRegionCopyAction
     CrossRegionCopyAction
     EncryptionConfiguration
     EncryptionConfiguration
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CrossRegionCopyAction' {EncryptionConfiguration
encryptionConfiguration :: EncryptionConfiguration
$sel:encryptionConfiguration:CrossRegionCopyAction' :: CrossRegionCopyAction -> EncryptionConfiguration
encryptionConfiguration} -> EncryptionConfiguration
encryptionConfiguration) (\s :: CrossRegionCopyAction
s@CrossRegionCopyAction' {} EncryptionConfiguration
a -> CrossRegionCopyAction
s {$sel:encryptionConfiguration:CrossRegionCopyAction' :: EncryptionConfiguration
encryptionConfiguration = EncryptionConfiguration
a} :: CrossRegionCopyAction)

instance Core.FromJSON CrossRegionCopyAction where
  parseJSON :: Value -> Parser CrossRegionCopyAction
parseJSON =
    String
-> (Object -> Parser CrossRegionCopyAction)
-> Value
-> Parser CrossRegionCopyAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CrossRegionCopyAction"
      ( \Object
x ->
          Maybe CrossRegionCopyRetainRule
-> Text -> EncryptionConfiguration -> CrossRegionCopyAction
CrossRegionCopyAction'
            (Maybe CrossRegionCopyRetainRule
 -> Text -> EncryptionConfiguration -> CrossRegionCopyAction)
-> Parser (Maybe CrossRegionCopyRetainRule)
-> Parser
     (Text -> EncryptionConfiguration -> CrossRegionCopyAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe CrossRegionCopyRetainRule)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"RetainRule")
            Parser (Text -> EncryptionConfiguration -> CrossRegionCopyAction)
-> Parser Text
-> Parser (EncryptionConfiguration -> CrossRegionCopyAction)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Target")
            Parser (EncryptionConfiguration -> CrossRegionCopyAction)
-> Parser EncryptionConfiguration -> Parser CrossRegionCopyAction
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser EncryptionConfiguration
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"EncryptionConfiguration")
      )

instance Prelude.Hashable CrossRegionCopyAction

instance Prelude.NFData CrossRegionCopyAction

instance Core.ToJSON CrossRegionCopyAction where
  toJSON :: CrossRegionCopyAction -> Value
toJSON CrossRegionCopyAction' {Maybe CrossRegionCopyRetainRule
Text
EncryptionConfiguration
encryptionConfiguration :: EncryptionConfiguration
target :: Text
retainRule :: Maybe CrossRegionCopyRetainRule
$sel:encryptionConfiguration:CrossRegionCopyAction' :: CrossRegionCopyAction -> EncryptionConfiguration
$sel:target:CrossRegionCopyAction' :: CrossRegionCopyAction -> Text
$sel:retainRule:CrossRegionCopyAction' :: CrossRegionCopyAction -> Maybe CrossRegionCopyRetainRule
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"RetainRule" Text -> CrossRegionCopyRetainRule -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (CrossRegionCopyRetainRule -> Pair)
-> Maybe CrossRegionCopyRetainRule -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe CrossRegionCopyRetainRule
retainRule,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Target" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
target),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"EncryptionConfiguration"
                  Text -> EncryptionConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= EncryptionConfiguration
encryptionConfiguration
              )
          ]
      )