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

import qualified Amazonka.Core as Core
import Amazonka.KinesisAnalytics.Types.S3ReferenceDataSource
import Amazonka.KinesisAnalytics.Types.SourceSchema
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes the reference data source by providing the source information
-- (S3 bucket name and object key name), the resulting in-application table
-- name that is created, and the necessary schema to map the data elements
-- in the Amazon S3 object to the in-application table.
--
-- /See:/ 'newReferenceDataSource' smart constructor.
data ReferenceDataSource = ReferenceDataSource'
  { -- | Identifies the S3 bucket and object that contains the reference data.
    -- Also identifies the IAM role Amazon Kinesis Analytics can assume to read
    -- this object on your behalf. An Amazon Kinesis Analytics application
    -- loads reference data only once. If the data changes, you call the
    -- @UpdateApplication@ operation to trigger reloading of data into your
    -- application.
    ReferenceDataSource -> Maybe S3ReferenceDataSource
s3ReferenceDataSource :: Prelude.Maybe S3ReferenceDataSource,
    -- | Name of the in-application table to create.
    ReferenceDataSource -> Text
tableName :: Prelude.Text,
    -- | Describes the format of the data in the streaming source, and how each
    -- data element maps to corresponding columns created in the in-application
    -- stream.
    ReferenceDataSource -> SourceSchema
referenceSchema :: SourceSchema
  }
  deriving (ReferenceDataSource -> ReferenceDataSource -> Bool
(ReferenceDataSource -> ReferenceDataSource -> Bool)
-> (ReferenceDataSource -> ReferenceDataSource -> Bool)
-> Eq ReferenceDataSource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReferenceDataSource -> ReferenceDataSource -> Bool
$c/= :: ReferenceDataSource -> ReferenceDataSource -> Bool
== :: ReferenceDataSource -> ReferenceDataSource -> Bool
$c== :: ReferenceDataSource -> ReferenceDataSource -> Bool
Prelude.Eq, ReadPrec [ReferenceDataSource]
ReadPrec ReferenceDataSource
Int -> ReadS ReferenceDataSource
ReadS [ReferenceDataSource]
(Int -> ReadS ReferenceDataSource)
-> ReadS [ReferenceDataSource]
-> ReadPrec ReferenceDataSource
-> ReadPrec [ReferenceDataSource]
-> Read ReferenceDataSource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ReferenceDataSource]
$creadListPrec :: ReadPrec [ReferenceDataSource]
readPrec :: ReadPrec ReferenceDataSource
$creadPrec :: ReadPrec ReferenceDataSource
readList :: ReadS [ReferenceDataSource]
$creadList :: ReadS [ReferenceDataSource]
readsPrec :: Int -> ReadS ReferenceDataSource
$creadsPrec :: Int -> ReadS ReferenceDataSource
Prelude.Read, Int -> ReferenceDataSource -> ShowS
[ReferenceDataSource] -> ShowS
ReferenceDataSource -> String
(Int -> ReferenceDataSource -> ShowS)
-> (ReferenceDataSource -> String)
-> ([ReferenceDataSource] -> ShowS)
-> Show ReferenceDataSource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReferenceDataSource] -> ShowS
$cshowList :: [ReferenceDataSource] -> ShowS
show :: ReferenceDataSource -> String
$cshow :: ReferenceDataSource -> String
showsPrec :: Int -> ReferenceDataSource -> ShowS
$cshowsPrec :: Int -> ReferenceDataSource -> ShowS
Prelude.Show, (forall x. ReferenceDataSource -> Rep ReferenceDataSource x)
-> (forall x. Rep ReferenceDataSource x -> ReferenceDataSource)
-> Generic ReferenceDataSource
forall x. Rep ReferenceDataSource x -> ReferenceDataSource
forall x. ReferenceDataSource -> Rep ReferenceDataSource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ReferenceDataSource x -> ReferenceDataSource
$cfrom :: forall x. ReferenceDataSource -> Rep ReferenceDataSource x
Prelude.Generic)

-- |
-- Create a value of 'ReferenceDataSource' 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:
--
-- 's3ReferenceDataSource', 'referenceDataSource_s3ReferenceDataSource' - Identifies the S3 bucket and object that contains the reference data.
-- Also identifies the IAM role Amazon Kinesis Analytics can assume to read
-- this object on your behalf. An Amazon Kinesis Analytics application
-- loads reference data only once. If the data changes, you call the
-- @UpdateApplication@ operation to trigger reloading of data into your
-- application.
--
-- 'tableName', 'referenceDataSource_tableName' - Name of the in-application table to create.
--
-- 'referenceSchema', 'referenceDataSource_referenceSchema' - Describes the format of the data in the streaming source, and how each
-- data element maps to corresponding columns created in the in-application
-- stream.
newReferenceDataSource ::
  -- | 'tableName'
  Prelude.Text ->
  -- | 'referenceSchema'
  SourceSchema ->
  ReferenceDataSource
newReferenceDataSource :: Text -> SourceSchema -> ReferenceDataSource
newReferenceDataSource Text
pTableName_ SourceSchema
pReferenceSchema_ =
  ReferenceDataSource' :: Maybe S3ReferenceDataSource
