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

import qualified Amazonka.Core as Core
import Amazonka.KinesisAnalytics.Types.MappingParameters
import Amazonka.KinesisAnalytics.Types.RecordFormatType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes the record format and relevant mapping information that should
-- be applied to schematize the records on the stream.
--
-- /See:/ 'newRecordFormat' smart constructor.
data RecordFormat = RecordFormat'
  { -- | When configuring application input at the time of creating or updating
    -- an application, provides additional mapping information specific to the
    -- record format (such as JSON, CSV, or record fields delimited by some
    -- delimiter) on the streaming source.
    RecordFormat -> Maybe MappingParameters
mappingParameters :: Prelude.Maybe MappingParameters,
    -- | The type of record format.
    RecordFormat -> RecordFormatType
recordFormatType :: RecordFormatType
  }
  deriving (RecordFormat -> RecordFormat -> Bool
(RecordFormat -> RecordFormat -> Bool)
-> (RecordFormat -> RecordFormat -> Bool) -> Eq RecordFormat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RecordFormat -> RecordFormat -> Bool
$c/= :: RecordFormat -> RecordFormat -> Bool
== :: RecordFormat -> RecordFormat -> Bool
$c== :: RecordFormat -> RecordFormat -> Bool
Prelude.Eq, ReadPrec [RecordFormat]
ReadPrec RecordFormat
Int -> ReadS RecordFormat
ReadS [RecordFormat]
(Int -> ReadS RecordFormat)
-> ReadS [RecordFormat]
-> ReadPrec RecordFormat
-> ReadPrec [RecordFormat]
-> Read RecordFormat
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RecordFormat]
$creadListPrec :: ReadPrec [RecordFormat]
readPrec :: ReadPrec RecordFormat
$creadPrec :: ReadPrec RecordFormat
readList :: ReadS [RecordFormat]
$creadList :: ReadS [RecordFormat]
readsPrec :: Int -> ReadS RecordFormat
$creadsPrec :: Int -> ReadS RecordFormat
Prelude.Read, Int -> RecordFormat -> ShowS
[RecordFormat] -> ShowS
RecordFormat -> String
(Int -> RecordFormat -> ShowS)
-> (RecordFormat -> String)
-> ([RecordFormat] -> ShowS)
-> Show RecordFormat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RecordFormat] -> ShowS
$cshowList :: [RecordFormat] -> ShowS
show :: RecordFormat -> String
$cshow :: RecordFormat -> String
showsPrec :: Int -> RecordFormat -> ShowS
$cshowsPrec :: Int -> RecordFormat -> ShowS
Prelude.Show, (forall x. RecordFormat -> Rep RecordFormat x)
-> (forall x. Rep RecordFormat x -> RecordFormat)
-> Generic RecordFormat
forall x. Rep RecordFormat x -> RecordFormat
forall x. RecordFormat -> Rep RecordFormat x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RecordFormat x -> RecordFormat
$cfrom :: forall x. RecordFormat -> Rep RecordFormat x
Prelude.Generic)

-- |
-- Create a value of 'RecordFormat' 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:
--
-- 'mappingParameters', 'recordFormat_mappingParameters' - When configuring application input at the time of creating or updating
-- an application, provides additional mapping information specific to the
-- record format (such as JSON, CSV, or record fields delimited by some
-- delimiter) on the streaming source.
--
-- 'recordFormatType', 'recordFormat_recordFormatType' - The type of record format.
newRecordFormat ::
  -- | 'recordFormatType'
  RecordFormatType ->
  RecordFormat
newRecordFormat :: RecordFormatType -> RecordFormat
newRecordFormat RecordFormatType
pRecordFormatType_ =
  RecordFormat' :: Maybe MappingParameters -> RecordFormatType -> RecordFormat
RecordFormat'
    { $sel:mappingParameters:RecordFormat' :: Maybe MappingParameters
mappingParameters = Maybe MappingParameters
forall a. Maybe a
Prelude.Nothing,
      $sel:recordFormatType:RecordFormat' :: RecordFormatType
recordFormatType = RecordFormatType
pRecordFormatType_
    }

