{-# 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.KinesisAnalyticsV2.Types.RecordColumn
-- 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.KinesisAnalyticsV2.Types.RecordColumn where

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

-- | For a SQL-based Kinesis Data Analytics application, describes the
-- mapping of each data element in the streaming source to the
-- corresponding column in the in-application stream.
--
-- Also used to describe the format of the reference data source.
--
-- /See:/ 'newRecordColumn' smart constructor.
data RecordColumn = RecordColumn'
  { -- | A reference to the data element in the streaming input or the reference
    -- data source.
    RecordColumn -> Maybe Text
mapping :: Prelude.Maybe Prelude.Text,
    -- | The name of the column that is created in the in-application input
    -- stream or reference table.
    RecordColumn -> Text
name :: Prelude.Text,
    -- | The type of column created in the in-application input stream or
    -- reference table.
    RecordColumn -> Text
sqlType :: Prelude.Text
  }
  deriving (RecordColumn -> RecordColumn -> Bool
(RecordColumn -> RecordColumn -> Bool)
-> (RecordColumn -> RecordColumn -> Bool) -> Eq RecordColumn
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RecordColumn -> RecordColumn -> Bool
$c/= :: RecordColumn -> RecordColumn -> Bool
== :: RecordColumn -> RecordColumn -> Bool
$c== :: RecordColumn -> RecordColumn -> Bool
Prelude.Eq, ReadPrec [RecordColumn]
ReadPrec RecordColumn
Int -> ReadS RecordColumn
ReadS [RecordColumn]
(Int -> ReadS RecordColumn)
-> ReadS [RecordColumn]
-> ReadPrec RecordColumn
-> ReadPrec [RecordColumn]
-> Read RecordColumn
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RecordColumn]
$creadListPrec :: ReadPrec [RecordColumn]
readPrec :: ReadPrec RecordColumn
$creadPrec :: ReadPrec RecordColumn
readList :: ReadS [RecordColumn]
$creadList :: ReadS [RecordColumn]
readsPrec :: Int -> ReadS RecordColumn
$creadsPrec :: Int -> ReadS RecordColumn
Prelude.Read, Int -> RecordColumn -> ShowS
[RecordColumn] -> ShowS
RecordColumn -> String
(Int -> RecordColumn -> ShowS)
-> (RecordColumn -> String)
-> ([RecordColumn] -> ShowS)
-> Show RecordColumn
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RecordColumn] -> ShowS
$cshowList :: [RecordColumn] -> ShowS
show :: RecordColumn -> String
$cshow :: RecordColumn -> String
showsPrec :: Int -> RecordColumn -> ShowS
$cshowsPrec :: Int -> RecordColumn -> ShowS
Prelude.Show, (forall x. RecordColumn -> Rep RecordColumn x)
-> (forall x. Rep RecordColumn x -> RecordColumn)
-> Generic RecordColumn
forall x. Rep RecordColumn x -> RecordColumn
forall x. RecordColumn -> Rep RecordColumn x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RecordColumn x -> RecordColumn
$cfrom :: forall x. RecordColumn -> Rep RecordColumn x
Prelude.Generic)

-- |
-- Create a value of 'RecordColumn' 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:
--
-- 'mapping', 'recordColumn_mapping' - A reference to the data element in the streaming input or the reference
-- data source.
--
-- 'name', 'recordColumn_name' - The name of the column that is created in the in-application input
-- stream or reference table.
--
-- 'sqlType', 'recordColumn_sqlType' - The type of column created in the in-application input stream or
-- reference table.
newRecordColumn ::
  -- | 'name'
  Prelude.Text ->
  -- | 'sqlType'
  Prelude.Text ->
  RecordColumn
newRecordColumn :: Text -> Text -> RecordColumn
newRecordColumn Text
pName_ Text
pSqlType_ =
  RecordColumn' :: Maybe Text -> Text -> Text -> RecordColumn