-> Text -> SourceSchema -> ReferenceDataSource
ReferenceDataSource'
    { $sel:s3ReferenceDataSource:ReferenceDataSource' :: Maybe S3ReferenceDataSource
s3ReferenceDataSource =
        Maybe S3ReferenceDataSource
forall a. Maybe a
Prelude.Nothing,
      $sel:tableName:ReferenceDataSource' :: Text
tableName = Text
pTableName_,
      $sel:referenceSchema:ReferenceDataSource' :: SourceSchema
referenceSchema = SourceSchema
pReferenceSchema_
    }

-- | Identifies the S3 bucket and object that contains the reference data.
-- Also identifies the IAM role Amazon Kinesis Analytics can assume to read
-- this object on your behalf. An Amazon Kinesis Analytics application
-- loads reference data only once. If the data changes, you call the
-- @UpdateApplication@ operation to trigger reloading of data into your
-- application.
referenceDataSource_s3ReferenceDataSource :: Lens.Lens' ReferenceDataSource (Prelude.Maybe S3ReferenceDataSource)
referenceDataSource_s3ReferenceDataSource :: (Maybe S3ReferenceDataSource -> f (Maybe S3ReferenceDataSource))
-> ReferenceDataSource -> f ReferenceDataSource
referenceDataSource_s3ReferenceDataSource = (ReferenceDataSource -> Maybe S3ReferenceDataSource)
-> (ReferenceDataSource
    -> Maybe S3ReferenceDataSource -> ReferenceDataSource)
-> Lens
     ReferenceDataSource
     ReferenceDataSource
     (Maybe S3ReferenceDataSource)
     (Maybe S3ReferenceDataSource)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReferenceDataSource' {Maybe S3ReferenceDataSource
s3ReferenceDataSource :: Maybe S3ReferenceDataSource
$sel:s3ReferenceDataSource:ReferenceDataSource' :: ReferenceDataSource -> Maybe S3ReferenceDataSource
s3ReferenceDataSource} -> Maybe S3ReferenceDataSource
s3ReferenceDataSource) (\s :: ReferenceDataSource
s@ReferenceDataSource' {} Maybe S3ReferenceDataSource
a -> ReferenceDataSource
s {$sel:s3ReferenceDataSource:ReferenceDataSource' :: Maybe S3ReferenceDataSource
s3ReferenceDataSource = Maybe S3ReferenceDataSource
a} :: ReferenceDataSource)

-- | Name of the in-application table to create.
referenceDataSource_tableName :: Lens.Lens' ReferenceDataSource Prelude.Text
referenceDataSource_tableName :: (Text -> f Text) -> ReferenceDataSource -> f ReferenceDataSource
referenceDataSource_tableName = (ReferenceDataSource -> Text)
-> (ReferenceDataSource -> Text -> ReferenceDataSource)
-> Lens ReferenceDataSource ReferenceDataSource Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReferenceDataSource' {Text
tableName :: Text
$sel:tableName:ReferenceDataSource' :: ReferenceDataSource -> Text
tableName} -> Text
tableName) (\s :: ReferenceDataSource
s@ReferenceDataSource' {} Text
a -> ReferenceDataSource
s {$sel:tableName:ReferenceDataSource' :: Text
tableName = Text
a} :: ReferenceDataSource)

-- | Describes the format of the data in the streaming source, and how each
-- data element maps to corresponding columns created in the in-application
-- stream.
referenceDataSource_referenceSchema :: Lens.Lens' ReferenceDataSource SourceSchema
referenceDataSource_referenceSchema :: (SourceSchema -> f SourceSchema)
-> ReferenceDataSource -> f ReferenceDataSource
referenceDataSource_referenceSchema = (ReferenceDataSource -> SourceSchema)
-> (ReferenceDataSource -> SourceSchema -> ReferenceDataSource)
-> Lens
     ReferenceDataSource ReferenceDataSource SourceSchema SourceSchema
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReferenceDataSource' {SourceSchema
referenceSchema :: SourceSchema
$sel:referenceSchema:ReferenceDataSource' :: ReferenceDataSource -> SourceSchema
referenceSchema} -> SourceSchema
referenceSchema) (\s :: ReferenceDataSource
s@ReferenceDataSource' {} SourceSchema
a -> ReferenceDataSource
s {$sel:referenceSchema:ReferenceDataSource' :: SourceSchema
referenceSchema = SourceSchema
a} :: ReferenceDataSource)

instance Prelude.Hashable ReferenceDataSource

instance Prelude.NFData ReferenceDataSource

instance Core.ToJSON ReferenceDataSource where
  toJSON :: ReferenceDataSource -> Value
toJSON ReferenceDataSource' {Maybe S3ReferenceDataSource
Text
SourceSchema
referenceSchema :: SourceSchema
tableName :: Text
s3ReferenceDataSource :: Maybe S3ReferenceDataSource
$sel:referenceSchema:ReferenceDataSource' :: ReferenceDataSource -> SourceSchema
$sel:tableName:ReferenceDataSource' :: ReferenceDataSource -> Text
$sel:s3ReferenceDataSource:ReferenceDataSource' :: ReferenceDataSource -> Maybe S3ReferenceDataSource
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"S3ReferenceDataSource" Text -> S3ReferenceDataSource -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (S3ReferenceDataSource -> Pair)
-> Maybe S3ReferenceDataSource -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe S3ReferenceDataSource
s3ReferenceDataSource,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"TableName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
tableName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ReferenceSchema" Text -> SourceSchema -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= SourceSchema
referenceSchema)
          ]
      )