{-# 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.DynamoDB.Types.CsvOptions
-- 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.DynamoDB.Types.CsvOptions where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.DynamoDB.Types.AttributeValue
import Amazonka.DynamoDB.Types.WriteRequest
import qualified Amazonka.Prelude as Prelude

-- | Processing options for the CSV file being imported.
--
-- /See:/ 'newCsvOptions' smart constructor.
data CsvOptions = CsvOptions'
  { -- | The delimiter used for separating items in the CSV file being imported.
    CsvOptions -> Maybe Text
delimiter :: Prelude.Maybe Prelude.Text,
    -- | List of the headers used to specify a common header for all source CSV
    -- files being imported. If this field is specified then the first line of
    -- each CSV file is treated as data instead of the header. If this field is
    -- not specified the the first line of each CSV file is treated as the
    -- header.
    CsvOptions -> Maybe (NonEmpty Text)
headerList :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text)
  }
  deriving (CsvOptions -> CsvOptions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CsvOptions -> CsvOptions -> Bool
$c/= :: CsvOptions -> CsvOptions -> Bool
== :: CsvOptions -> CsvOptions -> Bool
$c== :: CsvOptions -> CsvOptions -> Bool
Prelude.Eq, ReadPrec [CsvOptions]
ReadPrec CsvOptions
Int -> ReadS CsvOptions
ReadS [CsvOptions]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CsvOptions]
$creadListPrec :: ReadPrec [CsvOptions]
readPrec :: ReadPrec CsvOptions
$creadPrec :: ReadPrec CsvOptions
readList :: ReadS [CsvOptions]
$creadList :: ReadS [CsvOptions]
readsPrec :: Int -> ReadS CsvOptions
$creadsPrec :: Int -> ReadS CsvOptions
Prelude.Read, Int -> CsvOptions -> ShowS
[CsvOptions] -> ShowS
CsvOptions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CsvOptions] -> ShowS
$cshowList :: [CsvOptions] -> ShowS
show :: CsvOptions -> String
$cshow :: CsvOptions -> String
showsPrec :: Int -> CsvOptions -> ShowS
$cshowsPrec :: Int -> CsvOptions -> ShowS
Prelude.Show, forall x. Rep CsvOptions x -> CsvOptions
forall x. CsvOptions -> Rep CsvOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CsvOptions x -> CsvOptions
$cfrom :: forall x. CsvOptions -> Rep CsvOptions x
Prelude.Generic)

-- |
-- Create a value of 'CsvOptions' 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:
--
-- 'delimiter', 'csvOptions_delimiter' - The delimiter used for separating items in the CSV file being imported.
--
-- 'headerList', 'csvOptions_headerList' - List of the headers used to specify a common header for all source CSV
-- files being imported. If this field is specified then the first line of
-- each CSV file is treated as data instead of the header. If this field is
-- not specified the the first line of each CSV file is treated as the
-- header.
newCsvOptions ::
  CsvOptions
newCsvOptions :: CsvOptions
newCsvOptions =
  CsvOptions'
    { $sel:delimiter:CsvOptions' :: Maybe Text
delimiter = forall a. Maybe a
Prelude.Nothing,
      $sel:headerList:CsvOptions' :: Maybe (NonEmpty Text)
headerList = forall a. Maybe a
Prelude.Nothing
    }

-- | The delimiter used for separating items in the CSV file being imported.
csvOptions_delimiter :: Lens.Lens' CsvOptions (Prelude.Maybe Prelude.Text)
csvOptions_delimiter :: Lens' CsvOptions (Maybe Text)
csvOptions_delimiter = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CsvOptions' {Maybe Text
delimiter :: Maybe Text
$sel:delimiter:CsvOptions' :: CsvOptions -> Maybe Text
delimiter} -> Maybe Text
delimiter) (\s :: CsvOptions
s@CsvOptions' {} Maybe Text
a -> CsvOptions
s {$sel:delimiter:CsvOptions' :: Maybe Text
delimiter = Maybe Text
a} :: CsvOptions)

-- | List of the headers used to specify a common header for all source CSV
-- files being imported. If this field is specified then the first line of
-- each CSV file is treated as data instead of the header. If this field is
-- not specified the the first line of each CSV file is treated as the
-- header.
csvOptions_headerList :: Lens.Lens' CsvOptions (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
csvOptions_headerList :: Lens' CsvOptions (Maybe (NonEmpty Text))
csvOptions_headerList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CsvOptions' {Maybe (NonEmpty Text)
headerList :: Maybe (NonEmpty Text)
$sel:headerList:CsvOptions' :: CsvOptions -> Maybe (NonEmpty Text)
headerList} -> Maybe (NonEmpty Text)
headerList) (\s :: CsvOptions
s@CsvOptions' {} Maybe (NonEmpty Text)
a -> CsvOptions
s {$sel:headerList:CsvOptions' :: Maybe (NonEmpty Text)
headerList = Maybe (NonEmpty Text)
a} :: CsvOptions) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON CsvOptions where
  parseJSON :: Value -> Parser CsvOptions
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CsvOptions"
      ( \Object
x ->
          Maybe Text -> Maybe (NonEmpty Text) -> CsvOptions
CsvOptions'
            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
"Delimiter")
            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
"HeaderList")
      )

instance Prelude.Hashable CsvOptions where
  hashWithSalt :: Int -> CsvOptions -> Int
hashWithSalt Int
_salt CsvOptions' {Maybe (NonEmpty Text)
Maybe Text
headerList :: Maybe (NonEmpty Text)
delimiter :: Maybe Text
$sel:headerList:CsvOptions' :: CsvOptions -> Maybe (NonEmpty Text)
$sel:delimiter:CsvOptions' :: CsvOptions -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
delimiter
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Text)
headerList

instance Prelude.NFData CsvOptions where
  rnf :: CsvOptions -> ()
rnf CsvOptions' {Maybe (NonEmpty Text)
Maybe Text
headerList :: Maybe (NonEmpty Text)
delimiter :: Maybe Text
$sel:headerList:CsvOptions' :: CsvOptions -> Maybe (NonEmpty Text)
$sel:delimiter:CsvOptions' :: CsvOptions -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
delimiter
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Text)
headerList

instance Data.ToJSON CsvOptions where
  toJSON :: CsvOptions -> Value
toJSON CsvOptions' {Maybe (NonEmpty Text)
Maybe Text
headerList :: Maybe (NonEmpty Text)
delimiter :: Maybe Text
$sel:headerList:CsvOptions' :: CsvOptions -> Maybe (NonEmpty Text)
$sel:delimiter:CsvOptions' :: CsvOptions -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Delimiter" 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 Text
delimiter,
            (Key
"HeaderList" 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 (NonEmpty Text)
headerList
          ]
      )