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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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 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,
    -- | A single character that specifies the delimiter being used in the CSV
    -- file.
    CsvOptions -> Maybe Text
delimiter :: Prelude.Maybe Prelude.Text
  }
  deriving (CsvOptions -> CsvOptions -> Bool
(CsvOptions -> CsvOptions -> Bool)
-> (CsvOptions -> CsvOptions -> Bool) -> Eq CsvOptions
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]
(Int -> ReadS CsvOptions)
-> ReadS [CsvOptions]
-> ReadPrec CsvOptions
-> ReadPrec [CsvOptions]
-> Read 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
(Int -> CsvOptions -> ShowS)
-> (CsvOptions -> String)
-> ([CsvOptions] -> ShowS)
-> Show CsvOptions
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. CsvOptions -> Rep CsvOptions x)
-> (forall x. Rep CsvOptions x -> CsvOptions) -> Generic CsvOptions
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:
--
-- '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.
--
-- 'delimiter', 'csvOptions_delimiter' - A single character that specifies the delimiter being used in the CSV
-- file.
newCsvOptions ::
  CsvOptions
newCsvOptions :: CsvOptions
newCsvOptions =
  CsvOptions' :: Maybe Bool -> Maybe Text -> CsvOptions
CsvOptions'
    { $sel:headerRow:CsvOptions' :: Maybe Bool
headerRow = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:delimiter:CsvOptions' :: Maybe Text
delimiter = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: (Maybe Bool -> f (Maybe Bool)) -> CsvOptions -> f CsvOptions
csvOptions_headerRow = (CsvOptions -> Maybe Bool)
-> (CsvOptions -> Maybe Bool -> CsvOptions)
-> Lens CsvOptions CsvOptions (Maybe Bool) (Maybe Bool)
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)

-- | A single character that specifies the delimiter being used in the CSV
-- file.
csvOptions_delimiter :: Lens.Lens' CsvOptions (Prelude.Maybe Prelude.Text)
csvOptions_delimiter :: (Maybe Text -> f (Maybe Text)) -> CsvOptions -> f CsvOptions
csvOptions_delimiter = (CsvOptions -> Maybe Text)
-> (CsvOptions -> Maybe Text -> CsvOptions)
-> Lens CsvOptions CsvOptions (Maybe Text) (Maybe Text)
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)

instance Core.FromJSON CsvOptions where
  parseJSON :: Value -> Parser CsvOptions
parseJSON =
    String
-> (Object -> Parser CsvOptions) -> Value -> Parser CsvOptions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CsvOptions"
      ( \Object
x ->
          Maybe Bool -> Maybe Text -> CsvOptions
CsvOptions'
            (Maybe Bool -> Maybe Text -> CsvOptions)
-> Parser (Maybe Bool) -> Parser (Maybe Text -> CsvOptions)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"HeaderRow")
            Parser (Maybe Text -> CsvOptions)
-> Parser (Maybe Text) -> Parser CsvOptions
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Delimiter")
      )

instance Prelude.Hashable CsvOptions

instance Prelude.NFData CsvOptions

instance Core.ToJSON CsvOptions where
  toJSON :: CsvOptions -> Value
toJSON CsvOptions' {Maybe Bool
Maybe Text
delimiter :: Maybe Text
headerRow :: Maybe Bool
$sel:delimiter:CsvOptions' :: CsvOptions -> Maybe Text
$sel:headerRow:CsvOptions' :: CsvOptions -> Maybe Bool
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"HeaderRow" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
headerRow,
            (Text
"Delimiter" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
delimiter
          ]
      )