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

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

-- | For a SQL-based Kinesis Data Analytics application, 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'
  { -- | The row delimiter. For example, in a CSV format, /\'\\n\'/ is the
    -- typical row delimiter.
    CSVMappingParameters -> Text
recordRowDelimiter :: Prelude.Text,
    -- | The column delimiter. For example, in a CSV format, a comma (\",\") is
    -- the typical column delimiter.
    CSVMappingParameters -> Text
recordColumnDelimiter :: Prelude.Text
  }
  deriving (CSVMappingParameters -> CSVMappingParameters -> Bool
(CSVMappingParameters -> CSVMappingParameters -> Bool)
-> (CSVMappingParameters -> CSVMappingParameters -> Bool)
-> Eq CSVMappingParameters
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]
(Int -> ReadS CSVMappingParameters)
-> ReadS [CSVMappingParameters]
-> ReadPrec CSVMappingParameters
-> ReadPrec [CSVMappingParameters]
-> Read 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
(Int -> CSVMappingParameters -> ShowS)
-> (CSVMappingParameters -> String)
-> ([CSVMappingParameters] -> ShowS)
-> Show CSVMappingParameters
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. CSVMappingParameters -> Rep CSVMappingParameters x)
-> (forall x. Rep CSVMappingParameters x -> CSVMappingParameters)
-> Generic CSVMappingParameters
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' - The row delimiter. For example, in a CSV format, /\'\\n\'/ is the
-- typical row delimiter.
--
-- 'recordColumnDelimiter', 'cSVMappingParameters_recordColumnDelimiter' - The 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' :: Text -> Text -> CSVMappingParameters
CSVMappingParameters'
      { $sel:recordRowDelimiter:CSVMappingParameters' :: Text
recordRowDelimiter =
          Text
pRecordRowDelimiter_,
        $sel:recordColumnDelimiter:CSVMappingParameters' :: Text
recordColumnDelimiter = Text
pRecordColumnDelimiter_
      }

-- | The row delimiter. For example, in a CSV format, /\'\\n\'/ is the
-- typical row delimiter.
cSVMappingParameters_recordRowDelimiter :: Lens.Lens' CSVMappingParameters Prelude.Text
cSVMappingParameters_recordRowDelimiter :: (Text -> f Text) -> CSVMappingParameters -> f CSVMappingParameters
cSVMappingParameters_recordRowDelimiter = (CSVMappingParameters -> Text)
-> (CSVMappingParameters -> Text -> CSVMappingParameters)
-> Lens CSVMappingParameters CSVMappingParameters Text Text
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)

-- | The column delimiter. For example, in a CSV format, a comma (\",\") is
-- the typical column delimiter.
cSVMappingParameters_recordColumnDelimiter :: Lens.Lens' CSVMappingParameters Prelude.Text
cSVMappingParameters_recordColumnDelimiter :: (Text -> f Text) -> CSVMappingParameters -> f CSVMappingParameters
cSVMappingParameters_recordColumnDelimiter = (CSVMappingParameters -> Text)
-> (CSVMappingParameters -> Text -> CSVMappingParameters)
-> Lens CSVMappingParameters CSVMappingParameters Text Text
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 Core.FromJSON CSVMappingParameters where
  parseJSON :: Value -> Parser CSVMappingParameters
parseJSON =
    String
-> (Object -> Parser CSVMappingParameters)
-> Value
-> Parser CSVMappingParameters
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CSVMappingParameters"
      ( \Object
x ->
          Text -> Text -> CSVMappingParameters
CSVMappingParameters'
            (Text -> Text -> CSVMappingParameters)
-> Parser Text -> Parser (Text -> CSVMappingParameters)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"RecordRowDelimiter")
            Parser (Text -> CSVMappingParameters)
-> Parser Text -> Parser CSVMappingParameters
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"RecordColumnDelimiter")
      )

instance Prelude.Hashable CSVMappingParameters

instance Prelude.NFData CSVMappingParameters

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"RecordRowDelimiter" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
recordRowDelimiter),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"RecordColumnDelimiter"
                  Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
recordColumnDelimiter
              )
          ]
      )