{-# 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.MappingParameters
-- 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.MappingParameters 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.CSVMappingParameters
import Amazonka.KinesisAnalytics.Types.JSONMappingParameters
import qualified Amazonka.Prelude as Prelude

-- | 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.
--
-- /See:/ 'newMappingParameters' smart constructor.
data MappingParameters = MappingParameters'
  { -- | Provides additional mapping information when the record format uses
    -- delimiters (for example, CSV).
    MappingParameters -> Maybe CSVMappingParameters
cSVMappingParameters :: Prelude.Maybe CSVMappingParameters,
    -- | Provides additional mapping information when JSON is the record format
    -- on the streaming source.
    MappingParameters -> Maybe JSONMappingParameters
jSONMappingParameters :: Prelude.Maybe JSONMappingParameters
  }
  deriving (MappingParameters -> MappingParameters -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MappingParameters -> MappingParameters -> Bool
$c/= :: MappingParameters -> MappingParameters -> Bool
== :: MappingParameters -> MappingParameters -> Bool
$c== :: MappingParameters -> MappingParameters -> Bool
Prelude.Eq, ReadPrec [MappingParameters]
ReadPrec MappingParameters
Int -> ReadS MappingParameters
ReadS [MappingParameters]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MappingParameters]
$creadListPrec :: ReadPrec [MappingParameters]
readPrec :: ReadPrec MappingParameters
$creadPrec :: ReadPrec MappingParameters
readList :: ReadS [MappingParameters]
$creadList :: ReadS [MappingParameters]
readsPrec :: Int -> ReadS MappingParameters
$creadsPrec :: Int -> ReadS MappingParameters
Prelude.Read, Int -> MappingParameters -> ShowS
[MappingParameters] -> ShowS
MappingParameters -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MappingParameters] -> ShowS
$cshowList :: [MappingParameters] -> ShowS
show :: MappingParameters -> String
$cshow :: MappingParameters -> String
showsPrec :: Int -> MappingParameters -> ShowS
$cshowsPrec :: Int -> MappingParameters -> ShowS
Prelude.Show, forall x. Rep MappingParameters x -> MappingParameters
forall x. MappingParameters -> Rep MappingParameters x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MappingParameters x -> MappingParameters
$cfrom :: forall x. MappingParameters -> Rep MappingParameters x
Prelude.Generic)

-- |
-- Create a value of 'MappingParameters' 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:
--
-- 'cSVMappingParameters', 'mappingParameters_cSVMappingParameters' - Provides additional mapping information when the record format uses
-- delimiters (for example, CSV).
--
-- 'jSONMappingParameters', 'mappingParameters_jSONMappingParameters' - Provides additional mapping information when JSON is the record format
-- on the streaming source.
newMappingParameters ::
  MappingParameters
newMappingParameters :: MappingParameters
newMappingParameters =
  MappingParameters'
    { $sel:cSVMappingParameters:MappingParameters' :: Maybe CSVMappingParameters
cSVMappingParameters =
        forall a. Maybe a
Prelude.Nothing,
      $sel:jSONMappingParameters:MappingParameters' :: Maybe JSONMappingParameters
jSONMappingParameters = forall a. Maybe a
Prelude.Nothing
    }

-- | Provides additional mapping information when the record format uses
-- delimiters (for example, CSV).
mappingParameters_cSVMappingParameters :: Lens.Lens' MappingParameters (Prelude.Maybe CSVMappingParameters)
mappingParameters_cSVMappingParameters :: Lens' MappingParameters (Maybe CSVMappingParameters)
mappingParameters_cSVMappingParameters = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MappingParameters' {Maybe CSVMappingParameters
cSVMappingParameters :: Maybe CSVMappingParameters
$sel:cSVMappingParameters:MappingParameters' :: MappingParameters -> Maybe CSVMappingParameters
cSVMappingParameters} -> Maybe CSVMappingParameters
cSVMappingParameters) (\s :: MappingParameters
s@MappingParameters' {} Maybe CSVMappingParameters
a -> MappingParameters
s {$sel:cSVMappingParameters:MappingParameters' :: Maybe CSVMappingParameters
cSVMappingParameters = Maybe CSVMappingParameters
a} :: MappingParameters)

-- | Provides additional mapping information when JSON is the record format
-- on the streaming source.
mappingParameters_jSONMappingParameters :: Lens.Lens' MappingParameters (Prelude.Maybe JSONMappingParameters)
mappingParameters_jSONMappingParameters :: Lens' MappingParameters (Maybe JSONMappingParameters)
mappingParameters_jSONMappingParameters = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MappingParameters' {Maybe JSONMappingParameters
jSONMappingParameters :: Maybe JSONMappingParameters
$sel:jSONMappingParameters:MappingParameters' :: MappingParameters -> Maybe JSONMappingParameters
jSONMappingParameters} -> Maybe JSONMappingParameters
jSONMappingParameters) (\s :: MappingParameters
s@MappingParameters' {} Maybe JSONMappingParameters
a -> MappingParameters
s {$sel:jSONMappingParameters:MappingParameters' :: Maybe JSONMappingParameters
jSONMappingParameters = Maybe JSONMappingParameters
a} :: MappingParameters)

instance Data.FromJSON MappingParameters where
  parseJSON :: Value -> Parser MappingParameters
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"MappingParameters"
      ( \Object
x ->
          Maybe CSVMappingParameters
-> Maybe JSONMappingParameters -> MappingParameters
MappingParameters'
            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
"CSVMappingParameters")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"JSONMappingParameters")
      )

instance Prelude.Hashable MappingParameters where
  hashWithSalt :: Int -> MappingParameters -> Int
hashWithSalt Int
_salt MappingParameters' {Maybe CSVMappingParameters
Maybe JSONMappingParameters
jSONMappingParameters :: Maybe JSONMappingParameters
cSVMappingParameters :: Maybe CSVMappingParameters
$sel:jSONMappingParameters:MappingParameters' :: MappingParameters -> Maybe JSONMappingParameters
$sel:cSVMappingParameters:MappingParameters' :: MappingParameters -> Maybe CSVMappingParameters
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CSVMappingParameters
cSVMappingParameters
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe JSONMappingParameters
jSONMappingParameters

instance Prelude.NFData MappingParameters where
  rnf :: MappingParameters -> ()
rnf MappingParameters' {Maybe CSVMappingParameters
Maybe JSONMappingParameters
jSONMappingParameters :: Maybe JSONMappingParameters
cSVMappingParameters :: Maybe CSVMappingParameters
$sel:jSONMappingParameters:MappingParameters' :: MappingParameters -> Maybe JSONMappingParameters
$sel:cSVMappingParameters:MappingParameters' :: MappingParameters -> Maybe CSVMappingParameters
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe CSVMappingParameters
cSVMappingParameters
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe JSONMappingParameters
jSONMappingParameters

instance Data.ToJSON MappingParameters where
  toJSON :: MappingParameters -> Value
toJSON MappingParameters' {Maybe CSVMappingParameters
Maybe JSONMappingParameters
jSONMappingParameters :: Maybe JSONMappingParameters
cSVMappingParameters :: Maybe CSVMappingParameters
$sel:jSONMappingParameters:MappingParameters' :: MappingParameters -> Maybe JSONMappingParameters
$sel:cSVMappingParameters:MappingParameters' :: MappingParameters -> Maybe CSVMappingParameters
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"CSVMappingParameters" 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 CSVMappingParameters
cSVMappingParameters,
            (Key
"JSONMappingParameters" 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 JSONMappingParameters
jSONMappingParameters
          ]
      )