{-# 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.ChimeSDKMessaging.Types.Processor
-- 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.ChimeSDKMessaging.Types.Processor where

import Amazonka.ChimeSDKMessaging.Types.FallbackAction
import Amazonka.ChimeSDKMessaging.Types.ProcessorConfiguration
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The information about a processor in a channel flow.
--
-- /See:/ 'newProcessor' smart constructor.
data Processor = Processor'
  { -- | The name of the channel flow.
    Processor -> Sensitive Text
name :: Core.Sensitive Prelude.Text,
    -- | The information about the type of processor and its identifier.
    Processor -> ProcessorConfiguration
configuration :: ProcessorConfiguration,
    -- | The sequence in which processors run. If you have multiple processors in
    -- a channel flow, message processing goes through each processor in the
    -- sequence. The value determines the sequence. At this point, we support
    -- only 1 processor within a flow.
    Processor -> Natural
executionOrder :: Prelude.Natural,
    -- | Determines whether to continue or stop processing if communication with
    -- processor fails. If the last processor in a channel flow sequence has a
    -- fallback action of CONTINUE, and communication with the processor fails,
    -- the message is considered processed and sent to the recipients in the
    -- channel.
    Processor -> FallbackAction
fallbackAction :: FallbackAction
  }
  deriving (Processor -> Processor -> Bool
(Processor -> Processor -> Bool)
-> (Processor -> Processor -> Bool) -> Eq Processor
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Processor -> Processor -> Bool
$c/= :: Processor -> Processor -> Bool
== :: Processor -> Processor -> Bool
$c== :: Processor -> Processor -> Bool
Prelude.Eq, Int -> Processor -> ShowS
[Processor] -> ShowS
Processor -> String
(Int -> Processor -> ShowS)
-> (Processor -> String)
-> ([Processor] -> ShowS)
-> Show Processor
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Processor] -> ShowS
$cshowList :: [Processor] -> ShowS
show :: Processor -> String
$cshow :: Processor -> String
showsPrec :: Int -> Processor -> ShowS
$cshowsPrec :: Int -> Processor -> ShowS
Prelude.Show, (forall x. Processor -> Rep Processor x)
-> (forall x. Rep Processor x -> Processor) -> Generic Processor
forall x. Rep Processor x -> Processor
forall x. Processor -> Rep Processor x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Processor x -> Processor
$cfrom :: forall x. Processor -> Rep Processor x
Prelude.Generic)

-- |
-- Create a value of 'Processor' 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', 'processor_name' - The name of the channel flow.
--
-- 'configuration', 'processor_configuration' - The information about the type of processor and its identifier.
--
-- 'executionOrder', 'processor_executionOrder' - The sequence in which processors run. If you have multiple processors in
-- a channel flow, message processing goes through each processor in the
-- sequence. The value determines the sequence. At this point, we support
-- only 1 processor within a flow.
--
-- 'fallbackAction', 'processor_fallbackAction' - Determines whether to continue or stop processing if communication with
-- processor fails. If the last processor in a channel flow sequence has a
-- fallback action of CONTINUE, and communication with the processor fails,
-- the message is considered processed and sent to the recipients in the
-- channel.
newProcessor ::
  -- | 'name'
  Prelude.Text ->
  -- | 'configuration'
  ProcessorConfiguration ->
  -- | 'executionOrder'
  Prelude.Natural ->
  -- | 'fallbackAction'
  FallbackAction ->
  Processor
newProcessor :: Text
-> ProcessorConfiguration -> Natural -> FallbackAction -> Processor
newProcessor
  Text
pName_
  ProcessorConfiguration
pConfiguration_
  Natural
pExecutionOrder_
  FallbackAction
pFallbackAction_ =
    Processor' :: Sensitive Text
-> ProcessorConfiguration -> Natural -> FallbackAction -> Processor
Processor'
      { $sel:name:Processor' :: Sensitive Text
name = Tagged Text (Identity Text)
-> Tagged (Sensitive Text) (Identity (Sensitive Text))
forall a. Iso' (Sensitive a) a
Core._Sensitive (Tagged Text (Identity Text)
 -> Tagged (Sensitive Text) (Identity (Sensitive Text)))
-> Text -> Sensitive Text
forall t b. AReview t b -> b -> t
Lens.# Text
pName_,
        $sel:configuration:Processor' :: ProcessorConfiguration
configuration = ProcessorConfiguration
pConfiguration_,
        $sel:executionOrder:Processor' :: Natural
executionOrder = Natural
pExecutionOrder_,
        $sel:fallbackAction:Processor' :: FallbackAction
fallbackAction = FallbackAction
pFallbackAction_
      }

-- | The name of the channel flow.
processor_name :: Lens.Lens' Processor Prelude.Text
processor_name :: (Text -> f Text) -> Processor -> f Processor
processor_name = (Processor -> Sensitive Text)
-> (Processor -> Sensitive Text -> Processor)
-> Lens Processor Processor (Sensitive Text) (Sensitive Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Processor' {Sensitive Text
name :: Sensitive Text
$sel:name:Processor' :: Processor -> Sensitive Text
name} -> Sensitive Text
name) (\s :: Processor
s@Processor' {} Sensitive Text
a -> Processor
s {$sel:name:Processor' :: Sensitive Text
name = Sensitive Text
a} :: Processor) ((Sensitive Text -> f (Sensitive Text))
 -> Processor -> f Processor)
