{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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 :: Data.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 with message processing or stop it in
    -- cases where communication with a processor fails. If a processor has a
    -- fallback action of @ABORT@ and communication with it fails, the
    -- processor sets the message status to @FAILED@ and does not send the
    -- message to any recipients. Note that if the last processor in the
    -- channel flow sequence has a fallback action of @CONTINUE@ and
    -- communication with the processor fails, then the message is considered
    -- processed and sent to recipients of the channel.
    Processor -> FallbackAction
fallbackAction :: FallbackAction
  }
  deriving (Processor -> Processor -> Bool
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
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. 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 with message processing or stop it in
-- cases where communication with a processor fails. If a processor has a
-- fallback action of @ABORT@ and communication with it fails, the
-- processor sets the message status to @FAILED@ and does not send the
-- message to any recipients. Note that if the last processor in the
-- channel flow sequence has a fallback action of @CONTINUE@ and
-- communication with the processor fails, then the message is considered
-- processed and sent to recipients of 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'
      { $sel:name:Processor' :: Sensitive Text
name = forall a. Iso' (Sensitive a) a
Data._Sensitive 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 :: Lens' Processor Text
processor_name = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive

-- | The information about the type of processor and its identifier.
processor_configuration :: Lens.Lens' Processor ProcessorConfiguration
processor_configuration :: Lens' Processor ProcessorConfiguration
processor_configuration = 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 :: Lens' Processor Natural
processor_executionOrder = 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 with message processing or stop it in
-- cases where communication with a processor fails. If a processor has a
-- fallback action of @ABORT@ and communication with it fails, the
-- processor sets the message status to @FAILED@ and does not send the
-- message to any recipients. Note that if the last processor in the
-- channel flow sequence has a fallback action of @CONTINUE@ and
-- communication with the processor fails, then the message is considered
-- processed and sent to recipients of the channel.
processor_fallbackAction :: Lens.Lens' Processor FallbackAction
processor_fallbackAction :: Lens' Processor FallbackAction
processor_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 Data.FromJSON Processor where
  parseJSON :: Value -> Parser Processor
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Processor"
      ( \Object
x ->
          Sensitive Text
-> ProcessorConfiguration -> Natural -> FallbackAction -> Processor
Processor'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Name")
            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
"Configuration")
            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
"ExecutionOrder")
            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
"FallbackAction")
      )

instance Prelude.Hashable Processor where
  hashWithSalt :: Int -> Processor -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ProcessorConfiguration
configuration
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
executionOrder
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` FallbackAction
fallbackAction

instance Prelude.NFData Processor where
  rnf :: Processor -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Sensitive Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ProcessorConfiguration
configuration
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
executionOrder
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf FallbackAction
fallbackAction

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Sensitive Text
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"Configuration" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ProcessorConfiguration
configuration),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"ExecutionOrder" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
executionOrder),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"FallbackAction" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= FallbackAction
fallbackAction)
          ]
      )