{-# 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.Config.Types.SourceDetail
-- 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.Config.Types.SourceDetail where

import Amazonka.Config.Types.EventSource
import Amazonka.Config.Types.MaximumExecutionFrequency
import Amazonka.Config.Types.MessageType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Provides the source and the message types that trigger Config to
-- evaluate your Amazon Web Services resources against a rule. It also
-- provides the frequency with which you want Config to run evaluations for
-- the rule if the trigger type is periodic. You can specify the parameter
-- values for @SourceDetail@ only for custom rules.
--
-- /See:/ 'newSourceDetail' smart constructor.
data SourceDetail = SourceDetail'
  { -- | The type of notification that triggers Config to run an evaluation for a
    -- rule. You can specify the following notification types:
    --
    -- -   @ConfigurationItemChangeNotification@ - Triggers an evaluation when
    --     Config delivers a configuration item as a result of a resource
    --     change.
    --
    -- -   @OversizedConfigurationItemChangeNotification@ - Triggers an
    --     evaluation when Config delivers an oversized configuration item.
    --     Config may generate this notification type when a resource changes
    --     and the notification exceeds the maximum size allowed by Amazon SNS.
    --
    -- -   @ScheduledNotification@ - Triggers a periodic evaluation at the
    --     frequency specified for @MaximumExecutionFrequency@.
    --
    -- -   @ConfigurationSnapshotDeliveryCompleted@ - Triggers a periodic
    --     evaluation when Config delivers a configuration snapshot.
    --
    -- If you want your custom rule to be triggered by configuration changes,
    -- specify two SourceDetail objects, one for
    -- @ConfigurationItemChangeNotification@ and one for
    -- @OversizedConfigurationItemChangeNotification@.
    SourceDetail -> Maybe MessageType
messageType :: Prelude.Maybe MessageType,
    -- | The frequency at which you want Config to run evaluations for a custom
    -- rule with a periodic trigger. If you specify a value for
    -- @MaximumExecutionFrequency@, then @MessageType@ must use the
    -- @ScheduledNotification@ value.
    --
    -- By default, rules with a periodic trigger are evaluated every 24 hours.
    -- To change the frequency, specify a valid value for the
    -- @MaximumExecutionFrequency@ parameter.
    --
    -- Based on the valid value you choose, Config runs evaluations once for
    -- each valid value. For example, if you choose @Three_Hours@, Config runs
    -- evaluations once every three hours. In this case, @Three_Hours@ is the
    -- frequency of this rule.
    SourceDetail -> Maybe MaximumExecutionFrequency
maximumExecutionFrequency :: Prelude.Maybe MaximumExecutionFrequency,
    -- | The source of the event, such as an Amazon Web Services service, that
    -- triggers Config to evaluate your Amazon Web Services resources.
    SourceDetail -> Maybe EventSource
eventSource :: Prelude.Maybe EventSource
  }
  deriving (SourceDetail -> SourceDetail -> Bool
(SourceDetail -> SourceDetail -> Bool)
-> (SourceDetail -> SourceDetail -> Bool) -> Eq SourceDetail
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SourceDetail -> SourceDetail -> Bool
$c/= :: SourceDetail -> SourceDetail -> Bool
== :: SourceDetail -> SourceDetail -> Bool
$c== :: SourceDetail -> SourceDetail -> Bool
Prelude.Eq, ReadPrec [SourceDetail]
ReadPrec SourceDetail
Int -> ReadS SourceDetail
ReadS [SourceDetail]
(Int -> ReadS SourceDetail)
-> ReadS [SourceDetail]
-> ReadPrec SourceDetail
-> ReadPrec [SourceDetail]
-> Read SourceDetail
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SourceDetail]
$creadListPrec :: ReadPrec [SourceDetail]
readPrec :: ReadPrec SourceDetail
$creadPrec :: ReadPrec SourceDetail
readList :: ReadS [SourceDetail]
$creadList :: ReadS [SourceDetail]
readsPrec :: Int -> ReadS SourceDetail
$creadsPrec :: Int -> ReadS SourceDetail
Prelude.Read, Int -> SourceDetail -> ShowS
[SourceDetail] -> ShowS
SourceDetail -> String
(Int -> SourceDetail -> ShowS)
-> (SourceDetail -> String)
-> ([SourceDetail] -> ShowS)
-> Show SourceDetail
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SourceDetail] -> ShowS
$cshowList :: [SourceDetail] -> ShowS
show :: SourceDetail -> String
$cshow :: SourceDetail -> String
showsPrec :: Int -> SourceDetail -> ShowS
$cshowsPrec :: Int -> SourceDetail -> ShowS
Prelude.Show, (forall x. SourceDetail -> Rep SourceDetail x)
-> (forall x. Rep SourceDetail x -> SourceDetail)
-> Generic SourceDetail
forall x. Rep SourceDetail x -> SourceDetail
forall x. SourceDetail -> Rep SourceDetail x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SourceDetail x -> SourceDetail
$cfrom :: forall x. SourceDetail -> Rep SourceDetail x
Prelude.Generic)

