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

import qualified Amazonka.Core as Core
import Amazonka.KinesisAnalytics.Types.CSVMappingParameters
import Amazonka.KinesisAnalytics.Types.JSONMappingParameters
import qualified Amazonka.Lens as Lens
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
(MappingParameters -> MappingParameters -> Bool)
-> (MappingParameters -> MappingParameters -> Bool)
-> Eq MappingParameters
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]
(Int -> ReadS MappingParameters)
-> ReadS [MappingParameters]
-> ReadPrec MappingParameters
-> ReadPrec [MappingParameters]
-> Read 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
(Int -> MappingParameters -> ShowS)
-> (MappingParameters -> String)
-> ([MappingParameters] -> ShowS)
-> Show MappingParameters
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. MappingParameters -> Rep MappingParameters x)
-> (forall x. Rep MappingParameters x -> MappingParameters)
-> Generic MappingParameters
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' :: Maybe CSVMappingParameters
-> Maybe JSONMappingParameters -> MappingParameters
MappingParameters'
    { $sel:cSVMappingParameters:MappingParameters' :: Maybe CSVMappingParameters
cSVMappingParameters =
        Maybe CSVMappingParameters
forall a. Maybe a
Prelude.Nothing,
      $sel:jSONMappingParameters:MappingParameters' :: Maybe JSONMappingParameters
jSONMappingParameters = Maybe 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 :: (Maybe CSVMappingParameters -> f (Maybe CSVMappingParameters))
-> MappingParameters -> f MappingParameters
mappingParameters_cSVMappingParameters = (MappingParameters -> Maybe CSVMappingParameters)
-> (MappingParameters
    -> Maybe CSVMappingParameters -> MappingParameters)
-> Lens
     MappingParameters
     MappingParameters
     (Maybe CSVMappingParameters)
     (Maybe 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 :: (Maybe JSONMappingParameters -> f (Maybe JSONMappingParameters))
-> MappingParameters -> f MappingParameters
mappingParameters_jSONMappingParameters = (MappingParameters -> Maybe JSONMappingParameters)
-> (MappingParameters
    -> Maybe JSONMappingParameters -> MappingParameters)
-> Lens
     MappingParameters
     MappingParameters
     (Maybe JSONMappingParameters)
     (Maybe 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 Core.FromJSON MappingParameters where
  parseJSON :: Value -> Parser MappingParameters
parseJSON =
    String
-> (Object -> Parser MappingParameters)
-> Value
-> Parser MappingParameters
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"MappingParameters"
      ( \Object
x ->
          Maybe CSVMappingParameters
-> Maybe JSONMappingParameters -> MappingParameters
MappingParameters'
            (Maybe CSVMappingParameters
 -> Maybe JSONMappingParameters -> MappingParameters)
-> Parser (Maybe CSVMappingParameters)
-> Parser (Maybe JSONMappingParameters -> MappingParameters)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe CSVMappingParameters)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"CSVMappingParameters")
            Parser (Maybe JSONMappingParameters -> MappingParameters)
-> Parser (Maybe JSONMappingParameters) -> Parser MappingParameters
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe JSONMappingParameters)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"JSONMappingParameters")
      )

instance Prelude.Hashable MappingParameters

instance Prelude.NFData MappingParameters

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"CSVMappingParameters" Text -> CSVMappingParameters -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (CSVMappingParameters -> Pair)
-> Maybe CSVMappingParameters -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe CSVMappingParameters
cSVMappingParameters,
            (Text
"JSONMappingParameters" Text -> JSONMappingParameters -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (JSONMappingParameters -> Pair)
-> Maybe JSONMappingParameters -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe JSONMappingParameters
jSONMappingParameters
          ]
      )