{-# 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.AppSync.Types.SyncConfig
-- 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.AppSync.Types.SyncConfig where

import Amazonka.AppSync.Types.ConflictDetectionType
import Amazonka.AppSync.Types.ConflictHandlerType
import Amazonka.AppSync.Types.LambdaConflictHandlerConfig
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 Sync configuration for a resolver.
--
-- Specifies which Conflict Detection strategy and Resolution strategy to
-- use when the resolver is invoked.
--
-- /See:/ 'newSyncConfig' smart constructor.
data SyncConfig = SyncConfig'
  { -- | The Conflict Detection strategy to use.
    --
    -- -   __VERSION__: Detect conflicts based on object versions for this
    --     resolver.
    --
    -- -   __NONE__: Do not detect conflicts when invoking this resolver.
    SyncConfig -> Maybe ConflictDetectionType
conflictDetection :: Prelude.Maybe ConflictDetectionType,
    -- | The Conflict Resolution strategy to perform in the event of a conflict.
    --
    -- -   __OPTIMISTIC_CONCURRENCY__: Resolve conflicts by rejecting mutations
    --     when versions don\'t match the latest version at the server.
    --
    -- -   __AUTOMERGE__: Resolve conflicts with the Automerge conflict
    --     resolution strategy.
    --
    -- -   __LAMBDA__: Resolve conflicts with an Lambda function supplied in
    --     the @LambdaConflictHandlerConfig@.
    SyncConfig -> Maybe ConflictHandlerType
conflictHandler :: Prelude.Maybe ConflictHandlerType,
    -- | The @LambdaConflictHandlerConfig@ when configuring @LAMBDA@ as the
    -- Conflict Handler.
    SyncConfig -> Maybe LambdaConflictHandlerConfig
lambdaConflictHandlerConfig :: Prelude.Maybe LambdaConflictHandlerConfig
  }
  deriving (SyncConfig -> SyncConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SyncConfig -> SyncConfig -> Bool
$c/= :: SyncConfig -> SyncConfig -> Bool
== :: SyncConfig -> SyncConfig -> Bool
$c== :: SyncConfig -> SyncConfig -> Bool
Prelude.Eq, ReadPrec [SyncConfig]
ReadPrec SyncConfig
Int -> ReadS SyncConfig
ReadS [SyncConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SyncConfig]
$creadListPrec :: ReadPrec [SyncConfig]
readPrec :: ReadPrec SyncConfig
$creadPrec :: ReadPrec SyncConfig
readList :: ReadS [SyncConfig]
$creadList :: ReadS [SyncConfig]
readsPrec :: Int -> ReadS SyncConfig
$creadsPrec :: Int -> ReadS SyncConfig
Prelude.Read, Int -> SyncConfig -> ShowS
[SyncConfig] -> ShowS
SyncConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SyncConfig] -> ShowS
$cshowList :: [SyncConfig] -> ShowS
show :: SyncConfig -> String
$cshow :: SyncConfig -> String
showsPrec :: Int -> SyncConfig -> ShowS
$cshowsPrec :: Int -> SyncConfig -> ShowS
Prelude.Show, forall x. Rep SyncConfig x -> SyncConfig
forall x. SyncConfig -> Rep SyncConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SyncConfig x -> SyncConfig
$cfrom :: forall x. SyncConfig -> Rep SyncConfig x
Prelude.Generic)

-- |
-- Create a value of 'SyncConfig' 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:
--
-- 'conflictDetection', 'syncConfig_conflictDetection' - The Conflict Detection strategy to use.
--
-- -   __VERSION__: Detect conflicts based on object versions for this
--     resolver.
--
-- -   __NONE__: Do not detect conflicts when invoking this resolver.
--
-- 'conflictHandler', 'syncConfig_conflictHandler' - The Conflict Resolution strategy to perform in the event of a conflict.
--
-- -   __OPTIMISTIC_CONCURRENCY__: Resolve conflicts by rejecting mutations
--     when versions don\'t match the latest version at the server.
--
-- -   __AUTOMERGE__: Resolve conflicts with the Automerge conflict
--     resolution strategy.
--
-- -   __LAMBDA__: Resolve conflicts with an Lambda function supplied in
--     the @LambdaConflictHandlerConfig@.
--
-- 'lambdaConflictHandlerConfig', 'syncConfig_lambdaConflictHandlerConfig' - The @LambdaConflictHandlerConfig@ when configuring @LAMBDA@ as the
-- Conflict Handler.
newSyncConfig ::
  SyncConfig
