{-# 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.LexV2Models.Types.Button
-- 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.LexV2Models.Types.Button 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

-- | Describes a button to use on a response card used to gather slot values
-- from a user.
--
-- /See:/ 'newButton' smart constructor.
data Button = Button'
  { -- | The text that appears on the button. Use this to tell the user what
    -- value is returned when they choose this button.
    Button -> Text
text :: Prelude.Text,
    -- | The value returned to Amazon Lex when the user chooses this button. This
    -- must be one of the slot values configured for the slot.
    Button -> Text
value :: Prelude.Text
  }
  deriving (Button -> Button -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Button -> Button -> Bool
$c/= :: Button -> Button -> Bool
== :: Button -> Button -> Bool
$c== :: Button -> Button -> Bool
Prelude.Eq, ReadPrec [Button]
ReadPrec Button
Int -> ReadS Button
ReadS [Button]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Button]
$creadListPrec :: ReadPrec [Button]
readPrec :: ReadPrec Button
$creadPrec :: ReadPrec Button
readList :: ReadS [Button]
$creadList :: ReadS [Button]
readsPrec :: Int -> ReadS Button
$creadsPrec :: Int -> ReadS Button
Prelude.Read, Int -> Button -> ShowS
[Button] -> ShowS
Button -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Button] -> ShowS
$cshowList :: [Button] -> ShowS
show :: Button -> String
$cshow :: Button -> String
showsPrec :: Int -> Button -> ShowS
$cshowsPrec :: Int -> Button -> ShowS
Prelude.Show, forall x. Rep Button x -> Button
forall x. Button -> Rep Button x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Button x -> Button
$cfrom :: forall x. Button -> Rep Button x
Prelude.Generic)

-- |
-- Create a value of 'Button' 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:
--
-- 'text', 'button_text' - The text that appears on the button. Use this to tell the user what
-- value is returned when they choose this button.
--
-- 'value', 'button_value' - The value returned to Amazon Lex when the user chooses this button. This
-- must be one of the slot values configured for the slot.
newButton ::
  -- | 'text'
  Prelude.Text ->
  -- | 'value'
  Prelude.Text ->
  Button
newButton :: Text -> Text -> Button
newButton Text
pText_ Text
pValue_ =
  Button' {$sel:text:Button' :: Text
text = Text
pText_, $sel:value:Button' :: Text
value = Text
pValue_}

-- | The text that appears on the button. Use this to tell the user what
-- value is returned when they choose this button.
button_text :: Lens.Lens' Button Prelude.Text
button_text :: Lens' Button Text
button_text = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Button' {Text
text :: Text
$sel:text:Button' :: Button -> Text
text} -> Text
text) (\s :: Button
s@Button' {} Text
a -> Button
s {$sel:text:Button' :: Text
text = Text
a} :: Button)

-- | The value returned to Amazon Lex when the user chooses this button. This
-- must be one of the slot values configured for the slot.
button_value :: Lens.Lens' Button Prelude.Text
button_value :: Lens' Button Text
button_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Button' {Text
value :: Text
$sel:value:Button' :: Button -> Text
value} -> Text
value) (\s :: Button
s@Button' {} Text
a -> Button
s {$sel:value:Button' :: Text
value = Text
a} :: Button)

instance Data.FromJSON Button where
  parseJSON :: Value -> Parser Button
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Button"
      ( \Object
x ->
          Text -> Text -> Button
Button'
            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
"text")
            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
"value")
      )

instance Prelude.Hashable Button where
  hashWithSalt :: Int -> Button -> Int
hashWithSalt Int
_salt Button' {Text
value :: Text
text :: Text
$sel:value:Button' :: Button -> Text
$sel:text:Button' :: Button -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
text
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
value

instance Prelude.NFData Button where
  rnf :: Button -> ()
rnf Button' {Text
value :: Text
text :: Text
$sel:value:Button' :: Button -> Text
$sel:text:Button' :: Button -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
text seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
value

instance Data.ToJSON Button where
  toJSON :: Button -> Value
toJSON Button' {Text
value :: Text
text :: Text
$sel:value:Button' :: Button -> Text
$sel:text:Button' :: Button -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"text" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
text),
            forall a. a -> Maybe a
Prelude.Just (Key
"value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
value)
          ]
      )