{-# 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.QuickSight.Types.VisualCustomAction
-- 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.QuickSight.Types.VisualCustomAction where

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
import Amazonka.QuickSight.Types.VisualCustomActionOperation
import Amazonka.QuickSight.Types.VisualCustomActionTrigger
import Amazonka.QuickSight.Types.WidgetStatus

-- | A custom action defined on a visual.
--
-- /See:/ 'newVisualCustomAction' smart constructor.
data VisualCustomAction = VisualCustomAction'
  { -- | The status of the @VisualCustomAction@.
    VisualCustomAction -> Maybe WidgetStatus
status :: Prelude.Maybe WidgetStatus,
    -- | The ID of the @VisualCustomAction@.
    VisualCustomAction -> Text
customActionId :: Prelude.Text,
    -- | The name of the @VisualCustomAction@.
    VisualCustomAction -> Text
name :: Prelude.Text,
    -- | The trigger of the @VisualCustomAction@.
    --
    -- Valid values are defined as follows:
    --
    -- -   @DATA_POINT_CLICK@: Initiates a custom action by a left pointer
    --     click on a data point.
    --
    -- -   @DATA_POINT_MENU@: Initiates a custom action by right pointer click
    --     from the menu.
    VisualCustomAction -> VisualCustomActionTrigger
trigger :: VisualCustomActionTrigger,
    -- | A list of @VisualCustomActionOperations@.
    --
    -- This is a union type structure. For this structure to be valid, only one
    -- of the attributes can be defined.
    VisualCustomAction -> NonEmpty VisualCustomActionOperation
actionOperations :: Prelude.NonEmpty VisualCustomActionOperation
  }
  deriving (VisualCustomAction -> VisualCustomAction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VisualCustomAction -> VisualCustomAction -> Bool
$c/= :: VisualCustomAction -> VisualCustomAction -> Bool
== :: VisualCustomAction -> VisualCustomAction -> Bool
$c== :: VisualCustomAction -> VisualCustomAction -> Bool
Prelude.Eq, Int -> VisualCustomAction -> ShowS
[VisualCustomAction] -> ShowS
VisualCustomAction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VisualCustomAction] -> ShowS
$cshowList :: [VisualCustomAction] -> ShowS
show :: VisualCustomAction -> String
$cshow :: VisualCustomAction -> String
showsPrec :: Int -> VisualCustomAction -> ShowS
$cshowsPrec :: Int -> VisualCustomAction -> ShowS
Prelude.Show, forall x. Rep VisualCustomAction x -> VisualCustomAction
forall x. VisualCustomAction -> Rep VisualCustomAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep VisualCustomAction x -> VisualCustomAction
$cfrom :: forall x. VisualCustomAction -> Rep VisualCustomAction x
Prelude.Generic)

-- |
-- Create a value of 'VisualCustomAction' 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:
--
-- 'status', 'visualCustomAction_status' - The status of the @VisualCustomAction@.
--
-- 'customActionId', 'visualCustomAction_customActionId' - The ID of the @VisualCustomAction@.
--
-- 'name', 'visualCustomAction_name' - The name of the @VisualCustomAction@.
--
-- 'trigger', 'visualCustomAction_trigger' - The trigger of the @VisualCustomAction@.
--
-- Valid values are defined as follows:
--
-- -   @DATA_POINT_CLICK@: Initiates a custom action by a left pointer
--     click on a data point.
--
-- -   @DATA_POINT_MENU@: Initiates a custom action by right pointer click
--     from the menu.
--
-- 'actionOperations', 'visualCustomAction_actionOperations' - A list of @VisualCustomActionOperations@.
--
-- This is a union type structure. For this structure to be valid, only one
-- of the attributes can be defined.
newVisualCustomAction ::
  -- | 'customActionId'
  Prelude.Text ->
  -- | 'name'
  Prelude.Text ->
  -- | 'trigger'
  VisualCustomActionTrigger ->
  -- | 'actionOperations'
  Prelude.NonEmpty VisualCustomActionOperation ->
  VisualCustomAction
newVisualCustomAction :: Text
-> Text
-> VisualCustomActionTrigger
-> NonEmpty VisualCustomActionOperation
-> VisualCustomAction
newVisualCustomAction
  Text
pCustomActionId_
  Text
pName_
  VisualCustomActionTrigger
pTrigger_
  NonEmpty VisualCustomActionOperation
