{-# 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.Glue.Types.Column
-- 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.Glue.Types.Column where

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

-- | A column in a @Table@.
--
-- /See:/ 'newColumn' smart constructor.
data Column = Column'
  { -- | These key-value pairs define properties associated with the column.
    Column -> Maybe (HashMap Text Text)
parameters :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The data type of the @Column@.
    Column -> Maybe Text
type' :: Prelude.Maybe Prelude.Text,
    -- | A free-form text comment.
    Column -> Maybe Text
comment :: Prelude.Maybe Prelude.Text,
    -- | The name of the @Column@.
    Column -> Text
name :: Prelude.Text
  }
  deriving (Column -> Column -> Bool
(Column -> Column -> Bool)
-> (Column -> Column -> Bool) -> Eq Column
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Column -> Column -> Bool
$c/= :: Column -> Column -> Bool
== :: Column -> Column -> Bool
$c== :: Column -> Column -> Bool
Prelude.Eq, ReadPrec [Column]
ReadPrec Column
Int -> ReadS Column
ReadS [Column]
(Int -> ReadS Column)
-> ReadS [Column]
-> ReadPrec Column
-> ReadPrec [Column]
-> Read Column
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Column]
$creadListPrec :: ReadPrec [Column]
readPrec :: ReadPrec Column
$creadPrec :: ReadPrec Column
readList :: ReadS [Column]
$creadList :: ReadS [Column]
readsPrec :: Int -> ReadS Column
$creadsPrec :: Int -> ReadS Column
Prelude.Read, Int -> Column -> ShowS
[Column] -> ShowS
Column -> String
(Int -> Column -> ShowS)
-> (Column -> String) -> ([Column] -> ShowS) -> Show Column
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Column] -> ShowS
$cshowList :: [Column] -> ShowS
show :: Column -> String
$cshow :: Column -> String
showsPrec :: Int -> Column -> ShowS
$cshowsPrec :: Int -> Column -> ShowS
Prelude.Show, (forall x. Column -> Rep Column x)
-> (forall x. Rep Column x -> Column) -> Generic Column
forall x. Rep Column x -> Column
forall x. Column -> Rep Column x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Column x -> Column
$cfrom :: forall x. Column -> Rep Column x
Prelude.Generic)

-- |
-- Create a value of 'Column' 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', 'column_parameters' - These key-value pairs define properties associated with the column.
--
-- 'type'', 'column_type' - The data type of the @Column@.
--
-- 'comment', 'column_comment' - A free-form text comment.
--
-- 'name', 'column_name' - The name of the @Column@.
newColumn ::
  -- | 'name'
  Prelude.Text ->
  Column
newColumn :: Text -> Column
newColumn Text
pName_ =
  Column' :: Maybe (HashMap Text Text)
-> Maybe Text -> Maybe Text -> Text -> Column
Column'
    { $sel:parameters:Column' :: Maybe (HashMap Text Text)
parameters = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:type':Column' :: Maybe Text
type' = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:comment:Column' :: Maybe Text
comment = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:Column' :: Text
name = Text
pName_
    }

-- | These key-value pairs define properties associated with the column.
column_parameters :: Lens.Lens' Column (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
column_parameters :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> Column -> f Column
column_parameters = (Column -> Maybe (HashMap Text Text))
-> (Column -> Maybe (HashMap Text Text) -> Column)
-> Lens
     Column
     Column
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Column' {Maybe (HashMap Text Text)
parameters :: Maybe (HashMap Text Text)
$sel:parameters:Column' :: Column -> Maybe (HashMap Text Text)
parameters} -> Maybe (HashMap Text Text)
parameters) (\s :: Column
s@Column' {} Maybe (HashMap Text Text)
a -> Column
s {$sel:parameters:Column' :: Maybe (HashMap Text Text)
parameters = Maybe (HashMap Text Text)
a} :: Column) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> Column -> f Column)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> Column
-> f Column
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The data type of the @Column@.
column_type :: Lens.Lens' Column (Prelude.Maybe Prelude.Text)
column_type :: (Maybe Text -> f (Maybe Text)) -> Column -> f Column
column_type = (Column -> Maybe Text)
-> (Column -> Maybe Text -> Column)
-> Lens Column Column (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Column' {Maybe Text
type' :: Maybe Text
$sel:type':Column' :: Column -> Maybe Text
type'} -> Maybe Text
type') (\s :: Column
s@Column' {} Maybe Text
a -> Column
s {$sel:type':Column' :: Maybe Text
type' = Maybe Text
a} :: Column)

-- | A free-form text comment.
column_comment :: Lens.Lens' Column (Prelude.Maybe Prelude.Text)
column_comment :: (Maybe Text -> f (Maybe Text)) -> Column -> f Column
column_comment = (Column -> Maybe Text)
-> (Column -> Maybe Text -> Column)
-> Lens Column Column (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Column' {Maybe Text
comment :: Maybe Text
$sel:comment:Column' :: Column -> Maybe Text
comment} -> Maybe Text
comment) (\s :: Column
s@Column' {} Maybe Text
a -> Column
s {$sel:comment:Column' :: Maybe Text
comment = Maybe Text
a} :: Column)

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

instance Core.FromJSON Column where
  parseJSON :: Value -> Parser Column
parseJSON =
    String -> (Object -> Parser Column) -> Value -> Parser Column
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Column"
      ( \Object
x ->
          Maybe (HashMap Text Text)
-> Maybe Text -> Maybe Text -> Text -> Column
Column'
            (Maybe (HashMap Text Text)
 -> Maybe Text -> Maybe Text -> Text -> Column)
-> Parser (Maybe (HashMap Text Text))
-> Parser (Maybe Text -> Maybe Text -> Text -> Column)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Text)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Parameters" Parser (Maybe (Maybe (HashMap Text Text)))
-> Maybe (HashMap Text Text) -> Parser (Maybe (HashMap Text Text))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Text)
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe Text -> Maybe Text -> Text -> Column)
-> Parser (Maybe Text) -> Parser (Maybe Text -> Text -> Column)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Type")
            Parser (Maybe Text -> Text -> Column)
-> Parser (Maybe Text) -> Parser (Text -> Column)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Comment")
            Parser (Text -> Column) -> Parser Text -> Parser Column
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
"Name")
      )

instance Prelude.Hashable Column

instance Prelude.NFData Column

instance Core.ToJSON Column where
  toJSON :: Column -> Value
toJSON Column' {Maybe Text
Maybe (HashMap Text Text)
Text
name :: Text
comment :: Maybe Text
type' :: Maybe Text
parameters :: Maybe (HashMap Text Text)
$sel:name:Column' :: Column -> Text
$sel:comment:Column' :: Column -> Maybe Text
$sel:type':Column' :: Column -> Maybe Text
$sel:parameters:Column' :: Column -> Maybe (HashMap Text Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Parameters" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
parameters,
            (Text
"Type" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
type',
            (Text
"Comment" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
comment,
            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)
          ]
      )