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

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

-- | Specifies an event that triggers an event-based policy.
--
-- /See:/ 'newEventParameters' smart constructor.
data EventParameters = EventParameters'
  { -- | The type of event. Currently, only snapshot sharing events are
    -- supported.
    EventParameters -> EventTypeValues
eventType :: EventTypeValues,
    -- | The IDs of the Amazon Web Services accounts that can trigger policy by
    -- sharing snapshots with your account. The policy only runs if one of the
    -- specified Amazon Web Services accounts shares a snapshot with your
    -- account.
    EventParameters -> [Text]
snapshotOwner :: [Prelude.Text],
    -- | The snapshot description that can trigger the policy. The description
    -- pattern is specified using a regular expression. The policy runs only if
    -- a snapshot with a description that matches the specified pattern is
    -- shared with your account.
    --
    -- For example, specifying
    -- @^.*Created for policy: policy-1234567890abcdef0.*$@ configures the
    -- policy to run only if snapshots created by policy
    -- @policy-1234567890abcdef0@ are shared with your account.
    EventParameters -> Text
descriptionRegex :: Prelude.Text
  }
  deriving (EventParameters -> EventParameters -> Bool
(EventParameters -> EventParameters -> Bool)
-> (EventParameters -> EventParameters -> Bool)
-> Eq EventParameters
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EventParameters -> EventParameters -> Bool
$c/= :: EventParameters -> EventParameters -> Bool
== :: EventParameters -> EventParameters -> Bool
$c== :: EventParameters -> EventParameters -> Bool
Prelude.Eq, ReadPrec [EventParameters]
ReadPrec EventParameters
Int -> ReadS EventParameters
ReadS [EventParameters]
(Int -> ReadS EventParameters)
-> ReadS [EventParameters]
-> ReadPrec EventParameters
-> ReadPrec [EventParameters]
-> Read EventParameters
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EventParameters]
$creadListPrec :: ReadPrec [EventParameters]
readPrec :: ReadPrec EventParameters
$creadPrec :: ReadPrec EventParameters
readList :: ReadS [EventParameters]
$creadList :: ReadS [EventParameters]
readsPrec :: Int -> ReadS EventParameters
$creadsPrec :: Int -> ReadS EventParameters
Prelude.Read, Int -> EventParameters -> ShowS
[EventParameters] -> ShowS
EventParameters -> String
(Int -> EventParameters -> ShowS)
-> (EventParameters -> String)
-> ([EventParameters] -> ShowS)
-> Show EventParameters
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EventParameters] -> ShowS
$cshowList :: [EventParameters] -> ShowS
show :: EventParameters -> String
$cshow :: EventParameters -> String
showsPrec :: Int -> EventParameters -> ShowS
$cshowsPrec :: Int -> EventParameters -> ShowS
Prelude.Show, (forall x. EventParameters -> Rep EventParameters x)
-> (forall x. Rep EventParameters x -> EventParameters)
-> Generic EventParameters
forall x. Rep EventParameters x -> EventParameters
forall x. EventParameters -> Rep EventParameters x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EventParameters x -> EventParameters
$cfrom :: forall x. EventParameters -> Rep EventParameters x
Prelude.Generic)

-- |
-- Create a value of 'EventParameters' 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:
--
-- 'eventType', 'eventParameters_eventType' - The type of event. Currently, only snapshot sharing events are
-- supported.
--
-- 'snapshotOwner', 'eventParameters_snapshotOwner' - The IDs of the Amazon Web Services accounts that can trigger policy by
-- sharing snapshots with your account. The policy only runs if one of the
-- specified Amazon Web Services accounts shares a snapshot with your
-- account.
--
-- 'descriptionRegex', 'eventParameters_descriptionRegex' - The snapshot description that can trigger the policy. The description
-- pattern is specified using a regular expression. The policy runs only if
-- a snapshot with a description that matches the specified pattern is
-- shared with your account.
--
-- For example, specifying
-- @^.*Created for policy: policy-1234567890abcdef0.*$@ configures the
-- policy to run only if snapshots created by policy
-- @policy-1234567890abcdef0@ are shared with your account.
newEventParameters ::
  -- | 'eventType'
  EventTypeValues ->
  -- | 'descriptionRegex'
  Prelude.Text ->
  EventParameters
newEventParameters :: EventTypeValues -> Text -> EventParameters
newEventParameters EventTypeValues
pEventType_ Text
pDescriptionRegex_ =
  EventParameters' :: EventTypeValues -> [Text] -> Text -> EventParameters
EventParameters'
    { $sel:eventType:EventParameters' :: EventTypeValues
eventType = EventTypeValues
pEventType_,
      $sel:snapshotOwner:EventParameters' :: [Text]
snapshotOwner = [Text]
forall a. Monoid a => a
Prelude.mempty,
      $sel:descriptionRegex:EventParameters' :: Text
descriptionRegex = Text
pDescriptionRegex_
    }

