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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Provides additional mapping information when the record format uses
-- delimiters, such as CSV. For example, the following sample records use
-- CSV format, where the records use the /\'\\n\'/ as the row delimiter and
-- a comma (\",\") as the column delimiter:
--
-- @\"name1\", \"address1\"@
--
-- @\"name2\", \"address2\"@
--
-- /See:/ 'newCSVMappingParameters' smart constructor.
data CSVMappingParameters = CSVMappingParameters'
  { -- | Row delimiter. For example, in a CSV format, /\'\\n\'/ is the typical
    -- row delimiter.
    CSVMappingParameters -> Text
recordRowDelimiter :: Prelude.Text,
    -- | Column delimiter. For example, in a CSV format, a comma (\",\") is the
    -- typical column delimiter.
    CSVMappingParameters -> Text
recordColumnDelimiter :: Prelude.Text
  }
  deriving (CSVMappingParameters -> CSVMappingParameters -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CSVMappingParameters -> CSVMappingParameters -> Bool
$c/= :: CSVMappingParameters -> CSVMappingParameters -> Bool
== :: CSVMappingParameters -> CSVMappingParameters -> Bool
$c== :: CSVMappingParameters -> CSVMappingParameters -> Bool
Prelude.Eq, ReadPrec [CSVMappingParameters]
ReadPrec CSVMappingParameters
Int -> ReadS CSVMappingParameters
ReadS [CSVMappingParameters]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CSVMappingParameters]
$creadListPrec :: ReadPrec [CSVMappingParameters]
readPrec :: ReadPrec CSVMappingParameters
$creadPrec :: ReadPrec CSVMappingParameters
readList :: ReadS [CSVMappingParameters]
$creadList :: ReadS [CSVMappingParameters]
readsPrec :: Int -> ReadS CSVMappingParameters
$creadsPrec :: Int -> ReadS CSVMappingParameters
Prelude.Read, Int -> CSVMappingParameters -> ShowS
[CSVMappingParameters] -> ShowS
CSVMappingParameters -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CSVMappingParameters] -> ShowS
$cshowList :: [CSVMappingParameters] -> ShowS
show :: CSVMappingParameters -> String
$cshow :: CSVMappingParameters -> String
showsPrec :: Int -> CSVMappingParameters -> ShowS
$cshowsPrec :: Int -> CSVMappingParameters -> ShowS
Prelude.Show, forall x. Rep CSVMappingParameters x -> CSVMappingParameters
forall x. CSVMappingParameters -> Rep CSVMappingParameters x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CSVMappingParameters x -> CSVMappingParameters
$cfrom :: forall x. CSVMappingParameters -> Rep CSVMappingParameters x
Prelude.Generic)

-- |
-- Create a value of 'CSVMappingParameters' 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:
--
-- 'recordRowDelimiter', 'cSVMappingParameters_recordRowDelimiter' - Row delimiter. For example, in a CSV format, /\'\\n\'/ is the typical
-- row delimiter.
--
-- 'recordColumnDelimiter', 'cSVMappingParameters_recordColumnDelimiter' - Column delimiter. For example, in a CSV format, a comma (\",\") is the
-- typical column delimiter.
newCSVMappingParameters ::
  -- | 'recordRowDelimiter'
  Prelude.Text ->
  -- | 'recordColumnDelimiter'
  Prelude.Text ->
  CSVMappingParameters
newCSVMappingParameters :: Text -> Text -> CSVMappingParameters
newCSVMappingParameters
  Text
pRecordRowDelimiter_
  Text
pRecordColumnDelimiter_ =
    CSVMappingParameters'
      { $sel:recordRowDelimiter:CSVMappingParameters' :: Text
recordRowDelimiter =
          Text
pRecordRowDelimiter_,
        $sel:recordColumnDelimiter:CSVMappingParameters' :: Text
recordColumnDelimiter = Text
pRecordColumnDelimiter_
      }

-- | Row delimiter. For example, in a CSV format, /\'\\n\'/ is the typical
-- row delimiter.
cSVMappingParameters_recordRowDelimiter :: Lens.Lens' CSVMappingParameters Prelude.Text
cSVMappingParameters_recordRowDelimiter :: Lens' CSVMappingParameters Text
cSVMappingParameters_recordRowDelimiter = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CSVMappingParameters' {Text
recordRowDelimiter :: Text
$sel:recordRowDelimiter:CSVMappingParameters' :: CSVMappingParameters -> Text
recordRowDelimiter} -> Text
recordRowDelimiter) (\s :: CSVMappingParameters
s@CSVMappingParameters' {} Text
a -> CSVMappingParameters
s {$sel:recordRowDelimiter:CSVMappingParameters' :: Text
recordRowDelimiter = Text
a} :: CSVMappingParameters)

-- | Column delimiter. For example, in a CSV format, a comma (\",\") is the
-- typical column delimiter.
cSVMappingParameters_recordColumnDelimiter :: Lens.Lens' CSVMappingParameters Prelude.Text
cSVMappingParameters_recordColumnDelimiter :: Lens' CSVMappingParameters Text
cSVMappingParameters_recordColumnDelimiter = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CSVMappingParameters' {Text
recordColumnDelimiter :: Text
$sel:recordColumnDelimiter:CSVMappingParameters' :: CSVMappingParameters -> Text
recordColumnDelimiter} -> Text
recordColumnDelimiter) (\s :: CSVMappingParameters
s@CSVMappingParameters' {} Text
a -> CSVMappingParameters
s {$sel:recordColumnDelimiter:CSVMappingParameters' :: Text
recordColumnDelimiter = Text
a} :: CSVMappingParameters)

instance Data.FromJSON CSVMappingParameters where
  parseJSON :: Value -> Parser CSVMappingParameters
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CSVMappingParameters"
      ( \Object
x ->
          Text -> Text -> CSVMappingParameters
CSVMappingParameters'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"RecordRowDelimiter")
            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
"RecordColumnDelimiter")
      )

instance Prelude.Hashable CSVMappingParameters where
  hashWithSalt :: Int -> CSVMappingParameters -> Int
hashWithSalt Int
_salt CSVMappingParameters' {Text
recordColumnDelimiter :: Text
recordRowDelimiter :: Text
$sel:recordColumnDelimiter:CSVMappingParameters' :: CSVMappingParameters -> Text
$sel:recordRowDelimiter:CSVMappingParameters' :: CSVMappingParameters -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
recordRowDelimiter
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
recordColumnDelimiter

instance Prelude.NFData CSVMappingParameters where
  rnf :: CSVMappingParameters -> ()
rnf CSVMappingParameters' {Text
recordColumnDelimiter :: Text
recordRowDelimiter :: Text
$sel:recordColumnDelimiter:CSVMappingParameters' :: CSVMappingParameters -> Text
$sel:recordRowDelimiter:CSVMappingParameters' :: CSVMappingParameters -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
recordRowDelimiter
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
recordColumnDelimiter

instance Data.ToJSON CSVMappingParameters where
  toJSON :: CSVMappingParameters -> Value
toJSON CSVMappingParameters' {Text
recordColumnDelimiter :: Text
recordRowDelimiter :: Text
$sel:recordColumnDelimiter:CSVMappingParameters' :: CSVMappingParameters -> Text
$sel:recordRowDelimiter:CSVMappingParameters' :: CSVMappingParameters -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"RecordRowDelimiter" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
recordRowDelimiter),
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"RecordColumnDelimiter"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
recordColumnDelimiter
              )
          ]
      )