RecordColumn'
    { $sel:mapping:RecordColumn' :: Maybe Text
mapping = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:RecordColumn' :: Text
name = Text
pName_,
      $sel:sqlType:RecordColumn' :: Text
sqlType = Text
pSqlType_
    }

-- | A reference to the data element in the streaming input or the reference
-- data source.
recordColumn_mapping :: Lens.Lens' RecordColumn (Prelude.Maybe Prelude.Text)
recordColumn_mapping :: (Maybe Text -> f (Maybe Text)) -> RecordColumn -> f RecordColumn
recordColumn_mapping = (RecordColumn -> Maybe Text)
-> (RecordColumn -> Maybe Text -> RecordColumn)
-> Lens RecordColumn RecordColumn (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RecordColumn' {Maybe Text
mapping :: Maybe Text
$sel:mapping:RecordColumn' :: RecordColumn -> Maybe Text
mapping} -> Maybe Text
mapping) (\s :: RecordColumn
s@RecordColumn' {} Maybe Text
a -> RecordColumn
s {$sel:mapping:RecordColumn' :: Maybe Text
mapping = Maybe Text
a} :: RecordColumn)

-- | The name of the column that is created in the in-application input
-- stream or reference table.
recordColumn_name :: Lens.Lens' RecordColumn Prelude.Text
recordColumn_name :: (Text -> f Text) -> RecordColumn -> f RecordColumn
recordColumn_name = (RecordColumn -> Text)
-> (RecordColumn -> Text -> RecordColumn)
-> Lens RecordColumn RecordColumn Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RecordColumn' {Text
name :: Text
$sel:name:RecordColumn' :: RecordColumn -> Text
name} -> Text
name) (\s :: RecordColumn
s@RecordColumn' {} Text
a -> RecordColumn
s {$sel:name:RecordColumn' :: Text
name = Text
a} :: RecordColumn)

-- | The type of column created in the in-application input stream or
-- reference table.
recordColumn_sqlType :: Lens.Lens' RecordColumn Prelude.Text
recordColumn_sqlType :: (Text -> f Text) -> RecordColumn -> f RecordColumn
recordColumn_sqlType = (RecordColumn -> Text)
-> (RecordColumn -> Text -> RecordColumn)
-> Lens RecordColumn RecordColumn Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RecordColumn' {Text
sqlType :: Text
$sel:sqlType:RecordColumn' :: RecordColumn -> Text
sqlType} -> Text
sqlType) (\s :: RecordColumn
s@RecordColumn' {} Text
a -> RecordColumn
s {$sel:sqlType:RecordColumn' :: Text
sqlType = Text
a} :: RecordColumn)

instance Core.FromJSON RecordColumn where
  parseJSON :: Value -> Parser RecordColumn
parseJSON =
    String
-> (Object -> Parser RecordColumn) -> Value -> Parser RecordColumn
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RecordColumn"
      ( \Object
x ->
          Maybe Text -> Text -> Text -> RecordColumn
RecordColumn'
            (Maybe Text -> Text -> Text -> RecordColumn)
-> Parser (Maybe Text) -> Parser (Text -> Text -> RecordColumn)
forall (f :: * -> *) a b. Functor 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
"Mapping")
            Parser (Text -> Text -> RecordColumn)
-> Parser Text -> Parser (Text -> RecordColumn)
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")
            Parser (Text -> RecordColumn) -> Parser Text -> Parser RecordColumn
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
"SqlType")
      )

instance Prelude.Hashable RecordColumn

instance Prelude.NFData RecordColumn

instance Core.ToJSON RecordColumn where
  toJSON :: RecordColumn -> Value
toJSON RecordColumn' {Maybe Text
Text
sqlType :: Text
name :: Text
mapping :: Maybe Text
$sel:sqlType:RecordColumn' :: RecordColumn -> Text
$sel:name:RecordColumn' :: RecordColumn -> Text
$sel:mapping:RecordColumn' :: RecordColumn -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Mapping" 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
mapping,
            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
"SqlType" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
sqlType)
          ]
      )