{-# 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.AppFlow.Types.SalesforceDestinationProperties
-- 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.AppFlow.Types.SalesforceDestinationProperties where

import Amazonka.AppFlow.Types.ErrorHandlingConfig
import Amazonka.AppFlow.Types.WriteOperationType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The properties that are applied when Salesforce is being used as a
-- destination.
--
-- /See:/ 'newSalesforceDestinationProperties' smart constructor.
data SalesforceDestinationProperties = SalesforceDestinationProperties'
  { -- | This specifies the type of write operation to be performed in
    -- Salesforce. When the value is @UPSERT@, then @idFieldNames@ is required.
    SalesforceDestinationProperties -> Maybe WriteOperationType
writeOperationType :: Prelude.Maybe WriteOperationType,
    -- | The name of the field that Amazon AppFlow uses as an ID when performing
    -- a write operation such as update or delete.
    SalesforceDestinationProperties -> Maybe [Text]
idFieldNames :: Prelude.Maybe [Prelude.Text],
    -- | The settings that determine how Amazon AppFlow handles an error when
    -- placing data in the Salesforce destination. For example, this setting
    -- would determine if the flow should fail after one insertion error, or
    -- continue and attempt to insert every record regardless of the initial
    -- failure. @ErrorHandlingConfig@ is a part of the destination connector
    -- details.
    SalesforceDestinationProperties -> Maybe ErrorHandlingConfig
errorHandlingConfig :: Prelude.Maybe ErrorHandlingConfig,
    -- | The object specified in the Salesforce flow destination.
    SalesforceDestinationProperties -> Text
object' :: Prelude.Text
  }
  deriving (SalesforceDestinationProperties
-> SalesforceDestinationProperties -> Bool
(SalesforceDestinationProperties
 -> SalesforceDestinationProperties -> Bool)
-> (SalesforceDestinationProperties
    -> SalesforceDestinationProperties -> Bool)
-> Eq SalesforceDestinationProperties
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SalesforceDestinationProperties
-> SalesforceDestinationProperties -> Bool
$c/= :: SalesforceDestinationProperties
-> SalesforceDestinationProperties -> Bool
== :: SalesforceDestinationProperties
-> SalesforceDestinationProperties -> Bool
$c== :: SalesforceDestinationProperties
-> SalesforceDestinationProperties -> Bool
Prelude.Eq, ReadPrec [SalesforceDestinationProperties]
ReadPrec SalesforceDestinationProperties
Int -> ReadS SalesforceDestinationProperties
ReadS [SalesforceDestinationProperties]
(Int -> ReadS SalesforceDestinationProperties)
-> ReadS [SalesforceDestinationProperties]
-> ReadPrec SalesforceDestinationProperties
-> ReadPrec [SalesforceDestinationProperties]
-> Read SalesforceDestinationProperties
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SalesforceDestinationProperties]
$creadListPrec :: ReadPrec [SalesforceDestinationProperties]
readPrec :: ReadPrec SalesforceDestinationProperties
$creadPrec :: ReadPrec SalesforceDestinationProperties
readList :: ReadS [SalesforceDestinationProperties]
$creadList :: ReadS [SalesforceDestinationProperties]
readsPrec :: Int -> ReadS SalesforceDestinationProperties
$creadsPrec :: Int -> ReadS SalesforceDestinationProperties
Prelude.Read, Int -> SalesforceDestinationProperties -> ShowS
[SalesforceDestinationProperties] -> ShowS
SalesforceDestinationProperties -> String
(Int -> SalesforceDestinationProperties -> ShowS)
-> (SalesforceDestinationProperties -> String)
-> ([SalesforceDestinationProperties] -> ShowS)
-> Show SalesforceDestinationProperties
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SalesforceDestinationProperties] -> ShowS
$cshowList :: [SalesforceDestinationProperties] -> ShowS
show :: SalesforceDestinationProperties -> String
$cshow :: SalesforceDestinationProperties -> String
showsPrec :: Int -> SalesforceDestinationProperties -> ShowS
$cshowsPrec :: Int -> SalesforceDestinationProperties -> ShowS
Prelude.Show, (forall x.
 SalesforceDestinationProperties
 -> Rep SalesforceDestinationProperties x)
