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

import qualified Amazonka.Core as Core
import Amazonka.DLM.Types.CrossRegionCopyAction
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Specifies an action for an event-based policy.
--
-- /See:/ 'newAction' smart constructor.
data Action = Action'
  { -- | A descriptive name for the action.
    Action -> Text
name :: Prelude.Text,
    -- | The rule for copying shared snapshots across Regions.
    Action -> [CrossRegionCopyAction]
crossRegionCopy :: [CrossRegionCopyAction]
  }
  deriving (Action -> Action -> Bool
(Action -> Action -> Bool)
-> (Action -> Action -> Bool) -> Eq Action
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Action -> Action -> Bool
$c/= :: Action -> Action -> Bool
== :: Action -> Action -> Bool
$c== :: Action -> Action -> Bool
Prelude.Eq, ReadPrec [Action]
ReadPrec Action
Int -> ReadS Action
ReadS [Action]
(Int -> ReadS Action)
-> ReadS [Action]
-> ReadPrec Action
-> ReadPrec [Action]
-> Read Action
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Action]
$creadListPrec :: ReadPrec [Action]
readPrec :: ReadPrec Action
$creadPrec :: ReadPrec Action
readList :: ReadS [Action]
$creadList :: ReadS [Action]
readsPrec :: Int -> ReadS Action
$creadsPrec :: Int -> ReadS Action
Prelude.Read, Int -> Action -> ShowS
[Action] -> ShowS
Action -> String
(Int -> Action -> ShowS)
-> (Action -> String) -> ([Action] -> ShowS) -> Show Action
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Action] -> ShowS
$cshowList :: [Action] -> ShowS
show :: Action -> String
$cshow :: Action -> String
showsPrec :: Int -> Action -> ShowS
$cshowsPrec :: Int -> Action -> ShowS
Prelude.Show, (forall x. Action -> Rep Action x)
-> (forall x. Rep Action x -> Action) -> Generic Action
forall x. Rep Action x -> Action
forall x. Action -> Rep Action x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Action x -> Action
$cfrom :: forall x. Action -> Rep Action x
Prelude.Generic)

-- |
-- Create a value of 'Action' 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:
--
-- 'name', 'action_name' - A descriptive name for the action.
--
-- 'crossRegionCopy', 'action_crossRegionCopy' - The rule for copying shared snapshots across Regions.
newAction ::
  -- | 'name'
  Prelude.Text ->
  Action
newAction :: Text -> Action
newAction Text
pName_ =
  Action' :: Text -> [CrossRegionCopyAction] -> Action
Action'
    { $sel:name:Action' :: Text
name = Text
pName_,
      $sel:crossRegionCopy:Action' :: [CrossRegionCopyAction]
crossRegionCopy = [CrossRegionCopyAction]
forall a. Monoid a => a
Prelude.mempty
    }

-- | A descriptive name for the action.
action_name :: Lens.Lens' Action Prelude.Text
action_name :: (Text -> f Text) -> Action -> f Action
action_name = (Action -> Text)
-> (Action -> Text -> Action) -> Lens Action Action Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Action' {Text
name :: Text
$sel:name:Action' :: Action -> Text
name} -> Text
name) (\s :: Action
s@Action' {} Text
a -> Action
s {$sel:name:Action' :: Text
name = Text
a} :: Action)

-- | The rule for copying shared snapshots across Regions.
action_crossRegionCopy :: Lens.Lens' Action [CrossRegionCopyAction]
action_crossRegionCopy :: ([CrossRegionCopyAction] -> f [CrossRegionCopyAction])
-> Action -> f Action
action_crossRegionCopy = (Action -> [CrossRegionCopyAction])
-> (Action -> [CrossRegionCopyAction] -> Action)
-> Lens
     Action Action [CrossRegionCopyAction] [CrossRegionCopyAction]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Action' {[CrossRegionCopyAction]
crossRegionCopy :: [CrossRegionCopyAction]
$sel:crossRegionCopy:Action' :: Action -> [CrossRegionCopyAction]
crossRegionCopy} -> [CrossRegionCopyAction]
crossRegionCopy) (\s :: Action
s@Action' {} [CrossRegionCopyAction]
a -> Action
s {$sel:crossRegionCopy:Action' :: [CrossRegionCopyAction]
crossRegionCopy = [CrossRegionCopyAction]
a} :: Action) (([CrossRegionCopyAction] -> f [CrossRegionCopyAction])
 -> Action -> f Action)
-> (([CrossRegionCopyAction] -> f [CrossRegionCopyAction])
    -> [CrossRegionCopyAction] -> f [CrossRegionCopyAction])
-> ([CrossRegionCopyAction] -> f [CrossRegionCopyAction])
-> Action
-> f Action
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([CrossRegionCopyAction] -> f [CrossRegionCopyAction])
-> [CrossRegionCopyAction] -> f [CrossRegionCopyAction]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON Action where
  parseJSON :: Value -> Parser Action
parseJSON =
    String -> (Object -> Parser Action) -> Value -> Parser Action
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Action"
      ( \Object
x ->
          Text -> [CrossRegionCopyAction] -> Action
Action'
            (Text -> [CrossRegionCopyAction] -> Action)
-> Parser Text -> Parser ([CrossRegionCopyAction] -> Action)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Name")
            Parser ([CrossRegionCopyAction] -> Action)
-> Parser [CrossRegionCopyAction] -> Parser Action
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe [CrossRegionCopyAction])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"CrossRegionCopy"
                            Parser (Maybe [CrossRegionCopyAction])
-> [CrossRegionCopyAction] -> Parser [CrossRegionCopyAction]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [CrossRegionCopyAction]
forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable Action

instance Prelude.NFData Action

instance Core.ToJSON Action where
  toJSON :: Action -> Value
toJSON Action' {[CrossRegionCopyAction]
Text
crossRegionCopy :: [CrossRegionCopyAction]
name :: Text
$sel:crossRegionCopy:Action' :: Action -> [CrossRegionCopyAction]
$sel:name:Action' :: Action -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"CrossRegionCopy" Text -> [CrossRegionCopyAction] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [CrossRegionCopyAction]
crossRegionCopy)
          ]
      )