{-# 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.Connect.Types.RuleAction
-- 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.Connect.Types.RuleAction where

import Amazonka.Connect.Types.ActionType
import Amazonka.Connect.Types.AssignContactCategoryActionDefinition
import Amazonka.Connect.Types.EventBridgeActionDefinition
import Amazonka.Connect.Types.SendNotificationActionDefinition
import Amazonka.Connect.Types.TaskActionDefinition
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

-- | Information about the action to be performed when a rule is triggered.
--
-- /See:/ 'newRuleAction' smart constructor.
data RuleAction = RuleAction'
  { -- | Information about the contact category action.
    RuleAction -> Maybe AssignContactCategoryActionDefinition
assignContactCategoryAction :: Prelude.Maybe AssignContactCategoryActionDefinition,
    -- | Information about the EventBridge action.
    RuleAction -> Maybe EventBridgeActionDefinition
eventBridgeAction :: Prelude.Maybe EventBridgeActionDefinition,
    -- | Information about the send notification action.
    RuleAction -> Maybe SendNotificationActionDefinition
sendNotificationAction :: Prelude.Maybe SendNotificationActionDefinition,
    -- | Information about the task action. This field is required if
    -- @TriggerEventSource@ is one of the following values:
    -- @OnZendeskTicketCreate@ | @OnZendeskTicketStatusUpdate@ |
    -- @OnSalesforceCaseCreate@
    RuleAction -> Maybe TaskActionDefinition
taskAction :: Prelude.Maybe TaskActionDefinition,
    -- | The type of action that creates a rule.
    RuleAction -> ActionType
actionType :: ActionType
  }
  deriving (RuleAction -> RuleAction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RuleAction -> RuleAction -> Bool
$c/= :: RuleAction -> RuleAction -> Bool
== :: RuleAction -> RuleAction -> Bool
$c== :: RuleAction -> RuleAction -> Bool
Prelude.Eq, ReadPrec [RuleAction]
ReadPrec RuleAction
Int -> ReadS RuleAction
ReadS [RuleAction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RuleAction]
$creadListPrec :: ReadPrec [RuleAction]
readPrec :: ReadPrec RuleAction
$creadPrec :: ReadPrec RuleAction
readList :: ReadS [RuleAction]
$creadList :: ReadS [RuleAction]
readsPrec :: Int -> ReadS RuleAction
$creadsPrec :: Int -> ReadS RuleAction
Prelude.Read, Int -> RuleAction -> ShowS
[RuleAction] -> ShowS
RuleAction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RuleAction] -> ShowS
$cshowList :: [RuleAction] -> ShowS
show :: RuleAction -> String
$cshow :: RuleAction -> String
showsPrec :: Int -> RuleAction -> ShowS
$cshowsPrec :: Int -> RuleAction -> ShowS
Prelude.Show, forall x. Rep RuleAction x -> RuleAction
forall x. RuleAction -> Rep RuleAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RuleAction x -> RuleAction
$cfrom :: forall x. RuleAction -> Rep RuleAction x
Prelude.Generic)

-- |
-- Create a value of 'RuleAction' 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:
--
-- 'assignContactCategoryAction', 'ruleAction_assignContactCategoryAction' - Information about the contact category action.
--
-- 'eventBridgeAction', 'ruleAction_eventBridgeAction' - Information about the EventBridge action.
--
-- 'sendNotificationAction', 'ruleAction_sendNotificationAction' - Information about the send notification action.
--
-- 'taskAction', 'ruleAction_taskAction' - Information about the task action. This field is required if
-- @TriggerEventSource@ is one of the following values:
-- @OnZendeskTicketCreate@ | @OnZendeskTicketStatusUpdate@ |
-- @OnSalesforceCaseCreate@
--
-- 'actionType', 'ruleAction_actionType' - The type of action that creates a rule.
newRuleAction ::
  -- | 'actionType'
  ActionType ->
  RuleAction
newRuleAction :: ActionType -> RuleAction
newRuleAction ActionType
pActionType_ =
  RuleAction'
    { $sel:assignContactCategoryAction:RuleAction' :: Maybe AssignContactCategoryActionDefinition
assignContactCategoryAction =
        forall a. Maybe a
Prelude.Nothing,
      $sel:eventBridgeAction:RuleAction' :: Maybe EventBridgeActionDefinition
eventBridgeAction = forall a. Maybe a
Prelude.Nothing,
      $sel:sendNotificationAction:RuleAction' :: Maybe SendNotificationActionDefinition
sendNotificationAction = forall a. Maybe a
Prelude.Nothing,
      $sel:taskAction:RuleAction' :: Maybe TaskActionDefinition
taskAction = forall a. Maybe a
Prelude.Nothing,
      $sel:actionType:RuleAction' :: ActionType
actionType = ActionType
pActionType_
    }

