{-# 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.LookoutMetrics.Types.CsvFormatDescriptor
-- 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.LookoutMetrics.Types.CsvFormatDescriptor where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.LookoutMetrics.Types.CSVFileCompression
import qualified Amazonka.Prelude as Prelude

-- | Contains information about how a source CSV data file should be
-- analyzed.
--
-- /See:/ 'newCsvFormatDescriptor' smart constructor.
data CsvFormatDescriptor = CsvFormatDescriptor'
  { -- | The character set in which the source CSV file is written.
    CsvFormatDescriptor -> Maybe Text
charset :: Prelude.Maybe Prelude.Text,
    -- | Whether or not the source CSV file contains a header.
    CsvFormatDescriptor -> Maybe Bool
containsHeader :: Prelude.Maybe Prelude.Bool,
    -- | The character used to delimit the source CSV file.
    CsvFormatDescriptor -> Maybe Text
delimiter :: Prelude.Maybe Prelude.Text,
    -- | The level of compression of the source CSV file.
    CsvFormatDescriptor -> Maybe CSVFileCompression
fileCompression :: Prelude.Maybe CSVFileCompression,
    -- | A list of the source CSV file\'s headers, if any.
    CsvFormatDescriptor -> Maybe [Text]
headerList :: Prelude.Maybe [Prelude.Text],
    -- | The character used as a quote character.
    CsvFormatDescriptor -> Maybe Text
quoteSymbol :: Prelude.Maybe Prelude.Text
  }
  deriving (CsvFormatDescriptor -> CsvFormatDescriptor -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CsvFormatDescriptor -> CsvFormatDescriptor -> Bool
$c/= :: CsvFormatDescriptor -> CsvFormatDescriptor -> Bool
== :: CsvFormatDescriptor -> CsvFormatDescriptor -> Bool
$c== :: CsvFormatDescriptor -> CsvFormatDescriptor -> Bool
Prelude.Eq, ReadPrec [CsvFormatDescriptor]
ReadPrec CsvFormatDescriptor
Int -> ReadS CsvFormatDescriptor
ReadS [CsvFormatDescriptor]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CsvFormatDescriptor]
$creadListPrec :: ReadPrec [CsvFormatDescriptor]
readPrec :: ReadPrec CsvFormatDescriptor
$creadPrec :: ReadPrec CsvFormatDescriptor
readList :: ReadS [CsvFormatDescriptor]
$creadList :: ReadS [CsvFormatDescriptor]
readsPrec :: Int -> ReadS CsvFormatDescriptor
$creadsPrec :: Int -> ReadS CsvFormatDescriptor
Prelude.Read, Int -> CsvFormatDescriptor -> ShowS
[CsvFormatDescriptor] -> ShowS
CsvFormatDescriptor -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CsvFormatDescriptor] -> ShowS
$cshowList :: [CsvFormatDescriptor] -> ShowS
show :: CsvFormatDescriptor -> String
$cshow :: CsvFormatDescriptor -> String
showsPrec :: Int -> CsvFormatDescriptor -> ShowS
$cshowsPrec :: Int -> CsvFormatDescriptor -> ShowS
Prelude.Show, forall x. Rep CsvFormatDescriptor x -> CsvFormatDescriptor
forall x. CsvFormatDescriptor -> Rep CsvFormatDescriptor x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CsvFormatDescriptor x -> CsvFormatDescriptor
$cfrom :: forall x. CsvFormatDescriptor -> Rep CsvFormatDescriptor x
Prelude.Generic)

-- |
-- Create a value of 'CsvFormatDescriptor' 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:
--
-- 'charset', 'csvFormatDescriptor_charset' - The character set in which the source CSV file is written.
--
-- 'containsHeader', 'csvFormatDescriptor_containsHeader' - Whether or not the source CSV file contains a header.
--
-- 'delimiter', 'csvFormatDescriptor_delimiter' - The character used to delimit the source CSV file.
--
-- 'fileCompression', 'csvFormatDescriptor_fileCompression' - The level of compression of the source CSV file.
--
-- 'headerList', 'csvFormatDescriptor_headerList' - A list of the source CSV file\'s headers, if any.
--
-- 'quoteSymbol', 'csvFormatDescriptor_quoteSymbol' - The character used as a quote character.
newCsvFormatDescriptor ::
  CsvFormatDescriptor
