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

import qualified Amazonka.Core as Core
import Amazonka.KinesisAnalyticsV2.Types.RecordColumn
import Amazonka.KinesisAnalyticsV2.Types.RecordFormat
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | For a SQL-based Kinesis Data Analytics application, 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.
--
-- /See:/ 'newSourceSchema' smart constructor.
data SourceSchema = SourceSchema'
  { -- | Specifies the encoding of the records in the streaming source. For
    -- example, UTF-8.
    SourceSchema -> Maybe Text
recordEncoding :: Prelude.Maybe Prelude.Text,
    -- | Specifies the format of the records on the streaming source.
    SourceSchema -> RecordFormat
recordFormat :: RecordFormat,
    -- | A list of @RecordColumn@ objects.
    SourceSchema -> NonEmpty RecordColumn
recordColumns :: Prelude.NonEmpty RecordColumn
  }
  deriving (SourceSchema -> SourceSchema -> Bool
(SourceSchema -> SourceSchema -> Bool)
-> (SourceSchema -> SourceSchema -> Bool) -> Eq SourceSchema
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SourceSchema -> SourceSchema -> Bool
$c/= :: SourceSchema -> SourceSchema -> Bool
== :: SourceSchema -> SourceSchema -> Bool
$c== :: SourceSchema -> SourceSchema -> Bool
Prelude.Eq, ReadPrec [SourceSchema]
ReadPrec SourceSchema
Int -> ReadS SourceSchema
ReadS [SourceSchema]
(Int -> ReadS SourceSchema)
-> ReadS [SourceSchema]
-> ReadPrec SourceSchema
-> ReadPrec [SourceSchema]
-> Read SourceSchema
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SourceSchema]
$creadListPrec :: ReadPrec [SourceSchema]
readPrec :: ReadPrec SourceSchema
$creadPrec :: ReadPrec SourceSchema
readList :: ReadS [SourceSchema]
$creadList :: ReadS [SourceSchema]
readsPrec :: Int -> ReadS SourceSchema
$creadsPrec :: Int -> ReadS SourceSchema
Prelude.Read, Int -> SourceSchema -> ShowS
[SourceSchema] -> ShowS
SourceSchema -> String
(Int -> SourceSchema -> ShowS)
-> (SourceSchema -> String)
-> ([SourceSchema] -> ShowS)
-> Show SourceSchema
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SourceSchema] -> ShowS
$cshowList :: [SourceSchema] -> ShowS
show :: SourceSchema -> String
$cshow :: SourceSchema -> String
showsPrec :: Int -> SourceSchema -> ShowS
$cshowsPrec :: Int -> SourceSchema -> ShowS
Prelude.Show, (forall x. SourceSchema -> Rep SourceSchema x)
-> (forall x. Rep SourceSchema x -> SourceSchema)
-> Generic SourceSchema
forall x. Rep SourceSchema x -> SourceSchema
forall x. SourceSchema -> Rep SourceSchema x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SourceSchema x -> SourceSchema
$cfrom :: forall x. SourceSchema -> Rep SourceSchema x
Prelude.Generic)

-- |
-- Create a value of 'SourceSchema' 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:
--
-- 'recordEncoding', 'sourceSchema_recordEncoding' - Specifies the encoding of the records in the streaming source. For
-- example, UTF-8.
--
-- 'recordFormat', 'sourceSchema_recordFormat' - Specifies the format of the records on the streaming source.
--
-- 'recordColumns', 'sourceSchema_recordColumns' - A list of @RecordColumn@ objects.
newSourceSchema ::
  -- | 'recordFormat'
  RecordFormat ->
  -- | 'recordColumns'
  Prelude.NonEmpty RecordColumn ->
  SourceSchema
newSourceSchema :: RecordFormat -> NonEmpty RecordColumn -> SourceSchema
newSourceSchema RecordFormat
pRecordFormat_ NonEmpty RecordColumn
pRecordColumns_ =
  SourceSchema' :: Maybe Text -> RecordFormat -> NonEmpty RecordColumn -> SourceSchema
SourceSchema'
    { $sel:recordEncoding:SourceSchema' :: Maybe Text
recordEncoding = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:recordFormat:SourceSchema' :: RecordFormat
recordFormat = RecordFormat
pRecordFormat_,
      $sel:recordColumns:SourceSchema' :: NonEmpty RecordColumn
recordColumns = Tagged (NonEmpty RecordColumn) (Identity (NonEmpty RecordColumn))
-> Tagged
     (NonEmpty RecordColumn) (Identity (NonEmpty RecordColumn))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty RecordColumn) (Identity (NonEmpty RecordColumn))
 -> Tagged
      (NonEmpty RecordColumn) (Identity (NonEmpty RecordColumn)))
-> NonEmpty RecordColumn -> NonEmpty RecordColumn
forall t b. AReview t b -> b -> t
Lens.# NonEmpty RecordColumn
pRecordColumns_
    }

