{-# 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.ImageResponseCard
-- 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.ImageResponseCard where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.LexV2Models.Types.Button
import qualified Amazonka.Prelude as Prelude

-- | A card that is shown to the user by a messaging platform. You define the
-- contents of the card, the card is displayed by the platform.
--
-- When you use a response card, the response from the user is constrained
-- to the text associated with a button on the card.
--
-- /See:/ 'newImageResponseCard' smart constructor.
data ImageResponseCard = ImageResponseCard'
  { -- | A list of buttons that should be displayed on the response card. The
    -- arrangement of the buttons is determined by the platform that displays
    -- the button.
    ImageResponseCard -> Maybe [Button]
buttons :: Prelude.Maybe [Button],
    -- | The URL of an image to display on the response card. The image URL must
    -- be publicly available so that the platform displaying the response card
    -- has access to the image.
    ImageResponseCard -> Maybe Text
imageUrl :: Prelude.Maybe Prelude.Text,
    -- | The subtitle to display on the response card. The format of the subtitle
    -- is determined by the platform displaying the response card.
    ImageResponseCard -> Maybe Text
subtitle :: Prelude.Maybe Prelude.Text,
    -- | The title to display on the response card. The format of the title is
    -- determined by the platform displaying the response card.
    ImageResponseCard -> Text
title :: Prelude.Text
  }
  deriving (ImageResponseCard -> ImageResponseCard -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ImageResponseCard -> ImageResponseCard -> Bool
$c/= :: ImageResponseCard -> ImageResponseCard -> Bool
== :: ImageResponseCard -> ImageResponseCard -> Bool
$c== :: ImageResponseCard -> ImageResponseCard -> Bool
Prelude.Eq, ReadPrec [ImageResponseCard]
ReadPrec ImageResponseCard
Int -> ReadS ImageResponseCard
ReadS [ImageResponseCard]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ImageResponseCard]
$creadListPrec :: ReadPrec [ImageResponseCard]
readPrec :: ReadPrec ImageResponseCard
$creadPrec :: ReadPrec ImageResponseCard
readList :: ReadS [ImageResponseCard]
$creadList :: ReadS [ImageResponseCard]
readsPrec :: Int -> ReadS ImageResponseCard
$creadsPrec :: Int -> ReadS ImageResponseCard
Prelude.Read, Int -> ImageResponseCard -> ShowS
[ImageResponseCard] -> ShowS
ImageResponseCard -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ImageResponseCard] -> ShowS
$cshowList :: [ImageResponseCard] -> ShowS
show :: ImageResponseCard -> String
$cshow :: ImageResponseCard -> String
showsPrec :: Int -> ImageResponseCard -> ShowS
$cshowsPrec :: Int -> ImageResponseCard -> ShowS
Prelude.Show, forall x. Rep ImageResponseCard x -> ImageResponseCard
forall x. ImageResponseCard -> Rep ImageResponseCard x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ImageResponseCard x -> ImageResponseCard
$cfrom :: forall x. ImageResponseCard -> Rep ImageResponseCard x
Prelude.Generic)

-- |
-- Create a value of 'ImageResponseCard' 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:
--
-- 'buttons', 'imageResponseCard_buttons' - A list of buttons that should be displayed on the response card. The
-- arrangement of the buttons is determined by the platform that displays
-- the button.
--
-- 'imageUrl', 'imageResponseCard_imageUrl' - The URL of an image to display on the response card. The image URL must
-- be publicly available so that the platform displaying the response card
-- has access to the image.
--
-- 'subtitle', 'imageResponseCard_subtitle' - The subtitle to display on the response card. The format of the subtitle
-- is determined by the platform displaying the response card.
--
-- 'title', 'imageResponseCard_title' - The title to display on the response card. The format of the title is
-- determined by the platform displaying the response card.
newImageResponseCard ::
  -- | 'title'
  Prelude.Text ->
  ImageResponseCard
newImageResponseCard :: Text -> ImageResponseCard
newImageResponseCard Text
pTitle_ =
  ImageResponseCard'
    { $sel:buttons:ImageResponseCard' :: Maybe [Button]
buttons = forall a. Maybe a
Prelude.Nothing,
      $sel:imageUrl:ImageResponseCard' :: Maybe Text
imageUrl = forall a. Maybe a
Prelude.Nothing,
      $sel:subtitle:ImageResponseCard' :: Maybe Text
subtitle = forall a. Maybe a
Prelude.Nothing,
      $sel:title:ImageResponseCard' :: Text
title = Text
pTitle_
    }