newSyncConfig :: SyncConfig
newSyncConfig =
  SyncConfig'
    { $sel:conflictDetection:SyncConfig' :: Maybe ConflictDetectionType
conflictDetection = forall a. Maybe a
Prelude.Nothing,
      $sel:conflictHandler:SyncConfig' :: Maybe ConflictHandlerType
conflictHandler = forall a. Maybe a
Prelude.Nothing,
      $sel:lambdaConflictHandlerConfig:SyncConfig' :: Maybe LambdaConflictHandlerConfig
lambdaConflictHandlerConfig = forall a. Maybe a
Prelude.Nothing
    }

-- | The Conflict Detection strategy to use.
--
-- -   __VERSION__: Detect conflicts based on object versions for this
--     resolver.
--
-- -   __NONE__: Do not detect conflicts when invoking this resolver.
syncConfig_conflictDetection :: Lens.Lens' SyncConfig (Prelude.Maybe ConflictDetectionType)
syncConfig_conflictDetection :: Lens' SyncConfig (Maybe ConflictDetectionType)
syncConfig_conflictDetection = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SyncConfig' {Maybe ConflictDetectionType
conflictDetection :: Maybe ConflictDetectionType
$sel:conflictDetection:SyncConfig' :: SyncConfig -> Maybe ConflictDetectionType
conflictDetection} -> Maybe ConflictDetectionType
conflictDetection) (\s :: SyncConfig
s@SyncConfig' {} Maybe ConflictDetectionType
a -> SyncConfig
s {$sel:conflictDetection:SyncConfig' :: Maybe ConflictDetectionType
conflictDetection = Maybe ConflictDetectionType
a} :: SyncConfig)

-- | The Conflict Resolution strategy to perform in the event of a conflict.
--
-- -   __OPTIMISTIC_CONCURRENCY__: Resolve conflicts by rejecting mutations
--     when versions don\'t match the latest version at the server.
--
-- -   __AUTOMERGE__: Resolve conflicts with the Automerge conflict
--     resolution strategy.
--
-- -   __LAMBDA__: Resolve conflicts with an Lambda function supplied in
--     the @LambdaConflictHandlerConfig@.
syncConfig_conflictHandler :: Lens.Lens' SyncConfig (Prelude.Maybe ConflictHandlerType)
syncConfig_conflictHandler :: Lens' SyncConfig (Maybe ConflictHandlerType)
syncConfig_conflictHandler = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SyncConfig' {Maybe ConflictHandlerType
conflictHandler :: Maybe ConflictHandlerType
$sel:conflictHandler:SyncConfig' :: SyncConfig -> Maybe ConflictHandlerType
conflictHandler} -> Maybe ConflictHandlerType
conflictHandler) (\s :: SyncConfig
s@SyncConfig' {} Maybe ConflictHandlerType
a -> SyncConfig
s {$sel:conflictHandler:SyncConfig' :: Maybe ConflictHandlerType
conflictHandler = Maybe ConflictHandlerType
a} :: SyncConfig)

-- | The @LambdaConflictHandlerConfig@ when configuring @LAMBDA@ as the
-- Conflict Handler.
syncConfig_lambdaConflictHandlerConfig :: Lens.Lens' SyncConfig (Prelude.Maybe LambdaConflictHandlerConfig)
syncConfig_lambdaConflictHandlerConfig :: Lens' SyncConfig (Maybe LambdaConflictHandlerConfig)
syncConfig_lambdaConflictHandlerConfig = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SyncConfig' {Maybe LambdaConflictHandlerConfig
lambdaConflictHandlerConfig :: Maybe LambdaConflictHandlerConfig
$sel:lambdaConflictHandlerConfig:SyncConfig' :: SyncConfig -> Maybe LambdaConflictHandlerConfig
lambdaConflictHandlerConfig} -> Maybe LambdaConflictHandlerConfig
lambdaConflictHandlerConfig) (\s :: SyncConfig
s@SyncConfig' {} Maybe LambdaConflictHandlerConfig
a -> SyncConfig
s {$sel:lambdaConflictHandlerConfig:SyncConfig' :: Maybe LambdaConflictHandlerConfig
lambdaConflictHandlerConfig = Maybe LambdaConflictHandlerConfig
a} :: SyncConfig)