newCsvFormatDescriptor :: CsvFormatDescriptor
newCsvFormatDescriptor =
  CsvFormatDescriptor'
    { $sel:charset:CsvFormatDescriptor' :: Maybe Text
charset = forall a. Maybe a
Prelude.Nothing,
      $sel:containsHeader:CsvFormatDescriptor' :: Maybe Bool
containsHeader = forall a. Maybe a
Prelude.Nothing,
      $sel:delimiter:CsvFormatDescriptor' :: Maybe Text
delimiter = forall a. Maybe a
Prelude.Nothing,
      $sel:fileCompression:CsvFormatDescriptor' :: Maybe CSVFileCompression
fileCompression = forall a. Maybe a
Prelude.Nothing,
      $sel:headerList:CsvFormatDescriptor' :: Maybe [Text]
headerList = forall a. Maybe a
Prelude.Nothing,
      $sel:quoteSymbol:CsvFormatDescriptor' :: Maybe Text
quoteSymbol = forall a. Maybe a
Prelude.Nothing
    }

-- | The character set in which the source CSV file is written.
csvFormatDescriptor_charset :: Lens.Lens' CsvFormatDescriptor (Prelude.Maybe Prelude.Text)
csvFormatDescriptor_charset :: Lens' CsvFormatDescriptor (Maybe Text)
csvFormatDescriptor_charset = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CsvFormatDescriptor' {Maybe Text
charset :: Maybe Text
$sel:charset:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe Text
charset} -> Maybe Text
charset) (\s :: CsvFormatDescriptor
s@CsvFormatDescriptor' {} Maybe Text
a -> CsvFormatDescriptor
s {$sel:charset:CsvFormatDescriptor' :: Maybe Text
charset = Maybe Text
a} :: CsvFormatDescriptor)

-- | Whether or not the source CSV file contains a header.
csvFormatDescriptor_containsHeader :: Lens.Lens' CsvFormatDescriptor (Prelude.Maybe Prelude.Bool)
csvFormatDescriptor_containsHeader :: Lens' CsvFormatDescriptor (Maybe Bool)
csvFormatDescriptor_containsHeader = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CsvFormatDescriptor' {Maybe Bool
containsHeader :: Maybe Bool
$sel:containsHeader:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe Bool
containsHeader} -> Maybe Bool
containsHeader) (\s :: CsvFormatDescriptor
s@CsvFormatDescriptor' {} Maybe Bool
a -> CsvFormatDescriptor
s {$sel:containsHeader:CsvFormatDescriptor' :: Maybe Bool
containsHeader = Maybe Bool
a} :: CsvFormatDescriptor)

-- | The character used to delimit the source CSV file.
csvFormatDescriptor_delimiter :: Lens.Lens' CsvFormatDescriptor (Prelude.Maybe Prelude.Text)
csvFormatDescriptor_delimiter :: Lens' CsvFormatDescriptor (Maybe Text)
csvFormatDescriptor_delimiter = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CsvFormatDescriptor' {Maybe Text
delimiter :: Maybe Text
$sel:delimiter:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe Text
delimiter} -> Maybe Text
delimiter) (\s :: CsvFormatDescriptor
s@CsvFormatDescriptor' {} Maybe Text
a -> CsvFormatDescriptor
s {$sel:delimiter:CsvFormatDescriptor' :: Maybe Text
delimiter = Maybe Text
a} :: CsvFormatDescriptor)

-- | The level of compression of the source CSV file.
csvFormatDescriptor_fileCompression :: Lens.Lens' CsvFormatDescriptor (Prelude.Maybe CSVFileCompression)
csvFormatDescriptor_fileCompression :: Lens' CsvFormatDescriptor (Maybe CSVFileCompression)
csvFormatDescriptor_fileCompression = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CsvFormatDescriptor' {Maybe CSVFileCompression
fileCompression :: Maybe CSVFileCompression
$sel:fileCompression:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe CSVFileCompression
fileCompression} -> Maybe CSVFileCompression
fileCompression) (\s :: CsvFormatDescriptor
s@CsvFormatDescriptor' {} Maybe CSVFileCompression
a -> CsvFormatDescriptor
s {$sel:fileCompression:CsvFormatDescriptor' :: Maybe CSVFileCompression
fileCompression = Maybe CSVFileCompression
a} :: CsvFormatDescriptor)