-- |
-- Create a value of 'SourceDetail' 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:
--
-- 'messageType', 'sourceDetail_messageType' - The type of notification that triggers Config to run an evaluation for a
-- rule. You can specify the following notification types:
--
-- -   @ConfigurationItemChangeNotification@ - Triggers an evaluation when
--     Config delivers a configuration item as a result of a resource
--     change.
--
-- -   @OversizedConfigurationItemChangeNotification@ - Triggers an
--     evaluation when Config delivers an oversized configuration item.
--     Config may generate this notification type when a resource changes
--     and the notification exceeds the maximum size allowed by Amazon SNS.
--
-- -   @ScheduledNotification@ - Triggers a periodic evaluation at the
--     frequency specified for @MaximumExecutionFrequency@.
--
-- -   @ConfigurationSnapshotDeliveryCompleted@ - Triggers a periodic
--     evaluation when Config delivers a configuration snapshot.
--
-- If you want your custom rule to be triggered by configuration changes,
-- specify two SourceDetail objects, one for
-- @ConfigurationItemChangeNotification@ and one for
-- @OversizedConfigurationItemChangeNotification@.
--
-- 'maximumExecutionFrequency', 'sourceDetail_maximumExecutionFrequency' - The frequency at which you want Config to run evaluations for a custom
-- rule with a periodic trigger. If you specify a value for
-- @MaximumExecutionFrequency@, then @MessageType@ must use the
-- @ScheduledNotification@ value.
--
-- By default, rules with a periodic trigger are evaluated every 24 hours.
-- To change the frequency, specify a valid value for the
-- @MaximumExecutionFrequency@ parameter.
--
-- Based on the valid value you choose, Config runs evaluations once for
-- each valid value. For example, if you choose @Three_Hours@, Config runs
-- evaluations once every three hours. In this case, @Three_Hours@ is the
-- frequency of this rule.
--
-- 'eventSource', 'sourceDetail_eventSource' - The source of the event, such as an Amazon Web Services service, that
-- triggers Config to evaluate your Amazon Web Services resources.
newSourceDetail ::
  SourceDetail
newSourceDetail :: SourceDetail
newSourceDetail =
  SourceDetail' :: Maybe MessageType
-> Maybe MaximumExecutionFrequency
-> Maybe EventSource
-> SourceDetail
SourceDetail'
    { $sel:messageType:SourceDetail' :: Maybe MessageType
messageType = Maybe MessageType
forall a. Maybe a
Prelude.Nothing,
      $sel:maximumExecutionFrequency:SourceDetail' :: Maybe MaximumExecutionFrequency
maximumExecutionFrequency = Maybe MaximumExecutionFrequency
forall a. Maybe a
Prelude.Nothing,
      $sel:eventSource:SourceDetail' :: Maybe EventSource
eventSource = Maybe EventSource
forall a. Maybe a
Prelude.Nothing
    }

-- | The type of notification that triggers Config to run an evaluation for a
-- rule. You can specify the following notification types:
--
-- -   @ConfigurationItemChangeNotification@ - Triggers an evaluation when
--     Config delivers a configuration item as a result of a resource
--     change.
--
-- -   @OversizedConfigurationItemChangeNotification@ - Triggers an
--     evaluation when Config delivers an oversized configuration item.
--     Config may generate this notification type when a resource changes
--     and the notification exceeds the maximum size allowed by Amazon SNS.
--
-- -   @ScheduledNotification@ - Triggers a periodic evaluation at the
--     frequency specified for @MaximumExecutionFrequency@.
--
-- -   @ConfigurationSnapshotDeliveryCompleted@ - Triggers a periodic
--     evaluation when Config delivers a configuration snapshot.
--
-- If you want your custom rule to be triggered by configuration changes,
-- specify two SourceDetail objects, one for
-- @ConfigurationItemChangeNotification@ and one for
-- @OversizedConfigurationItemChangeNotification@.
sourceDetail_messageType :: Lens.Lens' SourceDetail (Prelude.Maybe MessageType)
sourceDetail_messageType :: (Maybe MessageType -> f (Maybe MessageType))
-> SourceDetail -> f SourceDetail
sourceDetail_messageType = (SourceDetail -> Maybe MessageType)
-> (SourceDetail -> Maybe MessageType -> SourceDetail)
-> Lens
     SourceDetail SourceDetail (Maybe MessageType) (Maybe MessageType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SourceDetail' {Maybe MessageType
messageType :: Maybe MessageType
$sel:messageType:SourceDetail' :: SourceDetail -> Maybe MessageType
messageType} -> Maybe MessageType
messageType) (\s :: SourceDetail
s@SourceDetail' {} Maybe MessageType
a -> SourceDetail
s {$sel:messageType:SourceDetail' :: Maybe MessageType
messageType = Maybe MessageType
a} :: SourceDetail)

