{-# 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.DynamoDB.Types.ParameterizedStatement
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.DynamoDB.Types.ParameterizedStatement where

import qualified Amazonka.Core as Core
import Amazonka.DynamoDB.Types.AttributeValue
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents a PartiQL statment that uses parameters.
--
-- /See:/ 'newParameterizedStatement' smart constructor.
data ParameterizedStatement = ParameterizedStatement'
  { -- | The parameter values.
    ParameterizedStatement -> Maybe (NonEmpty AttributeValue)
parameters :: Prelude.Maybe (Prelude.NonEmpty AttributeValue),
    -- | A PartiQL statment that uses parameters.
    ParameterizedStatement -> Text
statement :: Prelude.Text
  }
  deriving (ParameterizedStatement -> ParameterizedStatement -> Bool
(ParameterizedStatement -> ParameterizedStatement -> Bool)
-> (ParameterizedStatement -> ParameterizedStatement -> Bool)
-> Eq ParameterizedStatement
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ParameterizedStatement -> ParameterizedStatement -> Bool
$c/= :: ParameterizedStatement -> ParameterizedStatement -> Bool
== :: ParameterizedStatement -> ParameterizedStatement -> Bool
$c== :: ParameterizedStatement -> ParameterizedStatement -> Bool
Prelude.Eq, ReadPrec [ParameterizedStatement]
ReadPrec ParameterizedStatement
Int -> ReadS ParameterizedStatement
ReadS [ParameterizedStatement]
(Int -> ReadS ParameterizedStatement)
-> ReadS [ParameterizedStatement]
-> ReadPrec ParameterizedStatement
-> ReadPrec [ParameterizedStatement]
-> Read ParameterizedStatement
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ParameterizedStatement]
$creadListPrec :: ReadPrec [ParameterizedStatement]
readPrec :: ReadPrec ParameterizedStatement
$creadPrec :: ReadPrec ParameterizedStatement
readList :: ReadS [ParameterizedStatement]
$creadList :: ReadS [ParameterizedStatement]
readsPrec :: Int -> ReadS ParameterizedStatement
$creadsPrec :: Int -> ReadS ParameterizedStatement
Prelude.Read, Int -> ParameterizedStatement -> ShowS
[ParameterizedStatement] -> ShowS
ParameterizedStatement -> String
(Int -> ParameterizedStatement -> ShowS)
-> (ParameterizedStatement -> String)
-> ([ParameterizedStatement] -> ShowS)
-> Show ParameterizedStatement
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ParameterizedStatement] -> ShowS
$cshowList :: [ParameterizedStatement] -> ShowS
show :: ParameterizedStatement -> String
$cshow :: ParameterizedStatement -> String
showsPrec :: Int -> ParameterizedStatement -> ShowS
$cshowsPrec :: Int -> ParameterizedStatement -> ShowS
Prelude.Show, (forall x. ParameterizedStatement -> Rep ParameterizedStatement x)
-> (forall x.
    Rep ParameterizedStatement x -> ParameterizedStatement)
-> Generic ParameterizedStatement
forall x. Rep ParameterizedStatement x -> ParameterizedStatement
forall x. ParameterizedStatement -> Rep ParameterizedStatement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ParameterizedStatement x -> ParameterizedStatement
$cfrom :: forall x. ParameterizedStatement -> Rep ParameterizedStatement x
Prelude.Generic)

-- |
-- Create a value of 'ParameterizedStatement' 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:
--
-- 'parameters', 'parameterizedStatement_parameters' - The parameter values.
--
-- 'statement', 'parameterizedStatement_statement' - A PartiQL statment that uses parameters.
newParameterizedStatement ::
  -- | 'statement'
  Prelude.Text ->
  ParameterizedStatement
newParameterizedStatement :: Text -> ParameterizedStatement
newParameterizedStatement Text
pStatement_ =
  ParameterizedStatement' :: Maybe (NonEmpty AttributeValue) -> Text -> ParameterizedStatement
ParameterizedStatement'
    { $sel:parameters:ParameterizedStatement' :: Maybe (NonEmpty AttributeValue)
parameters =
        Maybe (NonEmpty AttributeValue)
forall a. Maybe a
Prelude.Nothing,
      $sel:statement:ParameterizedStatement' :: Text
statement = Text
pStatement_
    }

