{-# 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.AmplifyUiBuilder.Types.ComponentEvent
-- 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.AmplifyUiBuilder.Types.ComponentEvent where

import Amazonka.AmplifyUiBuilder.Types.ActionParameters
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

-- | Describes the configuration of an event. You can bind an event and a
-- corresponding action to a @Component@ or a @ComponentChild@. A button
-- click is an example of an event.
--
-- /See:/ 'newComponentEvent' smart constructor.
data ComponentEvent = ComponentEvent'
  { -- | The action to perform when a specific event is raised.
    ComponentEvent -> Maybe Text
action :: Prelude.Maybe Prelude.Text,
    -- | Binds an event to an action on a component. When you specify a
    -- @bindingEvent@, the event is called when the action is performed.
    ComponentEvent -> Maybe Text
bindingEvent :: Prelude.Maybe Prelude.Text,
    -- | Describes information about the action.
    ComponentEvent -> Maybe ActionParameters
parameters :: Prelude.Maybe ActionParameters
  }
  deriving (ComponentEvent -> ComponentEvent -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ComponentEvent -> ComponentEvent -> Bool
$c/= :: ComponentEvent -> ComponentEvent -> Bool
== :: ComponentEvent -> ComponentEvent -> Bool
$c== :: ComponentEvent -> ComponentEvent -> Bool
Prelude.Eq, ReadPrec [ComponentEvent]
ReadPrec ComponentEvent
Int -> ReadS ComponentEvent
ReadS [ComponentEvent]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ComponentEvent]
$creadListPrec :: ReadPrec [ComponentEvent]
readPrec :: ReadPrec ComponentEvent
$creadPrec :: ReadPrec ComponentEvent
readList :: ReadS [ComponentEvent]
$creadList :: ReadS [ComponentEvent]
readsPrec :: Int -> ReadS ComponentEvent
$creadsPrec :: Int -> ReadS ComponentEvent
Prelude.Read, Int -> ComponentEvent -> ShowS
[ComponentEvent] -> ShowS
ComponentEvent -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ComponentEvent] -> ShowS
$cshowList :: [ComponentEvent] -> ShowS
show :: ComponentEvent -> String
$cshow :: ComponentEvent -> String
showsPrec :: Int -> ComponentEvent -> ShowS
$cshowsPrec :: Int -> ComponentEvent -> ShowS
Prelude.Show, forall x. Rep ComponentEvent x -> ComponentEvent
forall x. ComponentEvent -> Rep ComponentEvent x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ComponentEvent x -> ComponentEvent
$cfrom :: forall x. ComponentEvent -> Rep ComponentEvent x
Prelude.Generic)

-- |
-- Create a value of 'ComponentEvent' 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:
--
-- 'action', 'componentEvent_action' - The action to perform when a specific event is raised.
--
-- 'bindingEvent', 'componentEvent_bindingEvent' - Binds an event to an action on a component. When you specify a
-- @bindingEvent@, the event is called when the action is performed.
--
-- 'parameters', 'componentEvent_parameters' - Describes information about the action.
newComponentEvent ::
  ComponentEvent
newComponentEvent :: ComponentEvent
newComponentEvent =
  ComponentEvent'
    { $sel:action:ComponentEvent' :: Maybe Text
action = forall a. Maybe a
Prelude.Nothing,
      $sel:bindingEvent:ComponentEvent' :: Maybe Text
bindingEvent = forall a. Maybe a
Prelude.Nothing,
      $sel:parameters:ComponentEvent' :: Maybe ActionParameters
parameters = forall a. Maybe a
Prelude.Nothing
    }

-- | The action to perform when a specific event is raised.
componentEvent_action :: Lens.Lens' ComponentEvent (Prelude.Maybe Prelude.Text)
componentEvent_action :: Lens' ComponentEvent (Maybe Text)
componentEvent_action = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentEvent' {Maybe Text
action :: Maybe Text
$sel:action:ComponentEvent' :: ComponentEvent -> Maybe Text
action} -> Maybe Text
action) (\s :: ComponentEvent
s@ComponentEvent' {} Maybe Text
a -> ComponentEvent
s {$sel:action:ComponentEvent' :: Maybe Text
action = Maybe Text
a} :: ComponentEvent)

