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

import qualified Amazonka.Core as Core
import Amazonka.DynamoDB.Types.ScalarAttributeType
import qualified Amazonka.Lens as Lens
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
(AttributeDefinition -> AttributeDefinition -> Bool)
-> (AttributeDefinition -> AttributeDefinition -> Bool)
-> Eq AttributeDefinition
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]
(Int -> ReadS AttributeDefinition)
-> ReadS [AttributeDefinition]
-> ReadPrec AttributeDefinition
-> ReadPrec [AttributeDefinition]
-> Read 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
(Int -> AttributeDefinition -> ShowS)
-> (AttributeDefinition -> String)
-> ([AttributeDefinition] -> ShowS)
-> Show AttributeDefinition
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. AttributeDefinition -> Rep AttributeDefinition x)
-> (forall x. Rep AttributeDefinition x -> AttributeDefinition)
-> Generic AttributeDefinition
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' :: Text -> ScalarAttributeType -> AttributeDefinition
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 :: (Text -> f Text) -> AttributeDefinition -> f AttributeDefinition
attributeDefinition_attributeName = (AttributeDefinition -> Text)
-> (AttributeDefinition -> Text -> AttributeDefinition)
-> Lens AttributeDefinition AttributeDefinition Text Text
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 :: (ScalarAttributeType -> f ScalarAttributeType)
-> AttributeDefinition -> f AttributeDefinition
attributeDefinition_attributeType = (AttributeDefinition -> ScalarAttributeType)
-> (AttributeDefinition
    -> ScalarAttributeType -> AttributeDefinition)
-> Lens
     AttributeDefinition
     AttributeDefinition
     ScalarAttributeType
     ScalarAttributeType
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 Core.FromJSON AttributeDefinition where
  parseJSON :: Value -> Parser AttributeDefinition
parseJSON =
    String
-> (Object -> Parser AttributeDefinition)
-> Value
-> Parser AttributeDefinition
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AttributeDefinition"
      ( \Object
x ->
          Text -> ScalarAttributeType -> AttributeDefinition
AttributeDefinition'
            (Text -> ScalarAttributeType -> AttributeDefinition)
-> Parser Text
-> Parser (ScalarAttributeType -> AttributeDefinition)
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
"AttributeName")
            Parser (ScalarAttributeType -> AttributeDefinition)
-> Parser ScalarAttributeType -> Parser AttributeDefinition
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ScalarAttributeType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"AttributeType")
      )

instance Prelude.Hashable AttributeDefinition

instance Prelude.NFData AttributeDefinition

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"AttributeName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
attributeName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"AttributeType" Text -> ScalarAttributeType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ScalarAttributeType
attributeType)
          ]
      )