-- | Specifies the encoding of the records in the streaming source. For
-- example, UTF-8.
sourceSchema_recordEncoding :: Lens.Lens' SourceSchema (Prelude.Maybe Prelude.Text)
sourceSchema_recordEncoding :: (Maybe Text -> f (Maybe Text)) -> SourceSchema -> f SourceSchema
sourceSchema_recordEncoding = (SourceSchema -> Maybe Text)
-> (SourceSchema -> Maybe Text -> SourceSchema)
-> Lens SourceSchema SourceSchema (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SourceSchema' {Maybe Text
recordEncoding :: Maybe Text
$sel:recordEncoding:SourceSchema' :: SourceSchema -> Maybe Text
recordEncoding} -> Maybe Text
recordEncoding) (\s :: SourceSchema
s@SourceSchema' {} Maybe Text
a -> SourceSchema
s {$sel:recordEncoding:SourceSchema' :: Maybe Text
recordEncoding = Maybe Text
a} :: SourceSchema)

-- | Specifies the format of the records on the streaming source.
sourceSchema_recordFormat :: Lens.Lens' SourceSchema RecordFormat
sourceSchema_recordFormat :: (RecordFormat -> f RecordFormat) -> SourceSchema -> f SourceSchema
sourceSchema_recordFormat = (SourceSchema -> RecordFormat)
-> (SourceSchema -> RecordFormat -> SourceSchema)
-> Lens SourceSchema SourceSchema RecordFormat RecordFormat
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SourceSchema' {RecordFormat
recordFormat :: RecordFormat
$sel:recordFormat:SourceSchema' :: SourceSchema -> RecordFormat
recordFormat} -> RecordFormat
recordFormat) (\s :: SourceSchema
s@SourceSchema' {} RecordFormat
a -> SourceSchema
s {$sel:recordFormat:SourceSchema' :: RecordFormat
recordFormat = RecordFormat
a} :: SourceSchema)

-- | A list of @RecordColumn@ objects.
sourceSchema_recordColumns :: Lens.Lens' SourceSchema (Prelude.NonEmpty RecordColumn)
sourceSchema_recordColumns :: (NonEmpty RecordColumn -> f (NonEmpty RecordColumn))
-> SourceSchema -> f SourceSchema
sourceSchema_recordColumns = (SourceSchema -> NonEmpty RecordColumn)
-> (SourceSchema -> NonEmpty RecordColumn -> SourceSchema)
-> Lens
     SourceSchema
     SourceSchema
     (NonEmpty RecordColumn)
     (NonEmpty RecordColumn)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SourceSchema' {NonEmpty RecordColumn
recordColumns :: NonEmpty RecordColumn
$sel:recordColumns:SourceSchema' :: SourceSchema -> NonEmpty RecordColumn
recordColumns} -> NonEmpty RecordColumn
recordColumns) (\s :: SourceSchema
s@SourceSchema' {} NonEmpty RecordColumn
a -> SourceSchema
s {$sel:recordColumns:SourceSchema' :: NonEmpty RecordColumn
recordColumns = NonEmpty RecordColumn
a} :: SourceSchema) ((NonEmpty RecordColumn -> f (NonEmpty RecordColumn))
 -> SourceSchema -> f SourceSchema)
-> ((NonEmpty RecordColumn -> f (NonEmpty RecordColumn))
    -> NonEmpty RecordColumn -> f (NonEmpty RecordColumn))
-> (NonEmpty RecordColumn -> f (NonEmpty RecordColumn))
-> SourceSchema
-> f SourceSchema
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty RecordColumn -> f (NonEmpty RecordColumn))
-> NonEmpty RecordColumn -> f (NonEmpty RecordColumn)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON SourceSchema where
  parseJSON :: Value -> Parser SourceSchema
parseJSON =
    String
-> (Object -> Parser SourceSchema) -> Value -> Parser SourceSchema
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SourceSchema"
      ( \Object
x ->
          Maybe Text -> RecordFormat -> NonEmpty RecordColumn -> SourceSchema
SourceSchema'
            (Maybe Text
 -> RecordFormat -> NonEmpty RecordColumn -> SourceSchema)
-> Parser (Maybe Text)
-> Parser (RecordFormat -> NonEmpty RecordColumn -> SourceSchema)
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
"RecordEncoding")
            Parser (RecordFormat -> NonEmpty RecordColumn -> SourceSchema)
-> Parser RecordFormat
-> Parser (NonEmpty RecordColumn -> SourceSchema)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser RecordFormat
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"RecordFormat")
            Parser (NonEmpty RecordColumn -> SourceSchema)
-> Parser (NonEmpty RecordColumn) -> Parser SourceSchema
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (NonEmpty RecordColumn)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"RecordColumns")
      )

instance Prelude.Hashable SourceSchema

instance Prelude.NFData SourceSchema

instance Core.ToJSON SourceSchema where
  toJSON :: SourceSchema -> Value
toJSON SourceSchema' {Maybe Text
NonEmpty RecordColumn
RecordFormat
recordColumns :: NonEmpty RecordColumn
recordFormat :: RecordFormat
recordEncoding :: Maybe Text
$sel:recordColumns:SourceSchema' :: SourceSchema -> NonEmpty RecordColumn
$sel:recordFormat:SourceSchema' :: SourceSchema -> RecordFormat
$sel:recordEncoding:SourceSchema' :: SourceSchema -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"RecordEncoding" 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
recordEncoding,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"RecordFormat" Text -> RecordFormat -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= RecordFormat
recordFormat),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"RecordColumns" Text -> NonEmpty RecordColumn -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty RecordColumn
recordColumns)
          ]
      )