{-# 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.Output
-- 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.Output where

import qualified Amazonka.Core as Core
import Amazonka.KinesisAnalyticsV2.Types.DestinationSchema
import Amazonka.KinesisAnalyticsV2.Types.KinesisFirehoseOutput
import Amazonka.KinesisAnalyticsV2.Types.KinesisStreamsOutput
import Amazonka.KinesisAnalyticsV2.Types.LambdaOutput
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes a SQL-based Kinesis Data Analytics application\'s output
-- configuration, in which you identify an in-application stream and a
-- destination where you want the in-application stream data to be written.
-- The destination can be a Kinesis data stream or a Kinesis Data Firehose
-- delivery stream.
--
-- /See:/ 'newOutput' smart constructor.
data Output = Output'
  { -- | Identifies an Amazon Lambda function as the destination.
    Output -> Maybe LambdaOutput
lambdaOutput :: Prelude.Maybe LambdaOutput,
    -- | Identifies a Kinesis data stream as the destination.
    Output -> Maybe KinesisStreamsOutput
kinesisStreamsOutput :: Prelude.Maybe KinesisStreamsOutput,
    -- | Identifies a Kinesis Data Firehose delivery stream as the destination.
    Output -> Maybe KinesisFirehoseOutput
kinesisFirehoseOutput :: Prelude.Maybe KinesisFirehoseOutput,
    -- | The name of the in-application stream.
    Output -> Text
name :: Prelude.Text,
    -- | Describes the data format when records are written to the destination.
    Output -> DestinationSchema
destinationSchema :: DestinationSchema
  }
  deriving (Output -> Output -> Bool
(Output -> Output -> Bool)
-> (Output -> Output -> Bool) -> Eq Output
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Output -> Output -> Bool
$c/= :: Output -> Output -> Bool
== :: Output -> Output -> Bool
$c== :: Output -> Output -> Bool
Prelude.Eq, ReadPrec [Output]
ReadPrec Output
Int -> ReadS Output
ReadS [Output]
(Int -> ReadS Output)
-> ReadS [Output]
-> ReadPrec Output
-> ReadPrec [Output]
-> Read Output
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Output]
$creadListPrec :: ReadPrec [Output]
readPrec :: ReadPrec Output
$creadPrec :: ReadPrec Output
readList :: ReadS [Output]
$creadList :: ReadS [Output]
readsPrec :: Int -> ReadS Output
$creadsPrec :: Int -> ReadS Output
Prelude.Read, Int -> Output -> ShowS
[Output] -> ShowS
Output -> String
(Int -> Output -> ShowS)
-> (Output -> String) -> ([Output] -> ShowS) -> Show Output
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Output] -> ShowS
$cshowList :: [Output] -> ShowS
show :: Output -> String
$cshow :: Output -> String
showsPrec :: Int -> Output -> ShowS
$cshowsPrec :: Int -> Output -> ShowS
Prelude.Show, (forall x. Output -> Rep Output x)
-> (forall x. Rep Output x -> Output) -> Generic Output
forall x. Rep Output x -> Output
forall x. Output -> Rep Output x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Output x -> Output
$cfrom :: forall x. Output -> Rep Output x
Prelude.Generic)

-- |
-- Create a value of 'Output' 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:
--
-- 'lambdaOutput', 'output_lambdaOutput' - Identifies an Amazon Lambda function as the destination.
--
-- 'kinesisStreamsOutput', 'output_kinesisStreamsOutput' - Identifies a Kinesis data stream as the destination.
--
-- 'kinesisFirehoseOutput', 'output_kinesisFirehoseOutput' - Identifies a Kinesis Data Firehose delivery stream as the destination.
--
-- 'name', 'output_name' - The name of the in-application stream.
--
-- 'destinationSchema', 'output_destinationSchema' - Describes the data format when records are written to the destination.
newOutput ::
  -- | 'name'
  Prelude.Text ->
  -- | 'destinationSchema'
  DestinationSchema ->
  Output
newOutput :: Text -> DestinationSchema -> Output
newOutput Text
pName_ DestinationSchema
pDestinationSchema_ =
  Output' :: Maybe LambdaOutput
-> Maybe KinesisStreamsOutput
-> Maybe KinesisFirehoseOutput
-> Text
-> DestinationSchema
-> Output
Output'
    { $sel:lambdaOutput:Output' :: Maybe LambdaOutput
lambdaOutput = Maybe LambdaOutput
forall a. Maybe a
Prelude.Nothing,
      $sel:kinesisStreamsOutput:Output' :: Maybe KinesisStreamsOutput
kinesisStreamsOutput = Maybe KinesisStreamsOutput
forall a. Maybe a
Prelude.Nothing,
      $sel:kinesisFirehoseOutput:Output' :: Maybe KinesisFirehoseOutput
kinesisFirehoseOutput = Maybe KinesisFirehoseOutput
forall a. Maybe a
Prelude.Nothing,
      $sel:name:Output' :: Text
name = Text
pName_,
      $sel:destinationSchema:Output' :: DestinationSchema
destinationSchema = DestinationSchema
pDestinationSchema_
    }

-- | Identifies an Amazon Lambda function as the destination.
output_lambdaOutput :: Lens.Lens' Output (Prelude.Maybe LambdaOutput)
output_lambdaOutput :: (Maybe LambdaOutput -> f (Maybe LambdaOutput))
-> Output -> f Output
output_lambdaOutput = (Output -> Maybe LambdaOutput)
-> (Output -> Maybe LambdaOutput -> Output)
-> Lens Output Output (Maybe LambdaOutput) (Maybe LambdaOutput)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Output' {Maybe LambdaOutput
lambdaOutput :: Maybe LambdaOutput
$sel:lambdaOutput:Output' :: Output -> Maybe LambdaOutput
lambdaOutput} -> Maybe LambdaOutput
lambdaOutput) (\s :: Output
s@Output' {} Maybe LambdaOutput
a -> Output
s {$sel:lambdaOutput:Output' :: Maybe LambdaOutput
lambdaOutput = Maybe LambdaOutput
a} :: Output)

