{-# 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.KeySpaces.Types.ColumnDefinition
-- 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.KeySpaces.Types.ColumnDefinition where

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

-- | The names and data types of regular columns.
--
-- /See:/ 'newColumnDefinition' smart constructor.
data ColumnDefinition = ColumnDefinition'
  { -- | The name of the column.
    ColumnDefinition -> Text
name :: Prelude.Text,
    -- | The data type of the column. For a list of available data types, see
    -- <https://docs.aws.amazon.com/keyspaces/latest/devguide/cql.elements.html#cql.data-types Data types>
    -- in the /Amazon Keyspaces Developer Guide/.
    ColumnDefinition -> Text
type' :: Prelude.Text
  }
  deriving (ColumnDefinition -> ColumnDefinition -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ColumnDefinition -> ColumnDefinition -> Bool
$c/= :: ColumnDefinition -> ColumnDefinition -> Bool
== :: ColumnDefinition -> ColumnDefinition -> Bool
$c== :: ColumnDefinition -> ColumnDefinition -> Bool
Prelude.Eq, ReadPrec [ColumnDefinition]
ReadPrec ColumnDefinition
Int -> ReadS ColumnDefinition
ReadS [ColumnDefinition]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ColumnDefinition]
$creadListPrec :: ReadPrec [ColumnDefinition]
readPrec :: ReadPrec ColumnDefinition
$creadPrec :: ReadPrec ColumnDefinition
readList :: ReadS [ColumnDefinition]
$creadList :: ReadS [ColumnDefinition]
readsPrec :: Int -> ReadS ColumnDefinition
$creadsPrec :: Int -> ReadS ColumnDefinition
Prelude.Read, Int -> ColumnDefinition -> ShowS
[ColumnDefinition] -> ShowS
ColumnDefinition -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ColumnDefinition] -> ShowS
$cshowList :: [ColumnDefinition] -> ShowS
show :: ColumnDefinition -> String
$cshow :: ColumnDefinition -> String
showsPrec :: Int -> ColumnDefinition -> ShowS
$cshowsPrec :: Int -> ColumnDefinition -> ShowS
Prelude.Show, forall x. Rep ColumnDefinition x -> ColumnDefinition
forall x. ColumnDefinition -> Rep ColumnDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ColumnDefinition x -> ColumnDefinition
$cfrom :: forall x. ColumnDefinition -> Rep ColumnDefinition x
Prelude.Generic)

-- |
-- Create a value of 'ColumnDefinition' 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', 'columnDefinition_name' - The name of the column.
--
-- 'type'', 'columnDefinition_type' - The data type of the column. For a list of available data types, see
-- <https://docs.aws.amazon.com/keyspaces/latest/devguide/cql.elements.html#cql.data-types Data types>
-- in the /Amazon Keyspaces Developer Guide/.
newColumnDefinition ::
  -- | 'name'
  Prelude.Text ->
  -- | 'type''
  Prelude.Text ->
  ColumnDefinition
newColumnDefinition :: Text -> Text -> ColumnDefinition
newColumnDefinition Text
pName_ Text
pType_ =
  ColumnDefinition' {$sel:name:ColumnDefinition' :: Text
name = Text
pName_, $sel:type':ColumnDefinition' :: Text
type' = Text
pType_}

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

-- | The data type of the column. For a list of available data types, see
-- <https://docs.aws.amazon.com/keyspaces/latest/devguide/cql.elements.html#cql.data-types Data types>
-- in the /Amazon Keyspaces Developer Guide/.
columnDefinition_type :: Lens.Lens' ColumnDefinition Prelude.Text
columnDefinition_type :: Lens' ColumnDefinition Text
columnDefinition_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ColumnDefinition' {Text
type' :: Text
$sel:type':ColumnDefinition' :: ColumnDefinition -> Text
type'} -> Text
type') (\s :: ColumnDefinition
s@ColumnDefinition' {} Text
a -> ColumnDefinition
s {$sel:type':ColumnDefinition' :: Text
type' = Text
a} :: ColumnDefinition)

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

instance Prelude.Hashable ColumnDefinition where
  hashWithSalt :: Int -> ColumnDefinition -> Int
hashWithSalt Int
_salt ColumnDefinition' {Text
type' :: Text
name :: Text
$sel:type':ColumnDefinition' :: ColumnDefinition -> Text
$sel:name:ColumnDefinition' :: ColumnDefinition -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
type'

instance Prelude.NFData ColumnDefinition where
  rnf :: ColumnDefinition -> ()
rnf ColumnDefinition' {Text
type' :: Text
name :: Text
$sel:type':ColumnDefinition' :: ColumnDefinition -> Text
$sel:name:ColumnDefinition' :: ColumnDefinition -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
name seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
type'

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