-- | The type of event. Currently, only snapshot sharing events are
-- supported.
eventParameters_eventType :: Lens.Lens' EventParameters EventTypeValues
eventParameters_eventType :: (EventTypeValues -> f EventTypeValues)
-> EventParameters -> f EventParameters
eventParameters_eventType = (EventParameters -> EventTypeValues)
-> (EventParameters -> EventTypeValues -> EventParameters)
-> Lens
     EventParameters EventParameters EventTypeValues EventTypeValues
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventParameters' {EventTypeValues
eventType :: EventTypeValues
$sel:eventType:EventParameters' :: EventParameters -> EventTypeValues
eventType} -> EventTypeValues
eventType) (\s :: EventParameters
s@EventParameters' {} EventTypeValues
a -> EventParameters
s {$sel:eventType:EventParameters' :: EventTypeValues
eventType = EventTypeValues
a} :: EventParameters)

-- | The IDs of the Amazon Web Services accounts that can trigger policy by
-- sharing snapshots with your account. The policy only runs if one of the
-- specified Amazon Web Services accounts shares a snapshot with your
-- account.
eventParameters_snapshotOwner :: Lens.Lens' EventParameters [Prelude.Text]
eventParameters_snapshotOwner :: ([Text] -> f [Text]) -> EventParameters -> f EventParameters
eventParameters_snapshotOwner = (EventParameters -> [Text])
-> (EventParameters -> [Text] -> EventParameters)
-> Lens EventParameters EventParameters [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventParameters' {[Text]
snapshotOwner :: [Text]
$sel:snapshotOwner:EventParameters' :: EventParameters -> [Text]
snapshotOwner} -> [Text]
snapshotOwner) (\s :: EventParameters
s@EventParameters' {} [Text]
a -> EventParameters
s {$sel:snapshotOwner:EventParameters' :: [Text]
snapshotOwner = [Text]
a} :: EventParameters) (([Text] -> f [Text]) -> EventParameters -> f EventParameters)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> EventParameters
-> f EventParameters
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The snapshot description that can trigger the policy. The description
-- pattern is specified using a regular expression. The policy runs only if
-- a snapshot with a description that matches the specified pattern is
-- shared with your account.
--
-- For example, specifying
-- @^.*Created for policy: policy-1234567890abcdef0.*$@ configures the
-- policy to run only if snapshots created by policy
-- @policy-1234567890abcdef0@ are shared with your account.
eventParameters_descriptionRegex :: Lens.Lens' EventParameters Prelude.Text
eventParameters_descriptionRegex :: (Text -> f Text) -> EventParameters -> f EventParameters
eventParameters_descriptionRegex = (EventParameters -> Text)
-> (EventParameters -> Text -> EventParameters)
-> Lens EventParameters EventParameters Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventParameters' {Text
descriptionRegex :: Text
$sel:descriptionRegex:EventParameters' :: EventParameters -> Text
descriptionRegex} -> Text
descriptionRegex) (\s :: EventParameters
s@EventParameters' {} Text
a -> EventParameters
s {$sel:descriptionRegex:EventParameters' :: Text
descriptionRegex = Text
a} :: EventParameters)

instance Core.FromJSON EventParameters where
  parseJSON :: Value -> Parser EventParameters
parseJSON =
    String
-> (Object -> Parser EventParameters)
-> Value
-> Parser EventParameters
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"EventParameters"
      ( \Object
x ->
          EventTypeValues -> [Text] -> Text -> EventParameters
EventParameters'
            (EventTypeValues -> [Text] -> Text -> EventParameters)
-> Parser EventTypeValues
-> Parser ([Text] -> Text -> EventParameters)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser EventTypeValues
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"EventType")
            Parser ([Text] -> Text -> EventParameters)
-> Parser [Text] -> Parser (Text -> EventParameters)
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
"SnapshotOwner" Parser (Maybe [Text]) -> [Text] -> Parser [Text]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Text -> EventParameters)
-> Parser Text -> Parser EventParameters
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
"DescriptionRegex")
      )

instance Prelude.Hashable EventParameters

instance Prelude.NFData EventParameters

instance Core.ToJSON EventParameters where
  toJSON :: EventParameters -> Value
toJSON EventParameters' {[Text]
Text
EventTypeValues
descriptionRegex :: Text
snapshotOwner :: [Text]
eventType :: EventTypeValues
$sel:descriptionRegex:EventParameters' :: EventParameters -> Text
$sel:snapshotOwner:EventParameters' :: EventParameters -> [Text]
$sel:eventType:EventParameters' :: EventParameters -> EventTypeValues
..} =
    [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
"EventType" Text -> EventTypeValues -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= EventTypeValues
eventType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"SnapshotOwner" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
snapshotOwner),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"DescriptionRegex" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
descriptionRegex)
          ]
      )