pActionOperations_ =
    VisualCustomAction'
      { $sel:status:VisualCustomAction' :: Maybe WidgetStatus
status = forall a. Maybe a
Prelude.Nothing,
        $sel:customActionId:VisualCustomAction' :: Text
customActionId = Text
pCustomActionId_,
        $sel:name:VisualCustomAction' :: Text
name = Text
pName_,
        $sel:trigger:VisualCustomAction' :: VisualCustomActionTrigger
trigger = VisualCustomActionTrigger
pTrigger_,
        $sel:actionOperations:VisualCustomAction' :: NonEmpty VisualCustomActionOperation
actionOperations =
          forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty VisualCustomActionOperation
pActionOperations_
      }

-- | The status of the @VisualCustomAction@.
visualCustomAction_status :: Lens.Lens' VisualCustomAction (Prelude.Maybe WidgetStatus)
visualCustomAction_status :: Lens' VisualCustomAction (Maybe WidgetStatus)
visualCustomAction_status = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VisualCustomAction' {Maybe WidgetStatus
status :: Maybe WidgetStatus
$sel:status:VisualCustomAction' :: VisualCustomAction -> Maybe WidgetStatus
status} -> Maybe WidgetStatus
status) (\s :: VisualCustomAction
s@VisualCustomAction' {} Maybe WidgetStatus
a -> VisualCustomAction
s {$sel:status:VisualCustomAction' :: Maybe WidgetStatus
status = Maybe WidgetStatus
a} :: VisualCustomAction)

-- | The ID of the @VisualCustomAction@.
visualCustomAction_customActionId :: Lens.Lens' VisualCustomAction Prelude.Text
visualCustomAction_customActionId :: Lens' VisualCustomAction Text
visualCustomAction_customActionId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VisualCustomAction' {Text
customActionId :: Text
$sel:customActionId:VisualCustomAction' :: VisualCustomAction -> Text
customActionId} -> Text
customActionId) (\s :: VisualCustomAction
s@VisualCustomAction' {} Text
a -> VisualCustomAction
s {$sel:customActionId:VisualCustomAction' :: Text
customActionId = Text
a} :: VisualCustomAction)

-- | The name of the @VisualCustomAction@.
visualCustomAction_name :: Lens.Lens' VisualCustomAction Prelude.Text
visualCustomAction_name :: Lens' VisualCustomAction Text
visualCustomAction_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VisualCustomAction' {Text
name :: Text
$sel:name:VisualCustomAction' :: VisualCustomAction -> Text
name} -> Text
name) (\s :: VisualCustomAction
s@VisualCustomAction' {} Text
a -> VisualCustomAction
s {$sel:name:VisualCustomAction' :: Text
name = Text
a} :: VisualCustomAction)

-- | The trigger of the @VisualCustomAction@.
--
-- Valid values are defined as follows:
--
-- -   @DATA_POINT_CLICK@: Initiates a custom action by a left pointer
--     click on a data point.
--
-- -   @DATA_POINT_MENU@: Initiates a custom action by right pointer click
--     from the menu.
visualCustomAction_trigger :: Lens.Lens' VisualCustomAction VisualCustomActionTrigger
visualCustomAction_trigger :: Lens' VisualCustomAction VisualCustomActionTrigger
visualCustomAction_trigger = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VisualCustomAction' {VisualCustomActionTrigger
trigger :: VisualCustomActionTrigger
$sel:trigger:VisualCustomAction' :: VisualCustomAction -> VisualCustomActionTrigger
trigger} -> VisualCustomActionTrigger
trigger) (\s :: VisualCustomAction
s@VisualCustomAction' {} VisualCustomActionTrigger
a -> VisualCustomAction
s {$sel:trigger:VisualCustomAction' :: VisualCustomActionTrigger
trigger = VisualCustomActionTrigger
a} :: VisualCustomAction)

