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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.KinesisAnalytics.Types.RecordColumn
import Amazonka.KinesisAnalytics.Types.RecordFormat
import qualified Amazonka.Prelude as Prelude

-- | 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
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]
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
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. 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'
    { $sel:recordEncoding:SourceSchema' :: Maybe Text
recordEncoding = forall a. Maybe a
Prelude.Nothing,
      $sel:recordFormat:SourceSchema' :: RecordFormat
recordFormat = RecordFormat
pRecordFormat_,
      $sel:recordColumns:SourceSchema' :: NonEmpty RecordColumn
recordColumns = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced 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 :: Lens' SourceSchema (Maybe Text)
sourceSchema_recordEncoding = 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 :: Lens' SourceSchema RecordFormat
sourceSchema_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 :: Lens' SourceSchema (NonEmpty RecordColumn)
sourceSchema_recordColumns = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable SourceSchema where
  hashWithSalt :: Int -> SourceSchema -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
recordEncoding
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` RecordFormat
recordFormat
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty RecordColumn
recordColumns

instance Prelude.NFData SourceSchema where
  rnf :: SourceSchema -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
recordEncoding
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf RecordFormat
recordFormat
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty RecordColumn
recordColumns

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"RecordEncoding" 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
recordEncoding,
            forall a. a -> Maybe a
Prelude.Just (Key
"RecordFormat" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= RecordFormat
recordFormat),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"RecordColumns" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty RecordColumn
recordColumns)
          ]
      )