-> (forall x.
    Rep SalesforceDestinationProperties x
    -> SalesforceDestinationProperties)
-> Generic SalesforceDestinationProperties
forall x.
Rep SalesforceDestinationProperties x
-> SalesforceDestinationProperties
forall x.
SalesforceDestinationProperties
-> Rep SalesforceDestinationProperties x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep SalesforceDestinationProperties x
-> SalesforceDestinationProperties
$cfrom :: forall x.
SalesforceDestinationProperties
-> Rep SalesforceDestinationProperties x
Prelude.Generic)

-- |
-- Create a value of 'SalesforceDestinationProperties' 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:
--
-- 'writeOperationType', 'salesforceDestinationProperties_writeOperationType' - This specifies the type of write operation to be performed in
-- Salesforce. When the value is @UPSERT@, then @idFieldNames@ is required.
--
-- 'idFieldNames', 'salesforceDestinationProperties_idFieldNames' - The name of the field that Amazon AppFlow uses as an ID when performing
-- a write operation such as update or delete.
--
-- 'errorHandlingConfig', 'salesforceDestinationProperties_errorHandlingConfig' - The settings that determine how Amazon AppFlow handles an error when
-- placing data in the Salesforce destination. For example, this setting
-- would determine if the flow should fail after one insertion error, or
-- continue and attempt to insert every record regardless of the initial
-- failure. @ErrorHandlingConfig@ is a part of the destination connector
-- details.
--
-- 'object'', 'salesforceDestinationProperties_object' - The object specified in the Salesforce flow destination.
newSalesforceDestinationProperties ::
  -- | 'object''
  Prelude.Text ->
  SalesforceDestinationProperties
newSalesforceDestinationProperties :: Text -> SalesforceDestinationProperties
newSalesforceDestinationProperties Text
pObject_ =
  SalesforceDestinationProperties' :: Maybe WriteOperationType
-> Maybe [Text]
-> Maybe ErrorHandlingConfig
-> Text
-> SalesforceDestinationProperties
SalesforceDestinationProperties'
    { $sel:writeOperationType:SalesforceDestinationProperties' :: Maybe WriteOperationType
writeOperationType =
        Maybe WriteOperationType
forall a. Maybe a
Prelude.Nothing,
      $sel:idFieldNames:SalesforceDestinationProperties' :: Maybe [Text]
idFieldNames = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:errorHandlingConfig:SalesforceDestinationProperties' :: Maybe ErrorHandlingConfig
errorHandlingConfig = Maybe ErrorHandlingConfig
forall a. Maybe a
Prelude.Nothing,
      $sel:object':SalesforceDestinationProperties' :: Text
object' = Text
pObject_
    }

-- | This specifies the type of write operation to be performed in
-- Salesforce. When the value is @UPSERT@, then @idFieldNames@ is required.
salesforceDestinationProperties_writeOperationType :: Lens.Lens' SalesforceDestinationProperties (Prelude.Maybe WriteOperationType)
salesforceDestinationProperties_writeOperationType :: (Maybe WriteOperationType -> f (Maybe WriteOperationType))
-> SalesforceDestinationProperties
-> f SalesforceDestinationProperties
salesforceDestinationProperties_writeOperationType = (SalesforceDestinationProperties -> Maybe WriteOperationType)
-> (SalesforceDestinationProperties
    -> Maybe WriteOperationType -> SalesforceDestinationProperties)
-> Lens
     SalesforceDestinationProperties
     SalesforceDestinationProperties
     (Maybe WriteOperationType)
     (Maybe WriteOperationType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SalesforceDestinationProperties' {Maybe WriteOperationType
writeOperationType :: Maybe WriteOperationType
$sel:writeOperationType:SalesforceDestinationProperties' :: SalesforceDestinationProperties -> Maybe WriteOperationType
writeOperationType} -> Maybe WriteOperationType
writeOperationType) (\s :: SalesforceDestinationProperties
s@SalesforceDestinationProperties' {} Maybe WriteOperationType
a -> SalesforceDestinationProperties
s {$sel:writeOperationType:SalesforceDestinationProperties' :: Maybe WriteOperationType
writeOperationType = Maybe WriteOperationType
a} :: SalesforceDestinationProperties)