-- | Binds an event to an action on a component. When you specify a
-- @bindingEvent@, the event is called when the action is performed.
componentEvent_bindingEvent :: Lens.Lens' ComponentEvent (Prelude.Maybe Prelude.Text)
componentEvent_bindingEvent :: Lens' ComponentEvent (Maybe Text)
componentEvent_bindingEvent = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentEvent' {Maybe Text
bindingEvent :: Maybe Text
$sel:bindingEvent:ComponentEvent' :: ComponentEvent -> Maybe Text
bindingEvent} -> Maybe Text
bindingEvent) (\s :: ComponentEvent
s@ComponentEvent' {} Maybe Text
a -> ComponentEvent
s {$sel:bindingEvent:ComponentEvent' :: Maybe Text
bindingEvent = Maybe Text
a} :: ComponentEvent)

-- | Describes information about the action.
componentEvent_parameters :: Lens.Lens' ComponentEvent (Prelude.Maybe ActionParameters)
componentEvent_parameters :: Lens' ComponentEvent (Maybe ActionParameters)
componentEvent_parameters = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentEvent' {Maybe ActionParameters
parameters :: Maybe ActionParameters
$sel:parameters:ComponentEvent' :: ComponentEvent -> Maybe ActionParameters
parameters} -> Maybe ActionParameters
parameters) (\s :: ComponentEvent
s@ComponentEvent' {} Maybe ActionParameters
a -> ComponentEvent
s {$sel:parameters:ComponentEvent' :: Maybe ActionParameters
parameters = Maybe ActionParameters
a} :: ComponentEvent)

instance Data.FromJSON ComponentEvent where
  parseJSON :: Value -> Parser ComponentEvent
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ComponentEvent"
      ( \Object
x ->
          Maybe Text
-> Maybe Text -> Maybe ActionParameters -> ComponentEvent
ComponentEvent'
            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
"action")
            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
"bindingEvent")
            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
"parameters")
      )

instance Prelude.Hashable ComponentEvent where
  hashWithSalt :: Int -> ComponentEvent -> Int
hashWithSalt Int
_salt ComponentEvent' {Maybe Text
Maybe ActionParameters
parameters :: Maybe ActionParameters
bindingEvent :: Maybe Text
action :: Maybe Text
$sel:parameters:ComponentEvent' :: ComponentEvent -> Maybe ActionParameters
$sel:bindingEvent:ComponentEvent' :: ComponentEvent -> Maybe Text
$sel:action:ComponentEvent' :: ComponentEvent -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
action
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
bindingEvent
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ActionParameters
parameters

instance Prelude.NFData ComponentEvent where
  rnf :: ComponentEvent -> ()
rnf ComponentEvent' {Maybe Text
Maybe ActionParameters
parameters :: Maybe ActionParameters
bindingEvent :: Maybe Text
action :: Maybe Text
$sel:parameters:ComponentEvent' :: ComponentEvent -> Maybe ActionParameters
$sel:bindingEvent:ComponentEvent' :: ComponentEvent -> Maybe Text
$sel:action:ComponentEvent' :: ComponentEvent -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
action
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
bindingEvent
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ActionParameters
parameters

instance Data.ToJSON ComponentEvent where
  toJSON :: ComponentEvent -> Value
toJSON ComponentEvent' {Maybe Text
Maybe ActionParameters
parameters :: Maybe ActionParameters
bindingEvent :: Maybe Text
action :: Maybe Text
$sel:parameters:ComponentEvent' :: ComponentEvent -> Maybe ActionParameters
$sel:bindingEvent:ComponentEvent' :: ComponentEvent -> Maybe Text
$sel:action:ComponentEvent' :: ComponentEvent -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"action" 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 Text
action,
            (Key
"bindingEvent" 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 Text
bindingEvent,
            (Key
"parameters" 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 ActionParameters
parameters
          ]
      )