-- | A list of buttons that should be displayed on the response card. The
-- arrangement of the buttons is determined by the platform that displays
-- the button.
imageResponseCard_buttons :: Lens.Lens' ImageResponseCard (Prelude.Maybe [Button])
imageResponseCard_buttons :: Lens' ImageResponseCard (Maybe [Button])
imageResponseCard_buttons = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ImageResponseCard' {Maybe [Button]
buttons :: Maybe [Button]
$sel:buttons:ImageResponseCard' :: ImageResponseCard -> Maybe [Button]
buttons} -> Maybe [Button]
buttons) (\s :: ImageResponseCard
s@ImageResponseCard' {} Maybe [Button]
a -> ImageResponseCard
s {$sel:buttons:ImageResponseCard' :: Maybe [Button]
buttons = Maybe [Button]
a} :: ImageResponseCard) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The URL of an image to display on the response card. The image URL must
-- be publicly available so that the platform displaying the response card
-- has access to the image.
imageResponseCard_imageUrl :: Lens.Lens' ImageResponseCard (Prelude.Maybe Prelude.Text)
imageResponseCard_imageUrl :: Lens' ImageResponseCard (Maybe Text)
imageResponseCard_imageUrl = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ImageResponseCard' {Maybe Text
imageUrl :: Maybe Text
$sel:imageUrl:ImageResponseCard' :: ImageResponseCard -> Maybe Text
imageUrl} -> Maybe Text
imageUrl) (\s :: ImageResponseCard
s@ImageResponseCard' {} Maybe Text
a -> ImageResponseCard
s {$sel:imageUrl:ImageResponseCard' :: Maybe Text
imageUrl = Maybe Text
a} :: ImageResponseCard)

-- | The subtitle to display on the response card. The format of the subtitle
-- is determined by the platform displaying the response card.
imageResponseCard_subtitle :: Lens.Lens' ImageResponseCard (Prelude.Maybe Prelude.Text)
imageResponseCard_subtitle :: Lens' ImageResponseCard (Maybe Text)
imageResponseCard_subtitle = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ImageResponseCard' {Maybe Text
subtitle :: Maybe Text
$sel:subtitle:ImageResponseCard' :: ImageResponseCard -> Maybe Text
subtitle} -> Maybe Text
subtitle) (\s :: ImageResponseCard
s@ImageResponseCard' {} Maybe Text
a -> ImageResponseCard
s {$sel:subtitle:ImageResponseCard' :: Maybe Text
subtitle = Maybe Text
a} :: ImageResponseCard)

-- | The title to display on the response card. The format of the title is
-- determined by the platform displaying the response card.
imageResponseCard_title :: Lens.Lens' ImageResponseCard Prelude.Text
imageResponseCard_title :: Lens' ImageResponseCard Text
imageResponseCard_title = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ImageResponseCard' {Text
title :: Text
$sel:title:ImageResponseCard' :: ImageResponseCard -> Text
title} -> Text
title) (\s :: ImageResponseCard
s@ImageResponseCard' {} Text
a -> ImageResponseCard
s {$sel:title:ImageResponseCard' :: Text
title = Text
a} :: ImageResponseCard)

instance Data.FromJSON ImageResponseCard where
  parseJSON :: Value -> Parser ImageResponseCard
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ImageResponseCard"
      ( \Object
x ->
          Maybe [Button]
-> Maybe Text -> Maybe Text -> Text -> ImageResponseCard
ImageResponseCard'
            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
"buttons" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"imageUrl")
            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
"subtitle")
            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
"title")
      )

instance Prelude.Hashable ImageResponseCard where
  hashWithSalt :: Int -> ImageResponseCard -> Int
hashWithSalt Int
_salt ImageResponseCard' {Maybe [Button]
Maybe Text
Text
title :: Text
subtitle :: Maybe Text
imageUrl :: Maybe Text
buttons :: Maybe [Button]
$sel:title:ImageResponseCard' :: ImageResponseCard -> Text
$sel:subtitle:ImageResponseCard' :: ImageResponseCard -> Maybe Text
$sel:imageUrl:ImageResponseCard' :: ImageResponseCard -> Maybe Text
$sel:buttons:ImageResponseCard' :: ImageResponseCard -> Maybe [Button]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Button]
buttons
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
imageUrl
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
subtitle
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
title

instance Prelude.NFData ImageResponseCard where
  rnf :: ImageResponseCard -> ()
rnf ImageResponseCard' {Maybe [Button]
Maybe Text
Text
title :: Text
subtitle :: Maybe Text
imageUrl :: Maybe Text
buttons :: Maybe [Button]
$sel:title:ImageResponseCard' :: ImageResponseCard -> Text
$sel:subtitle:ImageResponseCard' :: ImageResponseCard -> Maybe Text
$sel:imageUrl:ImageResponseCard' :: ImageResponseCard -> Maybe Text
$sel:buttons:ImageResponseCard' :: ImageResponseCard -> Maybe [Button]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Button]
buttons
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
imageUrl
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
subtitle
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
title

instance Data.ToJSON ImageResponseCard where
  toJSON :: ImageResponseCard -> Value
toJSON ImageResponseCard' {Maybe [Button]
Maybe Text
Text
title :: Text
subtitle :: Maybe Text
imageUrl :: Maybe Text
buttons :: Maybe [Button]
$sel:title:ImageResponseCard' :: ImageResponseCard -> Text
$sel:subtitle:ImageResponseCard' :: ImageResponseCard -> Maybe Text
$sel:imageUrl:ImageResponseCard' :: ImageResponseCard -> Maybe Text
$sel:buttons:ImageResponseCard' :: ImageResponseCard -> Maybe [Button]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"buttons" 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 [Button]
buttons,
            (Key
"imageUrl" 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
imageUrl,
            (Key
"subtitle" 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
subtitle,
            forall a. a -> Maybe a
Prelude.Just (Key
"title" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
title)
          ]
      )