-- | The name of the field that Amazon AppFlow uses as an ID when performing
-- a write operation such as update or delete.
salesforceDestinationProperties_idFieldNames :: Lens.Lens' SalesforceDestinationProperties (Prelude.Maybe [Prelude.Text])
salesforceDestinationProperties_idFieldNames :: (Maybe [Text] -> f (Maybe [Text]))
-> SalesforceDestinationProperties
-> f SalesforceDestinationProperties
salesforceDestinationProperties_idFieldNames = (SalesforceDestinationProperties -> Maybe [Text])
-> (SalesforceDestinationProperties
    -> Maybe [Text] -> SalesforceDestinationProperties)
-> Lens
     SalesforceDestinationProperties
     SalesforceDestinationProperties
     (Maybe [Text])
     (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SalesforceDestinationProperties' {Maybe [Text]
idFieldNames :: Maybe [Text]
$sel:idFieldNames:SalesforceDestinationProperties' :: SalesforceDestinationProperties -> Maybe [Text]
idFieldNames} -> Maybe [Text]
idFieldNames) (\s :: SalesforceDestinationProperties
s@SalesforceDestinationProperties' {} Maybe [Text]
a -> SalesforceDestinationProperties
s {$sel:idFieldNames:SalesforceDestinationProperties' :: Maybe [Text]
idFieldNames = Maybe [Text]
a} :: SalesforceDestinationProperties) ((Maybe [Text] -> f (Maybe [Text]))
 -> SalesforceDestinationProperties
 -> f SalesforceDestinationProperties)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> SalesforceDestinationProperties
-> f SalesforceDestinationProperties
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
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 AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The settings that determine how Amazon AppFlow handles an error when
-- placing data in the Salesforce destination. For example, this setting
-- would determine if the flow should fail after one insertion error, or
-- continue and attempt to insert every record regardless of the initial
-- failure. @ErrorHandlingConfig@ is a part of the destination connector
-- details.
salesforceDestinationProperties_errorHandlingConfig :: Lens.Lens' SalesforceDestinationProperties (Prelude.Maybe ErrorHandlingConfig)
salesforceDestinationProperties_errorHandlingConfig :: (Maybe ErrorHandlingConfig -> f (Maybe ErrorHandlingConfig))
-> SalesforceDestinationProperties
-> f SalesforceDestinationProperties
salesforceDestinationProperties_errorHandlingConfig = (SalesforceDestinationProperties -> Maybe ErrorHandlingConfig)
-> (SalesforceDestinationProperties
    -> Maybe ErrorHandlingConfig -> SalesforceDestinationProperties)
-> Lens
     SalesforceDestinationProperties
     SalesforceDestinationProperties
     (Maybe ErrorHandlingConfig)
     (Maybe ErrorHandlingConfig)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SalesforceDestinationProperties' {Maybe ErrorHandlingConfig
errorHandlingConfig :: Maybe ErrorHandlingConfig
$sel:errorHandlingConfig:SalesforceDestinationProperties' :: SalesforceDestinationProperties -> Maybe ErrorHandlingConfig
errorHandlingConfig} -> Maybe ErrorHandlingConfig
errorHandlingConfig) (\s :: SalesforceDestinationProperties
s@SalesforceDestinationProperties' {} Maybe ErrorHandlingConfig
a -> SalesforceDestinationProperties
s {$sel:errorHandlingConfig:SalesforceDestinationProperties' :: Maybe ErrorHandlingConfig
errorHandlingConfig = Maybe ErrorHandlingConfig
a} :: SalesforceDestinationProperties)