-> ((Text -> f Text) -> Sensitive Text -> f (Sensitive Text))
-> (Text -> f Text)
-> Processor
-> f Processor
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> f Text) -> Sensitive Text -> f (Sensitive Text)
forall a. Iso' (Sensitive a) a
Core._Sensitive

-- | The information about the type of processor and its identifier.
processor_configuration :: Lens.Lens' Processor ProcessorConfiguration
processor_configuration :: (ProcessorConfiguration -> f ProcessorConfiguration)
-> Processor -> f Processor
processor_configuration = (Processor -> ProcessorConfiguration)
-> (Processor -> ProcessorConfiguration -> Processor)
-> Lens
     Processor Processor ProcessorConfiguration ProcessorConfiguration
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Processor' {ProcessorConfiguration
configuration :: ProcessorConfiguration
$sel:configuration:Processor' :: Processor -> ProcessorConfiguration
configuration} -> ProcessorConfiguration
configuration) (\s :: Processor
s@Processor' {} ProcessorConfiguration
a -> Processor
s {$sel:configuration:Processor' :: ProcessorConfiguration
configuration = ProcessorConfiguration
a} :: Processor)

-- | The sequence in which processors run. If you have multiple processors in
-- a channel flow, message processing goes through each processor in the
-- sequence. The value determines the sequence. At this point, we support
-- only 1 processor within a flow.
processor_executionOrder :: Lens.Lens' Processor Prelude.Natural
processor_executionOrder :: (Natural -> f Natural) -> Processor -> f Processor
processor_executionOrder = (Processor -> Natural)
-> (Processor -> Natural -> Processor)
-> Lens Processor Processor Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Processor' {Natural
executionOrder :: Natural
$sel:executionOrder:Processor' :: Processor -> Natural
executionOrder} -> Natural
executionOrder) (\s :: Processor
s@Processor' {} Natural
a -> Processor
s {$sel:executionOrder:Processor' :: Natural
executionOrder = Natural
a} :: Processor)

-- | Determines whether to continue or stop processing if communication with
-- processor fails. If the last processor in a channel flow sequence has a
-- fallback action of CONTINUE, and communication with the processor fails,
-- the message is considered processed and sent to the recipients in the
-- channel.
processor_fallbackAction :: Lens.Lens' Processor FallbackAction
processor_fallbackAction :: (FallbackAction -> f FallbackAction) -> Processor -> f Processor
processor_fallbackAction = (Processor -> FallbackAction)
-> (Processor -> FallbackAction -> Processor)
-> Lens Processor Processor FallbackAction FallbackAction
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Processor' {FallbackAction
fallbackAction :: FallbackAction
$sel:fallbackAction:Processor' :: Processor -> FallbackAction
fallbackAction} -> FallbackAction
fallbackAction) (\s :: Processor
s@Processor' {} FallbackAction
a -> Processor
s {$sel:fallbackAction:Processor' :: FallbackAction
fallbackAction = FallbackAction
a} :: Processor)

instance Core.FromJSON Processor where
  parseJSON :: Value -> Parser Processor
parseJSON =
    String -> (Object -> Parser Processor) -> Value -> Parser Processor
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Processor"
      ( \Object
x ->
          Sensitive Text
-> ProcessorConfiguration -> Natural -> FallbackAction -> Processor
Processor'
            (Sensitive Text
 -> ProcessorConfiguration
 -> Natural
 -> FallbackAction
 -> Processor)
-> Parser (Sensitive Text)
-> Parser
     (ProcessorConfiguration -> Natural -> FallbackAction -> Processor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Sensitive Text)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Name")
            Parser
  (ProcessorConfiguration -> Natural -> FallbackAction -> Processor)
-> Parser ProcessorConfiguration
-> Parser (Natural -> FallbackAction -> Processor)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ProcessorConfiguration
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Configuration")
            Parser (Natural -> FallbackAction -> Processor)
-> Parser Natural -> Parser (FallbackAction -> Processor)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ExecutionOrder")
            Parser (FallbackAction -> Processor)
-> Parser FallbackAction -> Parser Processor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser FallbackAction
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"FallbackAction")
      )

instance Prelude.Hashable Processor

instance Prelude.NFData Processor

instance Core.ToJSON Processor where
  toJSON :: Processor -> Value
toJSON Processor' {Natural
Sensitive Text
FallbackAction
ProcessorConfiguration
fallbackAction :: FallbackAction
executionOrder :: Natural
configuration :: ProcessorConfiguration
name :: Sensitive Text
$sel:fallbackAction:Processor' :: Processor -> FallbackAction
$sel:executionOrder:Processor' :: Processor -> Natural
$sel:configuration:Processor' :: Processor -> ProcessorConfiguration
$sel:name:Processor' :: Processor -> Sensitive 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 -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Sensitive Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Configuration" Text -> ProcessorConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ProcessorConfiguration
configuration),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ExecutionOrder" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
executionOrder),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"FallbackAction" Text -> FallbackAction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= FallbackAction
fallbackAction)
          ]
      )