-- | Information about the contact category action.
ruleAction_assignContactCategoryAction :: Lens.Lens' RuleAction (Prelude.Maybe AssignContactCategoryActionDefinition)
ruleAction_assignContactCategoryAction :: Lens' RuleAction (Maybe AssignContactCategoryActionDefinition)
ruleAction_assignContactCategoryAction = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuleAction' {Maybe AssignContactCategoryActionDefinition
assignContactCategoryAction :: Maybe AssignContactCategoryActionDefinition
$sel:assignContactCategoryAction:RuleAction' :: RuleAction -> Maybe AssignContactCategoryActionDefinition
assignContactCategoryAction} -> Maybe AssignContactCategoryActionDefinition
assignContactCategoryAction) (\s :: RuleAction
s@RuleAction' {} Maybe AssignContactCategoryActionDefinition
a -> RuleAction
s {$sel:assignContactCategoryAction:RuleAction' :: Maybe AssignContactCategoryActionDefinition
assignContactCategoryAction = Maybe AssignContactCategoryActionDefinition
a} :: RuleAction)

-- | Information about the EventBridge action.
ruleAction_eventBridgeAction :: Lens.Lens' RuleAction (Prelude.Maybe EventBridgeActionDefinition)
ruleAction_eventBridgeAction :: Lens' RuleAction (Maybe EventBridgeActionDefinition)
ruleAction_eventBridgeAction = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuleAction' {Maybe EventBridgeActionDefinition
eventBridgeAction :: Maybe EventBridgeActionDefinition
$sel:eventBridgeAction:RuleAction' :: RuleAction -> Maybe EventBridgeActionDefinition
eventBridgeAction} -> Maybe EventBridgeActionDefinition
eventBridgeAction) (\s :: RuleAction
s@RuleAction' {} Maybe EventBridgeActionDefinition
a -> RuleAction
s {$sel:eventBridgeAction:RuleAction' :: Maybe EventBridgeActionDefinition
eventBridgeAction = Maybe EventBridgeActionDefinition
a} :: RuleAction)

-- | Information about the send notification action.
ruleAction_sendNotificationAction :: Lens.Lens' RuleAction (Prelude.Maybe SendNotificationActionDefinition)
ruleAction_sendNotificationAction :: Lens' RuleAction (Maybe SendNotificationActionDefinition)
ruleAction_sendNotificationAction = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuleAction' {Maybe SendNotificationActionDefinition
sendNotificationAction :: Maybe SendNotificationActionDefinition
$sel:sendNotificationAction:RuleAction' :: RuleAction -> Maybe SendNotificationActionDefinition
sendNotificationAction} -> Maybe SendNotificationActionDefinition
sendNotificationAction) (\s :: RuleAction
s@RuleAction' {} Maybe SendNotificationActionDefinition
a -> RuleAction
s {$sel:sendNotificationAction:RuleAction' :: Maybe SendNotificationActionDefinition
sendNotificationAction = Maybe SendNotificationActionDefinition
a} :: RuleAction)

-- | Information about the task action. This field is required if
-- @TriggerEventSource@ is one of the following values:
-- @OnZendeskTicketCreate@ | @OnZendeskTicketStatusUpdate@ |
-- @OnSalesforceCaseCreate@
ruleAction_taskAction :: Lens.Lens' RuleAction (Prelude.Maybe TaskActionDefinition)
ruleAction_taskAction :: Lens' RuleAction (Maybe TaskActionDefinition)
ruleAction_taskAction = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuleAction' {Maybe TaskActionDefinition
taskAction :: Maybe TaskActionDefinition
$sel:taskAction:RuleAction' :: RuleAction -> Maybe TaskActionDefinition
taskAction} -> Maybe TaskActionDefinition
taskAction) (\s :: RuleAction
s@RuleAction' {} Maybe TaskActionDefinition
a -> RuleAction
s {$sel:taskAction:RuleAction' :: Maybe TaskActionDefinition
taskAction = Maybe TaskActionDefinition
a} :: RuleAction)

-- | The type of action that creates a rule.
ruleAction_actionType :: Lens.Lens' RuleAction ActionType
ruleAction_actionType :: Lens' RuleAction ActionType
ruleAction_actionType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuleAction' {ActionType
actionType :: ActionType
$sel:actionType:RuleAction' :: RuleAction -> ActionType
actionType} -> ActionType
actionType) (\s :: RuleAction
s@RuleAction' {} ActionType
a -> RuleAction
s {$sel:actionType:RuleAction' :: ActionType
actionType = ActionType
a} :: RuleAction)

