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

-- | 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'
  { -- | Reference to the data element in the streaming input or the reference
    -- data source. This element is required if the
    -- <https://docs.aws.amazon.com/kinesisanalytics/latest/dev/API_RecordFormat.html#analytics-Type-RecordFormat-RecordFormatTypel RecordFormatType>
    -- is @JSON@.
    RecordColumn -> Maybe Text
mapping :: Prelude.Maybe Prelude.Text,
    -- | Name of the column created in the in-application input stream or
    -- reference table.
    RecordColumn -> Text
name :: Prelude.Text,
    -- | Type of column created in the in-application input stream or reference
    -- table.
    RecordColumn -> Text
sqlType :: Prelude.Text
  }
  deriving (RecordColumn -> RecordColumn -> Bool
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]
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
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. 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' - Reference to the data element in the streaming input or the reference
-- data source. This element is required if the
-- <https://docs.aws.amazon.com/kinesisanalytics/latest/dev/API_RecordFormat.html#analytics-Type-RecordFormat-RecordFormatTypel RecordFormatType>
-- is @JSON@.
--
-- 'name', 'recordColumn_name' - Name of the column created in the in-application input stream or
-- reference table.
--
-- 'sqlType', 'recordColumn_sqlType' - 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'
    { $sel:mapping:RecordColumn' :: Maybe Text
mapping = forall a. Maybe a
Prelude.Nothing,
      $sel:name:RecordColumn' :: Text
name = Text
pName_,
      $sel:sqlType:RecordColumn' :: Text
sqlType = Text
pSqlType_
    }

-- | Reference to the data element in the streaming input or the reference
-- data source. This element is required if the
-- <https://docs.aws.amazon.com/kinesisanalytics/latest/dev/API_RecordFormat.html#analytics-Type-RecordFormat-RecordFormatTypel RecordFormatType>
-- is @JSON@.
recordColumn_mapping :: Lens.Lens' RecordColumn (Prelude.Maybe Prelude.Text)
recordColumn_mapping :: Lens' RecordColumn (Maybe Text)
recordColumn_mapping = 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)

-- | Name of the column created in the in-application input stream or
-- reference table.
recordColumn_name :: Lens.Lens' RecordColumn Prelude.Text
recordColumn_name :: Lens' RecordColumn Text
recordColumn_name = 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)

-- | Type of column created in the in-application input stream or reference
-- table.
recordColumn_sqlType :: Lens.Lens' RecordColumn Prelude.Text
recordColumn_sqlType :: Lens' RecordColumn Text
recordColumn_sqlType = 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 Data.FromJSON RecordColumn where
  parseJSON :: Value -> Parser RecordColumn
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RecordColumn"
      ( \Object
x ->
          Maybe Text -> Text -> Text -> RecordColumn
RecordColumn'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Mapping")
            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
"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
"SqlType")
      )

instance Prelude.Hashable RecordColumn where
  hashWithSalt :: Int -> RecordColumn -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
mapping
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
sqlType

instance Prelude.NFData RecordColumn where
  rnf :: RecordColumn -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
mapping
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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
sqlType

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Mapping" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
mapping,
            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
"SqlType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
sqlType)
          ]
      )