-- | The object specified in the Salesforce flow destination.
salesforceDestinationProperties_object :: Lens.Lens' SalesforceDestinationProperties Prelude.Text
salesforceDestinationProperties_object :: (Text -> f Text)
-> SalesforceDestinationProperties
-> f SalesforceDestinationProperties
salesforceDestinationProperties_object = (SalesforceDestinationProperties -> Text)
-> (SalesforceDestinationProperties
    -> Text -> SalesforceDestinationProperties)
-> Lens
     SalesforceDestinationProperties
     SalesforceDestinationProperties
     Text
     Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SalesforceDestinationProperties' {Text
object' :: Text
$sel:object':SalesforceDestinationProperties' :: SalesforceDestinationProperties -> Text
object'} -> Text
object') (\s :: SalesforceDestinationProperties
s@SalesforceDestinationProperties' {} Text
a -> SalesforceDestinationProperties
s {$sel:object':SalesforceDestinationProperties' :: Text
object' = Text
a} :: SalesforceDestinationProperties)

instance
  Core.FromJSON
    SalesforceDestinationProperties
  where
  parseJSON :: Value -> Parser SalesforceDestinationProperties
parseJSON =
    String
-> (Object -> Parser SalesforceDestinationProperties)
-> Value
-> Parser SalesforceDestinationProperties
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SalesforceDestinationProperties"
      ( \Object
x ->
          Maybe WriteOperationType
-> Maybe [Text]
-> Maybe ErrorHandlingConfig
-> Text
-> SalesforceDestinationProperties
SalesforceDestinationProperties'
            (Maybe WriteOperationType
 -> Maybe [Text]
 -> Maybe ErrorHandlingConfig
 -> Text
 -> SalesforceDestinationProperties)
-> Parser (Maybe WriteOperationType)
-> Parser
     (Maybe [Text]
      -> Maybe ErrorHandlingConfig
      -> Text
      -> SalesforceDestinationProperties)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe WriteOperationType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"writeOperationType")
            Parser
  (Maybe [Text]
   -> Maybe ErrorHandlingConfig
   -> Text
   -> SalesforceDestinationProperties)
-> Parser (Maybe [Text])
-> Parser
     (Maybe ErrorHandlingConfig
      -> Text -> SalesforceDestinationProperties)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"idFieldNames" Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe ErrorHandlingConfig
   -> Text -> SalesforceDestinationProperties)
-> Parser (Maybe ErrorHandlingConfig)
-> Parser (Text -> SalesforceDestinationProperties)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ErrorHandlingConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"errorHandlingConfig")
            Parser (Text -> SalesforceDestinationProperties)
-> Parser Text -> Parser SalesforceDestinationProperties
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
"object")
      )

instance
  Prelude.Hashable
    SalesforceDestinationProperties

instance
  Prelude.NFData
    SalesforceDestinationProperties

instance Core.ToJSON SalesforceDestinationProperties where
  toJSON :: SalesforceDestinationProperties -> Value
toJSON SalesforceDestinationProperties' {Maybe [Text]
Maybe ErrorHandlingConfig
Maybe WriteOperationType
Text
object' :: Text
errorHandlingConfig :: Maybe ErrorHandlingConfig
idFieldNames :: Maybe [Text]
writeOperationType :: Maybe WriteOperationType
$sel:object':SalesforceDestinationProperties' :: SalesforceDestinationProperties -> Text
$sel:errorHandlingConfig:SalesforceDestinationProperties' :: SalesforceDestinationProperties -> Maybe ErrorHandlingConfig
$sel:idFieldNames:SalesforceDestinationProperties' :: SalesforceDestinationProperties -> Maybe [Text]
$sel:writeOperationType:SalesforceDestinationProperties' :: SalesforceDestinationProperties -> Maybe WriteOperationType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"writeOperationType" Text -> WriteOperationType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (WriteOperationType -> Pair)
-> Maybe WriteOperationType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe WriteOperationType
writeOperationType,
            (Text
"idFieldNames" 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]
idFieldNames,
            (Text
"errorHandlingConfig" Text -> ErrorHandlingConfig -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (ErrorHandlingConfig -> Pair)
-> Maybe ErrorHandlingConfig -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ErrorHandlingConfig
errorHandlingConfig,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"object" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
object')
          ]
      )