{-# 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.Firehose.Types.CopyCommand
-- 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.Firehose.Types.CopyCommand 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

-- | Describes a @COPY@ command for Amazon Redshift.
--
-- /See:/ 'newCopyCommand' smart constructor.
data CopyCommand = CopyCommand'
  { -- | Optional parameters to use with the Amazon Redshift @COPY@ command. For
    -- more information, see the \"Optional Parameters\" section of
    -- <https://docs.aws.amazon.com/redshift/latest/dg/r_COPY.html Amazon Redshift COPY command>.
    -- Some possible examples that would apply to Kinesis Data Firehose are as
    -- follows:
    --
    -- @delimiter \'\\t\' lzop;@ - fields are delimited with \"\\t\" (TAB
    -- character) and compressed using lzop.
    --
    -- @delimiter \'|\'@ - fields are delimited with \"|\" (this is the default
    -- delimiter).
    --
    -- @delimiter \'|\' escape@ - the delimiter should be escaped.
    --
    -- @fixedwidth \'venueid:3,venuename:25,venuecity:12,venuestate:2,venueseats:6\'@
    -- - fields are fixed width in the source, with each width specified after
    -- every column in the table.
    --
    -- @JSON \'s3:\/\/mybucket\/jsonpaths.txt\'@ - data is in JSON format, and
    -- the path specified is the format of the data.
    --
    -- For more examples, see
    -- <https://docs.aws.amazon.com/redshift/latest/dg/r_COPY_command_examples.html Amazon Redshift COPY command examples>.
    CopyCommand -> Maybe Text
copyOptions :: Prelude.Maybe Prelude.Text,
    -- | A comma-separated list of column names.
    CopyCommand -> Maybe Text
dataTableColumns :: Prelude.Maybe Prelude.Text,
    -- | The name of the target table. The table must already exist in the
    -- database.
    CopyCommand -> Text
dataTableName :: Prelude.Text
  }
  deriving (CopyCommand -> CopyCommand -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CopyCommand -> CopyCommand -> Bool
$c/= :: CopyCommand -> CopyCommand -> Bool
== :: CopyCommand -> CopyCommand -> Bool
$c== :: CopyCommand -> CopyCommand -> Bool
Prelude.Eq, ReadPrec [CopyCommand]
ReadPrec CopyCommand
Int -> ReadS CopyCommand
ReadS [CopyCommand]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CopyCommand]
$creadListPrec :: ReadPrec [CopyCommand]
readPrec :: ReadPrec CopyCommand
$creadPrec :: ReadPrec CopyCommand
readList :: ReadS [CopyCommand]
$creadList :: ReadS [CopyCommand]
readsPrec :: Int -> ReadS CopyCommand
$creadsPrec :: Int -> ReadS CopyCommand
Prelude.Read, Int -> CopyCommand -> ShowS
[CopyCommand] -> ShowS
CopyCommand -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CopyCommand] -> ShowS
$cshowList :: [CopyCommand] -> ShowS
show :: CopyCommand -> String
$cshow :: CopyCommand -> String
showsPrec :: Int -> CopyCommand -> ShowS
$cshowsPrec :: Int -> CopyCommand -> ShowS
Prelude.Show, forall x. Rep CopyCommand x -> CopyCommand
forall x. CopyCommand -> Rep CopyCommand x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CopyCommand x -> CopyCommand
$cfrom :: forall x. CopyCommand -> Rep CopyCommand x
Prelude.Generic)

-- |
-- Create a value of 'CopyCommand' 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:
--
-- 'copyOptions', 'copyCommand_copyOptions' - Optional parameters to use with the Amazon Redshift @COPY@ command. For
-- more information, see the \"Optional Parameters\" section of
-- <https://docs.aws.amazon.com/redshift/latest/dg/r_COPY.html Amazon Redshift COPY command>.
-- Some possible examples that would apply to Kinesis Data Firehose are as
-- follows:
--
-- @delimiter \'\\t\' lzop;@ - fields are delimited with \"\\t\" (TAB
-- character) and compressed using lzop.
--
-- @delimiter \'|\'@ - fields are delimited with \"|\" (this is the default
-- delimiter).
--
-- @delimiter \'|\' escape@ - the delimiter should be escaped.
--
-- @fixedwidth \'venueid:3,venuename:25,venuecity:12,venuestate:2,venueseats:6\'@
-- - fields are fixed width in the source, with each width specified after
-- every column in the table.
--
-- @JSON \'s3:\/\/mybucket\/jsonpaths.txt\'@ - data is in JSON format, and
-- the path specified is the format of the data.
--
-- For more examples, see
-- <https://docs.aws.amazon.com/redshift/latest/dg/r_COPY_command_examples.html Amazon Redshift COPY command examples>.
--
-- 'dataTableColumns', 'copyCommand_dataTableColumns' - A comma-separated list of column names.
--
-- 'dataTableName', 'copyCommand_dataTableName' - The name of the target table. The table must already exist in the
-- database.
newCopyCommand ::
  -- | 'dataTableName'
  Prelude.Text ->
  CopyCommand
newCopyCommand :: Text -> CopyCommand
newCopyCommand Text
pDataTableName_ =
  CopyCommand'
    { $sel:copyOptions:CopyCommand' :: Maybe Text
copyOptions = forall a. Maybe a
Prelude.Nothing,
      $sel:dataTableColumns:CopyCommand' :: Maybe Text
dataTableColumns = forall a. Maybe a
Prelude.Nothing,
      $sel:dataTableName:CopyCommand' :: Text
dataTableName = Text
pDataTableName_
    }