instance Data.FromJSON RuleAction where
  parseJSON :: Value -> Parser RuleAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RuleAction"
      ( \Object
x ->
          Maybe AssignContactCategoryActionDefinition
-> Maybe EventBridgeActionDefinition
-> Maybe SendNotificationActionDefinition
-> Maybe TaskActionDefinition
-> ActionType
-> RuleAction
RuleAction'
            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
"AssignContactCategoryAction")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"EventBridgeAction")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"SendNotificationAction")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"TaskAction")
            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
"ActionType")
      )

instance Prelude.Hashable RuleAction where
  hashWithSalt :: Int -> RuleAction -> Int
hashWithSalt Int
_salt RuleAction' {Maybe AssignContactCategoryActionDefinition
Maybe EventBridgeActionDefinition
Maybe SendNotificationActionDefinition
Maybe TaskActionDefinition
ActionType
actionType :: ActionType
taskAction :: Maybe TaskActionDefinition
sendNotificationAction :: Maybe SendNotificationActionDefinition
eventBridgeAction :: Maybe EventBridgeActionDefinition
assignContactCategoryAction :: Maybe AssignContactCategoryActionDefinition
$sel:actionType:RuleAction' :: RuleAction -> ActionType
$sel:taskAction:RuleAction' :: RuleAction -> Maybe TaskActionDefinition
$sel:sendNotificationAction:RuleAction' :: RuleAction -> Maybe SendNotificationActionDefinition
$sel:eventBridgeAction:RuleAction' :: RuleAction -> Maybe EventBridgeActionDefinition
$sel:assignContactCategoryAction:RuleAction' :: RuleAction -> Maybe AssignContactCategoryActionDefinition
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe AssignContactCategoryActionDefinition
assignContactCategoryAction
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe EventBridgeActionDefinition
eventBridgeAction
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe SendNotificationActionDefinition
sendNotificationAction
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe TaskActionDefinition
taskAction
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ActionType
actionType

instance Prelude.NFData RuleAction where
  rnf :: RuleAction -> ()
rnf RuleAction' {Maybe AssignContactCategoryActionDefinition
Maybe EventBridgeActionDefinition
Maybe SendNotificationActionDefinition
Maybe TaskActionDefinition
ActionType
actionType :: ActionType
taskAction :: Maybe TaskActionDefinition
sendNotificationAction :: Maybe SendNotificationActionDefinition
eventBridgeAction :: Maybe EventBridgeActionDefinition
assignContactCategoryAction :: Maybe AssignContactCategoryActionDefinition
$sel:actionType:RuleAction' :: RuleAction -> ActionType
$sel:taskAction:RuleAction' :: RuleAction -> Maybe TaskActionDefinition
$sel:sendNotificationAction:RuleAction' :: RuleAction -> Maybe SendNotificationActionDefinition
$sel:eventBridgeAction:RuleAction' :: RuleAction -> Maybe EventBridgeActionDefinition
$sel:assignContactCategoryAction:RuleAction' :: RuleAction -> Maybe AssignContactCategoryActionDefinition
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe AssignContactCategoryActionDefinition
assignContactCategoryAction
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe EventBridgeActionDefinition
eventBridgeAction
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe SendNotificationActionDefinition
sendNotificationAction
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe TaskActionDefinition
taskAction
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ActionType
actionType

instance Data.ToJSON RuleAction where
  toJSON :: RuleAction -> Value
toJSON RuleAction' {Maybe AssignContactCategoryActionDefinition
Maybe EventBridgeActionDefinition
Maybe SendNotificationActionDefinition
Maybe TaskActionDefinition
ActionType
actionType :: ActionType
taskAction :: Maybe TaskActionDefinition
sendNotificationAction :: Maybe SendNotificationActionDefinition
eventBridgeAction :: Maybe EventBridgeActionDefinition
assignContactCategoryAction :: Maybe AssignContactCategoryActionDefinition
$sel:actionType:RuleAction' :: RuleAction -> ActionType
$sel:taskAction:RuleAction' :: RuleAction -> Maybe TaskActionDefinition
$sel:sendNotificationAction:RuleAction' :: RuleAction -> Maybe SendNotificationActionDefinition
$sel:eventBridgeAction:RuleAction' :: RuleAction -> Maybe EventBridgeActionDefinition
$sel:assignContactCategoryAction:RuleAction' :: RuleAction -> Maybe AssignContactCategoryActionDefinition
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"AssignContactCategoryAction" 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 AssignContactCategoryActionDefinition
assignContactCategoryAction,
            (Key
"EventBridgeAction" 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 EventBridgeActionDefinition
eventBridgeAction,
            (Key
"SendNotificationAction" 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 SendNotificationActionDefinition
sendNotificationAction,
            (Key
"TaskAction" 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 TaskActionDefinition
taskAction,
            forall a. a -> Maybe a
Prelude.Just (Key
"ActionType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ActionType
actionType)
          ]
      )