{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.DLM.Types.EventSource where

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

-- | __[Event-based policies only]__ Specifies an event that activates 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
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]
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
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. 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'
    { $sel:parameters:EventSource' :: Maybe EventParameters
parameters = 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 :: Lens' EventSource (Maybe EventParameters)
eventSource_parameters = 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 :: Lens' EventSource EventSourceValues
eventSource_type = 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 Data.FromJSON EventSource where
  parseJSON :: Value -> Parser EventSource
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"EventSource"
      ( \Object
x ->
          Maybe EventParameters -> EventSourceValues -> EventSource
EventSource'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Parameters")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Type")
      )

instance Prelude.Hashable EventSource where
  hashWithSalt :: Int -> EventSource -> Int
hashWithSalt Int
_salt EventSource' {Maybe EventParameters
EventSourceValues
type' :: EventSourceValues
parameters :: Maybe EventParameters
$sel:type':EventSource' :: EventSource -> EventSourceValues
$sel:parameters:EventSource' :: EventSource -> Maybe EventParameters
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe EventParameters
parameters
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` EventSourceValues
type'

instance Prelude.NFData EventSource where
  rnf :: EventSource -> ()
rnf EventSource' {Maybe EventParameters
EventSourceValues
type' :: EventSourceValues
parameters :: Maybe EventParameters
$sel:type':EventSource' :: EventSource -> EventSourceValues
$sel:parameters:EventSource' :: EventSource -> Maybe EventParameters
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe EventParameters
parameters
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf EventSourceValues
type'

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Parameters" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe EventParameters
parameters,
            forall a. a -> Maybe a
Prelude.Just (Key
"Type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= EventSourceValues
type')
          ]
      )