-- | Identifies a Kinesis data stream as the destination.
output_kinesisStreamsOutput :: Lens.Lens' Output (Prelude.Maybe KinesisStreamsOutput)
output_kinesisStreamsOutput :: (Maybe KinesisStreamsOutput -> f (Maybe KinesisStreamsOutput))
-> Output -> f Output
output_kinesisStreamsOutput = (Output -> Maybe KinesisStreamsOutput)
-> (Output -> Maybe KinesisStreamsOutput -> Output)
-> Lens
     Output
     Output
     (Maybe KinesisStreamsOutput)
     (Maybe KinesisStreamsOutput)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Output' {Maybe KinesisStreamsOutput
kinesisStreamsOutput :: Maybe KinesisStreamsOutput
$sel:kinesisStreamsOutput:Output' :: Output -> Maybe KinesisStreamsOutput
kinesisStreamsOutput} -> Maybe KinesisStreamsOutput
kinesisStreamsOutput) (\s :: Output
s@Output' {} Maybe KinesisStreamsOutput
a -> Output
s {$sel:kinesisStreamsOutput:Output' :: Maybe KinesisStreamsOutput
kinesisStreamsOutput = Maybe KinesisStreamsOutput
a} :: Output)

-- | Identifies a Kinesis Data Firehose delivery stream as the destination.
output_kinesisFirehoseOutput :: Lens.Lens' Output (Prelude.Maybe KinesisFirehoseOutput)
output_kinesisFirehoseOutput :: (Maybe KinesisFirehoseOutput -> f (Maybe KinesisFirehoseOutput))
-> Output -> f Output
output_kinesisFirehoseOutput = (Output -> Maybe KinesisFirehoseOutput)
-> (Output -> Maybe KinesisFirehoseOutput -> Output)
-> Lens
     Output
     Output
     (Maybe KinesisFirehoseOutput)
     (Maybe KinesisFirehoseOutput)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Output' {Maybe KinesisFirehoseOutput
kinesisFirehoseOutput :: Maybe KinesisFirehoseOutput
$sel:kinesisFirehoseOutput:Output' :: Output -> Maybe KinesisFirehoseOutput
kinesisFirehoseOutput} -> Maybe KinesisFirehoseOutput
kinesisFirehoseOutput) (\s :: Output
s@Output' {} Maybe KinesisFirehoseOutput
a -> Output
s {$sel:kinesisFirehoseOutput:Output' :: Maybe KinesisFirehoseOutput
kinesisFirehoseOutput = Maybe KinesisFirehoseOutput
a} :: Output)

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

-- | Describes the data format when records are written to the destination.
output_destinationSchema :: Lens.Lens' Output DestinationSchema
output_destinationSchema :: (DestinationSchema -> f DestinationSchema) -> Output -> f Output
output_destinationSchema = (Output -> DestinationSchema)
-> (Output -> DestinationSchema -> Output)
-> Lens Output Output DestinationSchema DestinationSchema
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Output' {DestinationSchema
destinationSchema :: DestinationSchema
$sel:destinationSchema:Output' :: Output -> DestinationSchema
destinationSchema} -> DestinationSchema
destinationSchema) (\s :: Output
s@Output' {} DestinationSchema
a -> Output
s {$sel:destinationSchema:Output' :: DestinationSchema
destinationSchema = DestinationSchema
a} :: Output)

instance Prelude.Hashable Output

instance Prelude.NFData Output

instance Core.ToJSON Output where
  toJSON :: Output -> Value
toJSON Output' {Maybe KinesisFirehoseOutput
Maybe KinesisStreamsOutput
Maybe LambdaOutput
Text
DestinationSchema
destinationSchema :: DestinationSchema
name :: Text
kinesisFirehoseOutput :: Maybe KinesisFirehoseOutput
kinesisStreamsOutput :: Maybe KinesisStreamsOutput
lambdaOutput :: Maybe LambdaOutput
$sel:destinationSchema:Output' :: Output -> DestinationSchema
$sel:name:Output' :: Output -> Text
$sel:kinesisFirehoseOutput:Output' :: Output -> Maybe KinesisFirehoseOutput
$sel:kinesisStreamsOutput:Output' :: Output -> Maybe KinesisStreamsOutput
$sel:lambdaOutput:Output' :: Output -> Maybe LambdaOutput
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"LambdaOutput" Text -> LambdaOutput -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (LambdaOutput -> Pair) -> Maybe LambdaOutput -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe LambdaOutput
lambdaOutput,
            (Text
"KinesisStreamsOutput" Text -> KinesisStreamsOutput -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (KinesisStreamsOutput -> Pair)
-> Maybe KinesisStreamsOutput -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe KinesisStreamsOutput
kinesisStreamsOutput,
            (Text
"KinesisFirehoseOutput" Text -> KinesisFirehoseOutput -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (KinesisFirehoseOutput -> Pair)
-> Maybe KinesisFirehoseOutput -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe KinesisFirehoseOutput
kinesisFirehoseOutput,
            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
"DestinationSchema" Text -> DestinationSchema -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= DestinationSchema
destinationSchema)
          ]
      )