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

-- | Represents a set of options that define how DataBrew will read a
-- comma-separated value (CSV) file when creating a dataset from that file.
--
-- /See:/ 'newCsvOptions' smart constructor.
data CsvOptions = CsvOptions'
  { -- | A single character that specifies the delimiter being used in the CSV
    -- file.
    CsvOptions -> Maybe Text
delimiter :: Prelude.Maybe Prelude.Text,
    -- | A variable that specifies whether the first row in the file is parsed as
    -- the header. If this value is false, column names are auto-generated.
    CsvOptions -> Maybe Bool
headerRow :: Prelude.Maybe Prelude.Bool
  }
  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' - A single character that specifies the delimiter being used in the CSV
-- file.
--
-- 'headerRow', 'csvOptions_headerRow' - A variable that specifies whether the first row in the file is parsed as
-- the header. If this value is false, column names are auto-generated.
newCsvOptions ::
  CsvOptions
newCsvOptions :: CsvOptions
newCsvOptions =
  CsvOptions'
    { $sel:delimiter:CsvOptions' :: Maybe Text
delimiter = forall a. Maybe a
Prelude.Nothing,
      $sel:headerRow:CsvOptions' :: Maybe Bool
headerRow = forall a. Maybe a
Prelude.Nothing
    }

-- | A single character that specifies the delimiter being used in the CSV
-- file.
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)

-- | A variable that specifies whether the first row in the file is parsed as
-- the header. If this value is false, column names are auto-generated.
csvOptions_headerRow :: Lens.Lens' CsvOptions (Prelude.Maybe Prelude.Bool)
csvOptions_headerRow :: Lens' CsvOptions (Maybe Bool)
csvOptions_headerRow = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CsvOptions' {Maybe Bool
headerRow :: Maybe Bool
$sel:headerRow:CsvOptions' :: CsvOptions -> Maybe Bool
headerRow} -> Maybe Bool
headerRow) (\s :: CsvOptions
s@CsvOptions' {} Maybe Bool
a -> CsvOptions
s {$sel:headerRow:CsvOptions' :: Maybe Bool
headerRow = Maybe Bool
a} :: CsvOptions)

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 Bool -> 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
"HeaderRow")
      )

instance Prelude.Hashable CsvOptions where
  hashWithSalt :: Int -> CsvOptions -> Int
hashWithSalt Int
_salt CsvOptions' {Maybe Bool
Maybe Text
headerRow :: Maybe Bool
delimiter :: Maybe Text
$sel:headerRow:CsvOptions' :: CsvOptions -> Maybe Bool
$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 Bool
headerRow

instance Prelude.NFData CsvOptions where
  rnf :: CsvOptions -> ()
rnf CsvOptions' {Maybe Bool
Maybe Text
headerRow :: Maybe Bool
delimiter :: Maybe Text
$sel:headerRow:CsvOptions' :: CsvOptions -> Maybe Bool
$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 Bool
headerRow

instance Data.ToJSON CsvOptions where
  toJSON :: CsvOptions -> Value
toJSON CsvOptions' {Maybe Bool
Maybe Text
headerRow :: Maybe Bool
delimiter :: Maybe Text
$sel:headerRow:CsvOptions' :: CsvOptions -> Maybe Bool
$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
"HeaderRow" 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 Bool
headerRow
          ]
      )