-- | The parameter values.
parameterizedStatement_parameters :: Lens.Lens' ParameterizedStatement (Prelude.Maybe (Prelude.NonEmpty AttributeValue))
parameterizedStatement_parameters :: (Maybe (NonEmpty AttributeValue)
 -> f (Maybe (NonEmpty AttributeValue)))
-> ParameterizedStatement -> f ParameterizedStatement
parameterizedStatement_parameters = (ParameterizedStatement -> Maybe (NonEmpty AttributeValue))
-> (ParameterizedStatement
    -> Maybe (NonEmpty AttributeValue) -> ParameterizedStatement)
-> Lens
     ParameterizedStatement
     ParameterizedStatement
     (Maybe (NonEmpty AttributeValue))
     (Maybe (NonEmpty AttributeValue))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ParameterizedStatement' {Maybe (NonEmpty AttributeValue)
parameters :: Maybe (NonEmpty AttributeValue)
$sel:parameters:ParameterizedStatement' :: ParameterizedStatement -> Maybe (NonEmpty AttributeValue)
parameters} -> Maybe (NonEmpty AttributeValue)
parameters) (\s :: ParameterizedStatement
s@ParameterizedStatement' {} Maybe (NonEmpty AttributeValue)
a -> ParameterizedStatement
s {$sel:parameters:ParameterizedStatement' :: Maybe (NonEmpty AttributeValue)
parameters = Maybe (NonEmpty AttributeValue)
a} :: ParameterizedStatement) ((Maybe (NonEmpty AttributeValue)
  -> f (Maybe (NonEmpty AttributeValue)))
 -> ParameterizedStatement -> f ParameterizedStatement)
-> ((Maybe (NonEmpty AttributeValue)
     -> f (Maybe (NonEmpty AttributeValue)))
    -> Maybe (NonEmpty AttributeValue)
    -> f (Maybe (NonEmpty AttributeValue)))
-> (Maybe (NonEmpty AttributeValue)
    -> f (Maybe (NonEmpty AttributeValue)))
-> ParameterizedStatement
-> f ParameterizedStatement
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty AttributeValue)
  (NonEmpty AttributeValue)
  (NonEmpty AttributeValue)
  (NonEmpty AttributeValue)
-> Iso
     (Maybe (NonEmpty AttributeValue))
     (Maybe (NonEmpty AttributeValue))
     (Maybe (NonEmpty AttributeValue))
     (Maybe (NonEmpty AttributeValue))
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 AnIso
  (NonEmpty AttributeValue)
  (NonEmpty AttributeValue)
  (NonEmpty AttributeValue)
  (NonEmpty AttributeValue)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A PartiQL statment that uses parameters.
parameterizedStatement_statement :: Lens.Lens' ParameterizedStatement Prelude.Text
parameterizedStatement_statement :: (Text -> f Text)
-> ParameterizedStatement -> f ParameterizedStatement
parameterizedStatement_statement = (ParameterizedStatement -> Text)
-> (ParameterizedStatement -> Text -> ParameterizedStatement)
-> Lens ParameterizedStatement ParameterizedStatement Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ParameterizedStatement' {Text
statement :: Text
$sel:statement:ParameterizedStatement' :: ParameterizedStatement -> Text
statement} -> Text
statement) (\s :: ParameterizedStatement
s@ParameterizedStatement' {} Text
a -> ParameterizedStatement
s {$sel:statement:ParameterizedStatement' :: Text
statement = Text
a} :: ParameterizedStatement)

instance Prelude.Hashable ParameterizedStatement

instance Prelude.NFData ParameterizedStatement

instance Core.ToJSON ParameterizedStatement where
  toJSON :: ParameterizedStatement -> Value
toJSON ParameterizedStatement' {Maybe (NonEmpty AttributeValue)
Text
statement :: Text
parameters :: Maybe (NonEmpty AttributeValue)
$sel:statement:ParameterizedStatement' :: ParameterizedStatement -> Text
$sel:parameters:ParameterizedStatement' :: ParameterizedStatement -> Maybe (NonEmpty AttributeValue)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Parameters" Text -> NonEmpty AttributeValue -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NonEmpty AttributeValue -> Pair)
-> Maybe (NonEmpty AttributeValue) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty AttributeValue)
parameters,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Statement" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
statement)
          ]
      )