-- | When configuring application input at the time of creating or updating
-- an application, provides additional mapping information specific to the
-- record format (such as JSON, CSV, or record fields delimited by some
-- delimiter) on the streaming source.
recordFormat_mappingParameters :: Lens.Lens' RecordFormat (Prelude.Maybe MappingParameters)
recordFormat_mappingParameters :: (Maybe MappingParameters -> f (Maybe MappingParameters))
-> RecordFormat -> f RecordFormat
recordFormat_mappingParameters = (RecordFormat -> Maybe MappingParameters)
-> (RecordFormat -> Maybe MappingParameters -> RecordFormat)
-> Lens
     RecordFormat
     RecordFormat
     (Maybe MappingParameters)
     (Maybe MappingParameters)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RecordFormat' {Maybe MappingParameters
mappingParameters :: Maybe MappingParameters
$sel:mappingParameters:RecordFormat' :: RecordFormat -> Maybe MappingParameters
mappingParameters} -> Maybe MappingParameters
mappingParameters) (\s :: RecordFormat
s@RecordFormat' {} Maybe MappingParameters
a -> RecordFormat
s {$sel:mappingParameters:RecordFormat' :: Maybe MappingParameters
mappingParameters = Maybe MappingParameters
a} :: RecordFormat)

-- | The type of record format.
recordFormat_recordFormatType :: Lens.Lens' RecordFormat RecordFormatType
recordFormat_recordFormatType :: (RecordFormatType -> f RecordFormatType)
-> RecordFormat -> f RecordFormat
recordFormat_recordFormatType = (RecordFormat -> RecordFormatType)
-> (RecordFormat -> RecordFormatType -> RecordFormat)
-> Lens RecordFormat RecordFormat RecordFormatType RecordFormatType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RecordFormat' {RecordFormatType
recordFormatType :: RecordFormatType
$sel:recordFormatType:RecordFormat' :: RecordFormat -> RecordFormatType
recordFormatType} -> RecordFormatType
recordFormatType) (\s :: RecordFormat
s@RecordFormat' {} RecordFormatType
a -> RecordFormat
s {$sel:recordFormatType:RecordFormat' :: RecordFormatType
recordFormatType = RecordFormatType
a} :: RecordFormat)

instance Core.FromJSON RecordFormat where
  parseJSON :: Value -> Parser RecordFormat
parseJSON =
    String
-> (Object -> Parser RecordFormat) -> Value -> Parser RecordFormat
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RecordFormat"
      ( \Object
x ->
          Maybe MappingParameters -> RecordFormatType -> RecordFormat
RecordFormat'
            (Maybe MappingParameters -> RecordFormatType -> RecordFormat)
-> Parser (Maybe MappingParameters)
-> Parser (RecordFormatType -> RecordFormat)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe MappingParameters)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"MappingParameters")
            Parser (RecordFormatType -> RecordFormat)
-> Parser RecordFormatType -> Parser RecordFormat
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser RecordFormatType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"RecordFormatType")
      )

instance Prelude.Hashable RecordFormat

instance Prelude.NFData RecordFormat

instance Core.ToJSON RecordFormat where
  toJSON :: RecordFormat -> Value
toJSON RecordFormat' {Maybe MappingParameters
RecordFormatType
recordFormatType :: RecordFormatType
mappingParameters :: Maybe MappingParameters
$sel:recordFormatType:RecordFormat' :: RecordFormat -> RecordFormatType
$sel:mappingParameters:RecordFormat' :: RecordFormat -> Maybe MappingParameters
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"MappingParameters" Text -> MappingParameters -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (MappingParameters -> Pair)
-> Maybe MappingParameters -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe MappingParameters
mappingParameters,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"RecordFormatType" Text -> RecordFormatType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= RecordFormatType
recordFormatType)
          ]
      )