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

import qualified Amazonka.Core as Core
import Amazonka.DLM.Types.EventParameters
import Amazonka.DLM.Types.EventSourceValues
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Specifies an event that triggers an event-based policy.
--
-- /See:/ 'newEventSource' smart constructor.
data EventSource = EventSource'
  { -- | Information about the event.
    EventSource -> Maybe EventParameters
parameters :: Prelude.Maybe EventParameters,
    -- | The source of the event. Currently only managed CloudWatch Events rules
    -- are supported.
    EventSource -> EventSourceValues
type' :: EventSourceValues
  }
  deriving (EventSource -> EventSource -> Bool
(EventSource -> EventSource -> Bool)
-> (EventSource -> EventSource -> Bool) -> Eq EventSource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EventSource -> EventSource -> Bool
$c/= :: EventSource -> EventSource -> Bool
== :: EventSource -> EventSource -> Bool
$c== :: EventSource -> EventSource -> Bool
Prelude.Eq, ReadPrec [EventSource]
ReadPrec EventSource
Int -> ReadS EventSource
ReadS [EventSource]
(Int -> ReadS EventSource)
-> ReadS [EventSource]
-> ReadPrec EventSource
-> ReadPrec [EventSource]
-> Read EventSource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EventSource]
$creadListPrec :: ReadPrec [EventSource]
readPrec :: ReadPrec EventSource
$creadPrec :: ReadPrec EventSource
readList :: ReadS [EventSource]
$creadList :: ReadS [EventSource]
readsPrec :: Int -> ReadS EventSource
$creadsPrec :: Int -> ReadS EventSource
Prelude.Read, Int -> EventSource -> ShowS
[EventSource] -> ShowS
EventSource -> String
(Int -> EventSource -> ShowS)
-> (EventSource -> String)
-> ([EventSource] -> ShowS)
-> Show EventSource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EventSource] -> ShowS
$cshowList :: [EventSource] -> ShowS
show :: EventSource -> String
$cshow :: EventSource -> String
showsPrec :: Int -> EventSource -> ShowS
$cshowsPrec :: Int -> EventSource -> ShowS
Prelude.Show, (forall x. EventSource -> Rep EventSource x)
-> (forall x. Rep EventSource x -> EventSource)
-> Generic EventSource
forall x. Rep EventSource x -> EventSource
forall x. EventSource -> Rep EventSource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EventSource x -> EventSource
$cfrom :: forall x. EventSource -> Rep EventSource x
Prelude.Generic)

-- |
-- Create a value of 'EventSource' 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:
--
-- 'parameters', 'eventSource_parameters' - Information about the event.
--
-- 'type'', 'eventSource_type' - The source of the event. Currently only managed CloudWatch Events rules
-- are supported.
newEventSource ::
  -- | 'type''
  EventSourceValues ->
  EventSource
newEventSource :: EventSourceValues -> EventSource
newEventSource EventSourceValues
pType_ =
  EventSource' :: Maybe EventParameters -> EventSourceValues -> EventSource
EventSource'
    { $sel:parameters:EventSource' :: Maybe EventParameters
parameters = Maybe EventParameters
forall a. Maybe a
Prelude.Nothing,
      $sel:type':EventSource' :: EventSourceValues
type' = EventSourceValues
pType_
    }

-- | Information about the event.
eventSource_parameters :: Lens.Lens' EventSource (Prelude.Maybe EventParameters)
eventSource_parameters :: (Maybe EventParameters -> f (Maybe EventParameters))
-> EventSource -> f EventSource
eventSource_parameters = (EventSource -> Maybe EventParameters)
-> (EventSource -> Maybe EventParameters -> EventSource)
-> Lens
     EventSource
     EventSource
     (Maybe EventParameters)
     (Maybe EventParameters)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventSource' {Maybe EventParameters
parameters :: Maybe EventParameters
$sel:parameters:EventSource' :: EventSource -> Maybe EventParameters
parameters} -> Maybe EventParameters
parameters) (\s :: EventSource
s@EventSource' {} Maybe EventParameters
a -> EventSource
s {$sel:parameters:EventSource' :: Maybe EventParameters
parameters = Maybe EventParameters
a} :: EventSource)

-- | The source of the event. Currently only managed CloudWatch Events rules
-- are supported.
eventSource_type :: Lens.Lens' EventSource EventSourceValues
eventSource_type :: (EventSourceValues -> f EventSourceValues)
-> EventSource -> f EventSource
eventSource_type = (EventSource -> EventSourceValues)
-> (EventSource -> EventSourceValues -> EventSource)
-> Lens EventSource EventSource EventSourceValues EventSourceValues
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventSource' {EventSourceValues
type' :: EventSourceValues
$sel:type':EventSource' :: EventSource -> EventSourceValues
type'} -> EventSourceValues
type') (\s :: EventSource
s@EventSource' {} EventSourceValues
a -> EventSource
s {$sel:type':EventSource' :: EventSourceValues
type' = EventSourceValues
a} :: EventSource)

instance Core.FromJSON EventSource where
  parseJSON :: Value -> Parser EventSource
parseJSON =
    String
-> (Object -> Parser EventSource) -> Value -> Parser EventSource
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"EventSource"
      ( \Object
x ->
          Maybe EventParameters -> EventSourceValues -> EventSource
EventSource'
            (Maybe EventParameters -> EventSourceValues -> EventSource)
-> Parser (Maybe EventParameters)
-> Parser (EventSourceValues -> EventSource)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe EventParameters)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Parameters")
            Parser (EventSourceValues -> EventSource)
-> Parser EventSourceValues -> Parser EventSource
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser EventSourceValues
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Type")
      )

instance Prelude.Hashable EventSource

instance Prelude.NFData EventSource

instance Core.ToJSON EventSource where
  toJSON :: EventSource -> Value
toJSON EventSource' {Maybe EventParameters
EventSourceValues
type' :: EventSourceValues
parameters :: Maybe EventParameters
$sel:type':EventSource' :: EventSource -> EventSourceValues
$sel:parameters:EventSource' :: EventSource -> Maybe EventParameters
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Parameters" Text -> EventParameters -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (EventParameters -> Pair) -> Maybe EventParameters -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe EventParameters
parameters,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Type" Text -> EventSourceValues -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= EventSourceValues
type')
          ]
      )