{-# 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.RedshiftData.Types.SqlParameter
-- 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.RedshiftData.Types.SqlParameter where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A parameter used in a SQL statement.
--
-- /See:/ 'newSqlParameter' smart constructor.
data SqlParameter = SqlParameter'
  { -- | The name of the parameter.
    SqlParameter -> Text
name :: Prelude.Text,
    -- | The value of the parameter. Amazon Redshift implicitly converts to the
    -- proper data type. For more inforation, see
    -- <https://docs.aws.amazon.com/redshift/latest/dg/c_Supported_data_types.html Data types>
    -- in the /Amazon Redshift Database Developer Guide/.
    SqlParameter -> Text
value :: Prelude.Text
  }
  deriving (SqlParameter -> SqlParameter -> Bool
(SqlParameter -> SqlParameter -> Bool)
-> (SqlParameter -> SqlParameter -> Bool) -> Eq SqlParameter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SqlParameter -> SqlParameter -> Bool
$c/= :: SqlParameter -> SqlParameter -> Bool
== :: SqlParameter -> SqlParameter -> Bool
$c== :: SqlParameter -> SqlParameter -> Bool
Prelude.Eq, ReadPrec [SqlParameter]
ReadPrec SqlParameter
Int -> ReadS SqlParameter
ReadS [SqlParameter]
(Int -> ReadS SqlParameter)
-> ReadS [SqlParameter]
-> ReadPrec SqlParameter
-> ReadPrec [SqlParameter]
-> Read SqlParameter
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SqlParameter]
$creadListPrec :: ReadPrec [SqlParameter]
readPrec :: ReadPrec SqlParameter
$creadPrec :: ReadPrec SqlParameter
readList :: ReadS [SqlParameter]
$creadList :: ReadS [SqlParameter]
readsPrec :: Int -> ReadS SqlParameter
$creadsPrec :: Int -> ReadS SqlParameter
Prelude.Read, Int -> SqlParameter -> ShowS
[SqlParameter] -> ShowS
SqlParameter -> String
(Int -> SqlParameter -> ShowS)
-> (SqlParameter -> String)
-> ([SqlParameter] -> ShowS)
-> Show SqlParameter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SqlParameter] -> ShowS
$cshowList :: [SqlParameter] -> ShowS
show :: SqlParameter -> String
$cshow :: SqlParameter -> String
showsPrec :: Int -> SqlParameter -> ShowS
$cshowsPrec :: Int -> SqlParameter -> ShowS
Prelude.Show, (forall x. SqlParameter -> Rep SqlParameter x)
-> (forall x. Rep SqlParameter x -> SqlParameter)
-> Generic SqlParameter
forall x. Rep SqlParameter x -> SqlParameter
forall x. SqlParameter -> Rep SqlParameter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SqlParameter x -> SqlParameter
$cfrom :: forall x. SqlParameter -> Rep SqlParameter x
Prelude.Generic)

-- |
-- Create a value of 'SqlParameter' 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:
--
-- 'name', 'sqlParameter_name' - The name of the parameter.
--
-- 'value', 'sqlParameter_value' - The value of the parameter. Amazon Redshift implicitly converts to the
-- proper data type. For more inforation, see
-- <https://docs.aws.amazon.com/redshift/latest/dg/c_Supported_data_types.html Data types>
-- in the /Amazon Redshift Database Developer Guide/.
newSqlParameter ::
  -- | 'name'
  Prelude.Text ->
  -- | 'value'
  Prelude.Text ->
  SqlParameter
newSqlParameter :: Text -> Text -> SqlParameter
newSqlParameter Text
pName_ Text
pValue_ =
  SqlParameter' :: Text -> Text -> SqlParameter
SqlParameter' {$sel:name:SqlParameter' :: Text
name = Text
pName_, $sel:value:SqlParameter' :: Text
value = Text
pValue_}

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

-- | The value of the parameter. Amazon Redshift implicitly converts to the
-- proper data type. For more inforation, see
-- <https://docs.aws.amazon.com/redshift/latest/dg/c_Supported_data_types.html Data types>
-- in the /Amazon Redshift Database Developer Guide/.
sqlParameter_value :: Lens.Lens' SqlParameter Prelude.Text
sqlParameter_value :: (Text -> f Text) -> SqlParameter -> f SqlParameter
sqlParameter_value = (SqlParameter -> Text)
-> (SqlParameter -> Text -> SqlParameter)
-> Lens SqlParameter SqlParameter Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SqlParameter' {Text
value :: Text
$sel:value:SqlParameter' :: SqlParameter -> Text
value} -> Text
value) (\s :: SqlParameter
s@SqlParameter' {} Text
a -> SqlParameter
s {$sel:value:SqlParameter' :: Text
value = Text
a} :: SqlParameter)

instance Core.FromJSON SqlParameter where
  parseJSON :: Value -> Parser SqlParameter
parseJSON =
    String
-> (Object -> Parser SqlParameter) -> Value -> Parser SqlParameter
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SqlParameter"
      ( \Object
x ->
          Text -> Text -> SqlParameter
SqlParameter'
            (Text -> Text -> SqlParameter)
-> Parser Text -> Parser (Text -> SqlParameter)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"name") Parser (Text -> SqlParameter) -> Parser Text -> Parser SqlParameter
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"value")
      )

instance Prelude.Hashable SqlParameter

instance Prelude.NFData SqlParameter

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