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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(CopyCommand -> CopyCommand -> Bool)
-> (CopyCommand -> CopyCommand -> Bool) -> Eq CopyCommand
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]
(Int -> ReadS CopyCommand)
-> ReadS [CopyCommand]
-> ReadPrec CopyCommand
-> ReadPrec [CopyCommand]
-> Read 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
(Int -> CopyCommand -> ShowS)
-> (CopyCommand -> String)
-> ([CopyCommand] -> ShowS)
-> Show CopyCommand
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. CopyCommand -> Rep CopyCommand x)
-> (forall x. Rep CopyCommand x -> CopyCommand)
-> Generic CopyCommand
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' :: Maybe Text -> Maybe Text -> Text -> CopyCommand
CopyCommand'
    { $sel:copyOptions:CopyCommand' :: Maybe Text
copyOptions = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:dataTableColumns:CopyCommand' :: Maybe Text
dataTableColumns = Maybe Text
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 :: (Maybe Text -> f (Maybe Text)) -> CopyCommand -> f CopyCommand
copyCommand_copyOptions = (CopyCommand -> Maybe Text)
-> (CopyCommand -> Maybe Text -> CopyCommand)
-> Lens CopyCommand CopyCommand (Maybe Text) (Maybe Text)
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 :: (Maybe Text -> f (Maybe Text)) -> CopyCommand -> f CopyCommand
copyCommand_dataTableColumns = (CopyCommand -> Maybe Text)
-> (CopyCommand -> Maybe Text -> CopyCommand)
-> Lens CopyCommand CopyCommand (Maybe Text) (Maybe Text)
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 :: (Text -> f Text) -> CopyCommand -> f CopyCommand
copyCommand_dataTableName = (CopyCommand -> Text)
-> (CopyCommand -> Text -> CopyCommand)
-> Lens CopyCommand CopyCommand Text Text
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 Core.FromJSON CopyCommand where
  parseJSON :: Value -> Parser CopyCommand
parseJSON =
    String
-> (Object -> Parser CopyCommand) -> Value -> Parser CopyCommand
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CopyCommand"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Text -> CopyCommand
CopyCommand'
            (Maybe Text -> Maybe Text -> Text -> CopyCommand)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Text -> CopyCommand)
forall (f :: * -> *) a b. Functor 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
"CopyOptions")
            Parser (Maybe Text -> Text -> CopyCommand)
-> Parser (Maybe Text) -> Parser (Text -> CopyCommand)
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
"DataTableColumns")
            Parser (Text -> CopyCommand) -> Parser Text -> Parser CopyCommand
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"DataTableName")
      )

instance Prelude.Hashable CopyCommand

instance Prelude.NFData CopyCommand

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"CopyOptions" 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
copyOptions,
            (Text
"DataTableColumns" 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
dataTableColumns,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"DataTableName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
dataTableName)
          ]
      )