-- | A list of the source CSV file\'s headers, if any.
csvFormatDescriptor_headerList :: Lens.Lens' CsvFormatDescriptor (Prelude.Maybe [Prelude.Text])
csvFormatDescriptor_headerList :: Lens' CsvFormatDescriptor (Maybe [Text])
csvFormatDescriptor_headerList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CsvFormatDescriptor' {Maybe [Text]
headerList :: Maybe [Text]
$sel:headerList:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe [Text]
headerList} -> Maybe [Text]
headerList) (\s :: CsvFormatDescriptor
s@CsvFormatDescriptor' {} Maybe [Text]
a -> CsvFormatDescriptor
s {$sel:headerList:CsvFormatDescriptor' :: Maybe [Text]
headerList = Maybe [Text]
a} :: CsvFormatDescriptor) 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

-- | The character used as a quote character.
csvFormatDescriptor_quoteSymbol :: Lens.Lens' CsvFormatDescriptor (Prelude.Maybe Prelude.Text)
csvFormatDescriptor_quoteSymbol :: Lens' CsvFormatDescriptor (Maybe Text)
csvFormatDescriptor_quoteSymbol = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CsvFormatDescriptor' {Maybe Text
quoteSymbol :: Maybe Text
$sel:quoteSymbol:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe Text
quoteSymbol} -> Maybe Text
quoteSymbol) (\s :: CsvFormatDescriptor
s@CsvFormatDescriptor' {} Maybe Text
a -> CsvFormatDescriptor
s {$sel:quoteSymbol:CsvFormatDescriptor' :: Maybe Text
quoteSymbol = Maybe Text
a} :: CsvFormatDescriptor)

instance Data.FromJSON CsvFormatDescriptor where
  parseJSON :: Value -> Parser CsvFormatDescriptor
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CsvFormatDescriptor"
      ( \Object
x ->
          Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe CSVFileCompression
-> Maybe [Text]
-> Maybe Text
-> CsvFormatDescriptor
CsvFormatDescriptor'
            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
"Charset")
            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
"ContainsHeader")
            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
"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
"FileCompression")
            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" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"QuoteSymbol")
      )

instance Prelude.Hashable CsvFormatDescriptor where
  hashWithSalt :: Int -> CsvFormatDescriptor -> Int
hashWithSalt Int
_salt CsvFormatDescriptor' {Maybe Bool
Maybe [Text]
Maybe Text
Maybe CSVFileCompression
quoteSymbol :: Maybe Text
headerList :: Maybe [Text]
fileCompression :: Maybe CSVFileCompression
delimiter :: Maybe Text
containsHeader :: Maybe Bool
charset :: Maybe Text
$sel:quoteSymbol:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe Text
$sel:headerList:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe [Text]
$sel:fileCompression:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe CSVFileCompression
$sel:delimiter:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe Text
$sel:containsHeader:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe Bool
$sel:charset:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
charset
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
containsHeader
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
delimiter
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CSVFileCompression
fileCompression
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
headerList
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
quoteSymbol

instance Prelude.NFData CsvFormatDescriptor where
  rnf :: CsvFormatDescriptor -> ()
rnf CsvFormatDescriptor' {Maybe Bool
Maybe [Text]
Maybe Text
Maybe CSVFileCompression
quoteSymbol :: Maybe Text
headerList :: Maybe [Text]
fileCompression :: Maybe CSVFileCompression
delimiter :: Maybe Text
containsHeader :: Maybe Bool
charset :: Maybe Text
$sel:quoteSymbol:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe Text
$sel:headerList:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe [Text]
$sel:fileCompression:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe CSVFileCompression
$sel:delimiter:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe Text
$sel:containsHeader:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe Bool
$sel:charset:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
charset
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
containsHeader
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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 CSVFileCompression
fileCompression
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
headerList
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
quoteSymbol

instance Data.ToJSON CsvFormatDescriptor where
  toJSON :: CsvFormatDescriptor -> Value
toJSON CsvFormatDescriptor' {Maybe Bool
Maybe [Text]
Maybe Text
Maybe CSVFileCompression
quoteSymbol :: Maybe Text
headerList :: Maybe [Text]
fileCompression :: Maybe CSVFileCompression
delimiter :: Maybe Text
containsHeader :: Maybe Bool
charset :: Maybe Text
$sel:quoteSymbol:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe Text
$sel:headerList:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe [Text]
$sel:fileCompression:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe CSVFileCompression
$sel:delimiter:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe Text
$sel:containsHeader:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe Bool
$sel:charset:CsvFormatDescriptor' :: CsvFormatDescriptor -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Charset" 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
charset,
            (Key
"ContainsHeader" 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
containsHeader,
            (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
"FileCompression" 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 CSVFileCompression
fileCompression,
            (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 [Text]
headerList,
            (Key
"QuoteSymbol" 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
quoteSymbol
          ]
      )