{-# 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.AttributeDefinition
-- 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.DynamoDB.Types.AttributeDefinition where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.DynamoDB.Types.AttributeValue
import Amazonka.DynamoDB.Types.ScalarAttributeType
import Amazonka.DynamoDB.Types.WriteRequest
import qualified Amazonka.Prelude as Prelude

-- | Represents an attribute for describing the key schema for the table and
-- indexes.
--
-- /See:/ 'newAttributeDefinition' smart constructor.
data AttributeDefinition = AttributeDefinition'
  { -- | A name for the attribute.
    AttributeDefinition -> Text
attributeName :: Prelude.Text,
    -- | The data type for the attribute, where:
    --
    -- -   @S@ - the attribute is of type String
    --
    -- -   @N@ - the attribute is of type Number
    --
    -- -   @B@ - the attribute is of type Binary
    AttributeDefinition -> ScalarAttributeType
attributeType :: ScalarAttributeType
  }
  deriving (AttributeDefinition -> AttributeDefinition -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttributeDefinition -> AttributeDefinition -> Bool
$c/= :: AttributeDefinition -> AttributeDefinition -> Bool
== :: AttributeDefinition -> AttributeDefinition -> Bool
$c== :: AttributeDefinition -> AttributeDefinition -> Bool
Prelude.Eq, ReadPrec [AttributeDefinition]
ReadPrec AttributeDefinition
Int -> ReadS AttributeDefinition
ReadS [AttributeDefinition]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttributeDefinition]
$creadListPrec :: ReadPrec [AttributeDefinition]
readPrec :: ReadPrec AttributeDefinition
$creadPrec :: ReadPrec AttributeDefinition
readList :: ReadS [AttributeDefinition]
$creadList :: ReadS [AttributeDefinition]
readsPrec :: Int -> ReadS AttributeDefinition
$creadsPrec :: Int -> ReadS AttributeDefinition
Prelude.Read, Int -> AttributeDefinition -> ShowS
[AttributeDefinition] -> ShowS
AttributeDefinition -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttributeDefinition] -> ShowS
$cshowList :: [AttributeDefinition] -> ShowS
show :: AttributeDefinition -> String
$cshow :: AttributeDefinition -> String
showsPrec :: Int -> AttributeDefinition -> ShowS
$cshowsPrec :: Int -> AttributeDefinition -> ShowS
Prelude.Show, forall x. Rep AttributeDefinition x -> AttributeDefinition
forall x. AttributeDefinition -> Rep AttributeDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AttributeDefinition x -> AttributeDefinition
$cfrom :: forall x. AttributeDefinition -> Rep AttributeDefinition x
Prelude.Generic)

-- |
-- Create a value of 'AttributeDefinition' 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:
--
-- 'attributeName', 'attributeDefinition_attributeName' - A name for the attribute.
--
-- 'attributeType', 'attributeDefinition_attributeType' - The data type for the attribute, where:
--
-- -   @S@ - the attribute is of type String
--
-- -   @N@ - the attribute is of type Number
--
-- -   @B@ - the attribute is of type Binary
newAttributeDefinition ::
  -- | 'attributeName'
  Prelude.Text ->
  -- | 'attributeType'
  ScalarAttributeType ->
  AttributeDefinition
newAttributeDefinition :: Text -> ScalarAttributeType -> AttributeDefinition
newAttributeDefinition
  Text
pAttributeName_
  ScalarAttributeType
pAttributeType_ =
    AttributeDefinition'
      { $sel:attributeName:AttributeDefinition' :: Text
attributeName =
          Text
pAttributeName_,
        $sel:attributeType:AttributeDefinition' :: ScalarAttributeType
attributeType = ScalarAttributeType
pAttributeType_
      }

-- | A name for the attribute.
attributeDefinition_attributeName :: Lens.Lens' AttributeDefinition Prelude.Text
attributeDefinition_attributeName :: Lens' AttributeDefinition Text
attributeDefinition_attributeName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttributeDefinition' {Text
attributeName :: Text
$sel:attributeName:AttributeDefinition' :: AttributeDefinition -> Text
attributeName} -> Text
attributeName) (\s :: AttributeDefinition
s@AttributeDefinition' {} Text
a -> AttributeDefinition
s {$sel:attributeName:AttributeDefinition' :: Text
attributeName = Text
a} :: AttributeDefinition)

-- | The data type for the attribute, where:
--
-- -   @S@ - the attribute is of type String
--
-- -   @N@ - the attribute is of type Number
--
-- -   @B@ - the attribute is of type Binary
attributeDefinition_attributeType :: Lens.Lens' AttributeDefinition ScalarAttributeType
attributeDefinition_attributeType :: Lens' AttributeDefinition ScalarAttributeType
attributeDefinition_attributeType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttributeDefinition' {ScalarAttributeType
attributeType :: ScalarAttributeType
$sel:attributeType:AttributeDefinition' :: AttributeDefinition -> ScalarAttributeType
attributeType} -> ScalarAttributeType
attributeType) (\s :: AttributeDefinition
s@AttributeDefinition' {} ScalarAttributeType
a -> AttributeDefinition
s {$sel:attributeType:AttributeDefinition' :: ScalarAttributeType
attributeType = ScalarAttributeType
a} :: AttributeDefinition)

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

instance Prelude.Hashable AttributeDefinition where
  hashWithSalt :: Int -> AttributeDefinition -> Int
hashWithSalt Int
_salt AttributeDefinition' {Text
ScalarAttributeType
attributeType :: ScalarAttributeType
attributeName :: Text
$sel:attributeType:AttributeDefinition' :: AttributeDefinition -> ScalarAttributeType
$sel:attributeName:AttributeDefinition' :: AttributeDefinition -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
attributeName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ScalarAttributeType
attributeType

instance Prelude.NFData AttributeDefinition where
  rnf :: AttributeDefinition -> ()
rnf AttributeDefinition' {Text
ScalarAttributeType
attributeType :: ScalarAttributeType
attributeName :: Text
$sel:attributeType:AttributeDefinition' :: AttributeDefinition -> ScalarAttributeType
$sel:attributeName:AttributeDefinition' :: AttributeDefinition -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
attributeName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ScalarAttributeType
attributeType

instance Data.ToJSON AttributeDefinition where
  toJSON :: AttributeDefinition -> Value
toJSON AttributeDefinition' {Text
ScalarAttributeType
attributeType :: ScalarAttributeType
attributeName :: Text
$sel:attributeType:AttributeDefinition' :: AttributeDefinition -> ScalarAttributeType
$sel:attributeName:AttributeDefinition' :: AttributeDefinition -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"AttributeName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
attributeName),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"AttributeType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ScalarAttributeType
attributeType)
          ]
      )