instance Data.FromJSON SyncConfig where
  parseJSON :: Value -> Parser SyncConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"SyncConfig"
      ( \Object
x ->
          Maybe ConflictDetectionType
-> Maybe ConflictHandlerType
-> Maybe LambdaConflictHandlerConfig
-> SyncConfig
SyncConfig'
            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
"conflictDetection")
            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
"conflictHandler")
            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
"lambdaConflictHandlerConfig")
      )

instance Prelude.Hashable SyncConfig where
  hashWithSalt :: Int -> SyncConfig -> Int
hashWithSalt Int
_salt SyncConfig' {Maybe ConflictDetectionType
Maybe ConflictHandlerType
Maybe LambdaConflictHandlerConfig
lambdaConflictHandlerConfig :: Maybe LambdaConflictHandlerConfig
conflictHandler :: Maybe ConflictHandlerType
conflictDetection :: Maybe ConflictDetectionType
$sel:lambdaConflictHandlerConfig:SyncConfig' :: SyncConfig -> Maybe LambdaConflictHandlerConfig
$sel:conflictHandler:SyncConfig' :: SyncConfig -> Maybe ConflictHandlerType
$sel:conflictDetection:SyncConfig' :: SyncConfig -> Maybe ConflictDetectionType
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ConflictDetectionType
conflictDetection
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ConflictHandlerType
conflictHandler
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe LambdaConflictHandlerConfig
lambdaConflictHandlerConfig

instance Prelude.NFData SyncConfig where
  rnf :: SyncConfig -> ()
rnf SyncConfig' {Maybe ConflictDetectionType
Maybe ConflictHandlerType
Maybe LambdaConflictHandlerConfig
lambdaConflictHandlerConfig :: Maybe LambdaConflictHandlerConfig
conflictHandler :: Maybe ConflictHandlerType
conflictDetection :: Maybe ConflictDetectionType
$sel:lambdaConflictHandlerConfig:SyncConfig' :: SyncConfig -> Maybe LambdaConflictHandlerConfig
$sel:conflictHandler:SyncConfig' :: SyncConfig -> Maybe ConflictHandlerType
$sel:conflictDetection:SyncConfig' :: SyncConfig -> Maybe ConflictDetectionType
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ConflictDetectionType
conflictDetection
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ConflictHandlerType
conflictHandler
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe LambdaConflictHandlerConfig
lambdaConflictHandlerConfig

instance Data.ToJSON SyncConfig where
  toJSON :: SyncConfig -> Value
toJSON SyncConfig' {Maybe ConflictDetectionType
Maybe ConflictHandlerType
Maybe LambdaConflictHandlerConfig
lambdaConflictHandlerConfig :: Maybe LambdaConflictHandlerConfig
conflictHandler :: Maybe ConflictHandlerType
conflictDetection :: Maybe ConflictDetectionType
$sel:lambdaConflictHandlerConfig:SyncConfig' :: SyncConfig -> Maybe LambdaConflictHandlerConfig
$sel:conflictHandler:SyncConfig' :: SyncConfig -> Maybe ConflictHandlerType
$sel:conflictDetection:SyncConfig' :: SyncConfig -> Maybe ConflictDetectionType
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"conflictDetection" 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 ConflictDetectionType
conflictDetection,
            (Key
"conflictHandler" 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 ConflictHandlerType
conflictHandler,
            (Key
"lambdaConflictHandlerConfig" 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 LambdaConflictHandlerConfig
lambdaConflictHandlerConfig
          ]
      )