-- | A list of @VisualCustomActionOperations@.
--
-- This is a union type structure. For this structure to be valid, only one
-- of the attributes can be defined.
visualCustomAction_actionOperations :: Lens.Lens' VisualCustomAction (Prelude.NonEmpty VisualCustomActionOperation)
visualCustomAction_actionOperations :: Lens' VisualCustomAction (NonEmpty VisualCustomActionOperation)
visualCustomAction_actionOperations = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VisualCustomAction' {NonEmpty VisualCustomActionOperation
actionOperations :: NonEmpty VisualCustomActionOperation
$sel:actionOperations:VisualCustomAction' :: VisualCustomAction -> NonEmpty VisualCustomActionOperation
actionOperations} -> NonEmpty VisualCustomActionOperation
actionOperations) (\s :: VisualCustomAction
s@VisualCustomAction' {} NonEmpty VisualCustomActionOperation
a -> VisualCustomAction
s {$sel:actionOperations:VisualCustomAction' :: NonEmpty VisualCustomActionOperation
actionOperations = NonEmpty VisualCustomActionOperation
a} :: VisualCustomAction) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON VisualCustomAction where
  parseJSON :: Value -> Parser VisualCustomAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"VisualCustomAction"
      ( \Object
x ->
          Maybe WidgetStatus
-> Text
-> Text
-> VisualCustomActionTrigger
-> NonEmpty VisualCustomActionOperation
-> VisualCustomAction
VisualCustomAction'
            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
"Status")
            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
"CustomActionId")
            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
"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
"Trigger")
            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
"ActionOperations")
      )

instance Prelude.Hashable VisualCustomAction where
  hashWithSalt :: Int -> VisualCustomAction -> Int
hashWithSalt Int
_salt VisualCustomAction' {Maybe WidgetStatus
NonEmpty VisualCustomActionOperation
Text
VisualCustomActionTrigger
actionOperations :: NonEmpty VisualCustomActionOperation
trigger :: VisualCustomActionTrigger
name :: Text
customActionId :: Text
status :: Maybe WidgetStatus
$sel:actionOperations:VisualCustomAction' :: VisualCustomAction -> NonEmpty VisualCustomActionOperation
$sel:trigger:VisualCustomAction' :: VisualCustomAction -> VisualCustomActionTrigger
$sel:name:VisualCustomAction' :: VisualCustomAction -> Text
$sel:customActionId:VisualCustomAction' :: VisualCustomAction -> Text
$sel:status:VisualCustomAction' :: VisualCustomAction -> Maybe WidgetStatus
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe WidgetStatus
status
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
customActionId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` VisualCustomActionTrigger
trigger
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty VisualCustomActionOperation
actionOperations

instance Prelude.NFData VisualCustomAction where
  rnf :: VisualCustomAction -> ()
rnf VisualCustomAction' {Maybe WidgetStatus
NonEmpty VisualCustomActionOperation
Text
VisualCustomActionTrigger
actionOperations :: NonEmpty VisualCustomActionOperation
trigger :: VisualCustomActionTrigger
name :: Text
customActionId :: Text
status :: Maybe WidgetStatus
$sel:actionOperations:VisualCustomAction' :: VisualCustomAction -> NonEmpty VisualCustomActionOperation
$sel:trigger:VisualCustomAction' :: VisualCustomAction -> VisualCustomActionTrigger
$sel:name:VisualCustomAction' :: VisualCustomAction -> Text
$sel:customActionId:VisualCustomAction' :: VisualCustomAction -> Text
$sel:status:VisualCustomAction' :: VisualCustomAction -> Maybe WidgetStatus
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe WidgetStatus
status
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
customActionId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf VisualCustomActionTrigger
trigger
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty VisualCustomActionOperation
actionOperations

instance Data.ToJSON VisualCustomAction where
  toJSON :: VisualCustomAction -> Value
toJSON VisualCustomAction' {Maybe WidgetStatus
NonEmpty VisualCustomActionOperation
Text
VisualCustomActionTrigger
actionOperations :: NonEmpty VisualCustomActionOperation
trigger :: VisualCustomActionTrigger
name :: Text
customActionId :: Text
status :: Maybe WidgetStatus
$sel:actionOperations:VisualCustomAction' :: VisualCustomAction -> NonEmpty VisualCustomActionOperation
$sel:trigger:VisualCustomAction' :: VisualCustomAction -> VisualCustomActionTrigger
$sel:name:VisualCustomAction' :: VisualCustomAction -> Text
$sel:customActionId:VisualCustomAction' :: VisualCustomAction -> Text
$sel:status:VisualCustomAction' :: VisualCustomAction -> Maybe WidgetStatus
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Status" 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 WidgetStatus
status,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"CustomActionId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
customActionId),
            forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"Trigger" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= VisualCustomActionTrigger
trigger),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"ActionOperations" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty VisualCustomActionOperation
actionOperations)
          ]
      )