-- | Optional parameters to use with the Amazon Redshift @COPY@ command. For
-- more information, see the \"Optional Parameters\" section of
-- <https://docs.aws.amazon.com/redshift/latest/dg/r_COPY.html Amazon Redshift COPY command>.
-- Some possible examples that would apply to Kinesis Data Firehose are as
-- follows:
--
-- @delimiter \'\\t\' lzop;@ - fields are delimited with \"\\t\" (TAB
-- character) and compressed using lzop.
--
-- @delimiter \'|\'@ - fields are delimited with \"|\" (this is the default
-- delimiter).
--
-- @delimiter \'|\' escape@ - the delimiter should be escaped.
--
-- @fixedwidth \'venueid:3,venuename:25,venuecity:12,venuestate:2,venueseats:6\'@
-- - fields are fixed width in the source, with each width specified after
-- every column in the table.
--
-- @JSON \'s3:\/\/mybucket\/jsonpaths.txt\'@ - data is in JSON format, and
-- the path specified is the format of the data.
--
-- For more examples, see
-- <https://docs.aws.amazon.com/redshift/latest/dg/r_COPY_command_examples.html Amazon Redshift COPY command examples>.
copyCommand_copyOptions :: Lens.Lens' CopyCommand (Prelude.Maybe Prelude.Text)
copyCommand_copyOptions :: Lens' CopyCommand (Maybe Text)
copyCommand_copyOptions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CopyCommand' {Maybe Text
copyOptions :: Maybe Text
$sel:copyOptions:CopyCommand' :: CopyCommand -> Maybe Text
copyOptions} -> Maybe Text
copyOptions) (\s :: CopyCommand
s@CopyCommand' {} Maybe Text
a -> CopyCommand
s {$sel:copyOptions:CopyCommand' :: Maybe Text
copyOptions = Maybe Text
a} :: CopyCommand)

-- | A comma-separated list of column names.
copyCommand_dataTableColumns :: Lens.Lens' CopyCommand (Prelude.Maybe Prelude.Text)
copyCommand_dataTableColumns :: Lens' CopyCommand (Maybe Text)
copyCommand_dataTableColumns = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CopyCommand' {Maybe Text
dataTableColumns :: Maybe Text
$sel:dataTableColumns:CopyCommand' :: CopyCommand -> Maybe Text
dataTableColumns} -> Maybe Text
dataTableColumns) (\s :: CopyCommand
s@CopyCommand' {} Maybe Text
a -> CopyCommand
s {$sel:dataTableColumns:CopyCommand' :: Maybe Text
dataTableColumns = Maybe Text
a} :: CopyCommand)

-- | The name of the target table. The table must already exist in the
-- database.
copyCommand_dataTableName :: Lens.Lens' CopyCommand Prelude.Text
copyCommand_dataTableName :: Lens' CopyCommand Text
copyCommand_dataTableName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CopyCommand' {Text
dataTableName :: Text
$sel:dataTableName:CopyCommand' :: CopyCommand -> Text
dataTableName} -> Text
dataTableName) (\s :: CopyCommand
s@CopyCommand' {} Text
a -> CopyCommand
s {$sel:dataTableName:CopyCommand' :: Text
dataTableName = Text
a} :: CopyCommand)

instance Data.FromJSON CopyCommand where
  parseJSON :: Value -> Parser CopyCommand
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CopyCommand"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Text -> CopyCommand
CopyCommand'
            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
"CopyOptions")
            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
"DataTableColumns")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"DataTableName")
      )

instance Prelude.Hashable CopyCommand where
  hashWithSalt :: Int -> CopyCommand -> Int
hashWithSalt Int
_salt CopyCommand' {Maybe Text
Text
dataTableName :: Text
dataTableColumns :: Maybe Text
copyOptions :: Maybe Text
$sel:dataTableName:CopyCommand' :: CopyCommand -> Text
$sel:dataTableColumns:CopyCommand' :: CopyCommand -> Maybe Text
$sel:copyOptions:CopyCommand' :: CopyCommand -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
copyOptions
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
dataTableColumns
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
dataTableName

instance Prelude.NFData CopyCommand where
  rnf :: CopyCommand -> ()
rnf CopyCommand' {Maybe Text
Text
dataTableName :: Text
dataTableColumns :: Maybe Text
copyOptions :: Maybe Text
$sel:dataTableName:CopyCommand' :: CopyCommand -> Text
$sel:dataTableColumns:CopyCommand' :: CopyCommand -> Maybe Text
$sel:copyOptions:CopyCommand' :: CopyCommand -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
copyOptions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
dataTableColumns
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
dataTableName

instance Data.ToJSON CopyCommand where
  toJSON :: CopyCommand -> Value
toJSON CopyCommand' {Maybe Text
Text
dataTableName :: Text
dataTableColumns :: Maybe Text
copyOptions :: Maybe Text
$sel:dataTableName:CopyCommand' :: CopyCommand -> Text
$sel:dataTableColumns:CopyCommand' :: CopyCommand -> Maybe Text
$sel:copyOptions:CopyCommand' :: CopyCommand -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"CopyOptions" 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
copyOptions,
            (Key
"DataTableColumns" 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
dataTableColumns,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"DataTableName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
dataTableName)
          ]
      )