-- | The frequency at which you want Config to run evaluations for a custom
-- rule with a periodic trigger. If you specify a value for
-- @MaximumExecutionFrequency@, then @MessageType@ must use the
-- @ScheduledNotification@ value.
--
-- By default, rules with a periodic trigger are evaluated every 24 hours.
-- To change the frequency, specify a valid value for the
-- @MaximumExecutionFrequency@ parameter.
--
-- Based on the valid value you choose, Config runs evaluations once for
-- each valid value. For example, if you choose @Three_Hours@, Config runs
-- evaluations once every three hours. In this case, @Three_Hours@ is the
-- frequency of this rule.
sourceDetail_maximumExecutionFrequency :: Lens.Lens' SourceDetail (Prelude.Maybe MaximumExecutionFrequency)
sourceDetail_maximumExecutionFrequency :: (Maybe MaximumExecutionFrequency
 -> f (Maybe MaximumExecutionFrequency))
-> SourceDetail -> f SourceDetail
sourceDetail_maximumExecutionFrequency = (SourceDetail -> Maybe MaximumExecutionFrequency)
-> (SourceDetail
    -> Maybe MaximumExecutionFrequency -> SourceDetail)
-> Lens
     SourceDetail
     SourceDetail
     (Maybe MaximumExecutionFrequency)
     (Maybe MaximumExecutionFrequency)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SourceDetail' {Maybe MaximumExecutionFrequency
maximumExecutionFrequency :: Maybe MaximumExecutionFrequency
$sel:maximumExecutionFrequency:SourceDetail' :: SourceDetail -> Maybe MaximumExecutionFrequency
maximumExecutionFrequency} -> Maybe MaximumExecutionFrequency
maximumExecutionFrequency) (\s :: SourceDetail
s@SourceDetail' {} Maybe MaximumExecutionFrequency
a -> SourceDetail
s {$sel:maximumExecutionFrequency:SourceDetail' :: Maybe MaximumExecutionFrequency
maximumExecutionFrequency = Maybe MaximumExecutionFrequency
a} :: SourceDetail)

-- | The source of the event, such as an Amazon Web Services service, that
-- triggers Config to evaluate your Amazon Web Services resources.
sourceDetail_eventSource :: Lens.Lens' SourceDetail (Prelude.Maybe EventSource)
sourceDetail_eventSource :: (Maybe EventSource -> f (Maybe EventSource))
-> SourceDetail -> f SourceDetail
sourceDetail_eventSource = (SourceDetail -> Maybe EventSource)
-> (SourceDetail -> Maybe EventSource -> SourceDetail)
-> Lens
     SourceDetail SourceDetail (Maybe EventSource) (Maybe EventSource)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SourceDetail' {Maybe EventSource
eventSource :: Maybe EventSource
$sel:eventSource:SourceDetail' :: SourceDetail -> Maybe EventSource
eventSource} -> Maybe EventSource
eventSource) (\s :: SourceDetail
s@SourceDetail' {} Maybe EventSource
a -> SourceDetail
s {$sel:eventSource:SourceDetail' :: Maybe EventSource
eventSource = Maybe EventSource
a} :: SourceDetail)

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

instance Prelude.Hashable SourceDetail

instance Prelude.NFData SourceDetail

instance Core.ToJSON SourceDetail where
  toJSON :: SourceDetail -> Value
toJSON SourceDetail' {Maybe EventSource
Maybe MaximumExecutionFrequency
Maybe MessageType
eventSource :: Maybe EventSource
maximumExecutionFrequency :: Maybe MaximumExecutionFrequency
messageType :: Maybe MessageType
$sel:eventSource:SourceDetail' :: SourceDetail -> Maybe EventSource
$sel:maximumExecutionFrequency:SourceDetail' :: SourceDetail -> Maybe MaximumExecutionFrequency
$sel:messageType:SourceDetail' :: SourceDetail -> Maybe MessageType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"MessageType" Text -> MessageType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (MessageType -> Pair) -> Maybe MessageType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe MessageType
messageType,
            (Text
"MaximumExecutionFrequency" Text -> MaximumExecutionFrequency -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (MaximumExecutionFrequency -> Pair)
-> Maybe MaximumExecutionFrequency -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe MaximumExecutionFrequency
maximumExecutionFrequency,
            (Text
"EventSource" Text -> EventSource -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (EventSource -> Pair) -> Maybe EventSource -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe EventSource
eventSource
          ]
      )