{-# 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-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.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.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes a Sync configuration for a resolver.
--
-- Contains information on which Conflict Detection as well as Resolution
-- strategy should be performed when the resolver is invoked.
--
-- /See:/ 'newSyncConfig' smart constructor.
data SyncConfig = SyncConfig'
  { -- | The Conflict Resolution strategy to perform in the event of a conflict.
    --
    -- -   __OPTIMISTIC_CONCURRENCY__: Resolve conflicts by rejecting mutations
    --     when versions do not match the latest version at the server.
    --
    -- -   __AUTOMERGE__: Resolve conflicts with the Automerge conflict
    --     resolution strategy.
    --
    -- -   __LAMBDA__: Resolve conflicts with a Lambda function supplied in the
    --     LambdaConflictHandlerConfig.
    SyncConfig -> Maybe ConflictHandlerType
conflictHandler :: Prelude.Maybe ConflictHandlerType,
    -- | The Conflict Detection strategy to use.
    --
    -- -   __VERSION__: Detect conflicts based on object versions for this
    --     resolver.
    --
    -- -   __NONE__: Do not detect conflicts when executing this resolver.
    SyncConfig -> Maybe ConflictDetectionType
conflictDetection :: Prelude.Maybe ConflictDetectionType,
    -- | The @LambdaConflictHandlerConfig@ when configuring LAMBDA as the
    -- Conflict Handler.
    SyncConfig -> Maybe LambdaConflictHandlerConfig
lambdaConflictHandlerConfig :: Prelude.Maybe LambdaConflictHandlerConfig
  }
  deriving (SyncConfig -> SyncConfig -> Bool
(SyncConfig -> SyncConfig -> Bool)
-> (SyncConfig -> SyncConfig -> Bool) -> Eq SyncConfig
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]
(Int -> ReadS SyncConfig)
-> ReadS [SyncConfig]
-> ReadPrec SyncConfig
-> ReadPrec [SyncConfig]
-> Read 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
(Int -> SyncConfig -> ShowS)
-> (SyncConfig -> String)
-> ([SyncConfig] -> ShowS)
-> Show SyncConfig
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. SyncConfig -> Rep SyncConfig x)
-> (forall x. Rep SyncConfig x -> SyncConfig) -> Generic SyncConfig
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:
--
-- 'conflictHandler', 'syncConfig_conflictHandler' - The Conflict Resolution strategy to perform in the event of a conflict.
--
-- -   __OPTIMISTIC_CONCURRENCY__: Resolve conflicts by rejecting mutations
--     when versions do not match the latest version at the server.
--
-- -   __AUTOMERGE__: Resolve conflicts with the Automerge conflict
--     resolution strategy.
--
-- -   __LAMBDA__: Resolve conflicts with a Lambda function supplied in the
--     LambdaConflictHandlerConfig.
--
-- '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 executing this resolver.
--
-- 'lambdaConflictHandlerConfig', 'syncConfig_lambdaConflictHandlerConfig' - The @LambdaConflictHandlerConfig@ when configuring LAMBDA as the
-- Conflict Handler.
newSyncConfig ::
  SyncConfig
newSyncConfig :: SyncConfig
newSyncConfig =
  SyncConfig' :: Maybe ConflictHandlerType
-> Maybe ConflictDetectionType
-> Maybe LambdaConflictHandlerConfig
-> SyncConfig
SyncConfig'
    { $sel:conflictHandler:SyncConfig' :: Maybe ConflictHandlerType
conflictHandler = Maybe ConflictHandlerType
forall a. Maybe a
Prelude.Nothing,
      $sel:conflictDetection:SyncConfig' :: Maybe ConflictDetectionType
conflictDetection = Maybe ConflictDetectionType
forall a. Maybe a
Prelude.Nothing,
      $sel:lambdaConflictHandlerConfig:SyncConfig' :: Maybe LambdaConflictHandlerConfig
lambdaConflictHandlerConfig = Maybe LambdaConflictHandlerConfig
forall a. Maybe a
Prelude.Nothing
    }

-- | The Conflict Resolution strategy to perform in the event of a conflict.
--
-- -   __OPTIMISTIC_CONCURRENCY__: Resolve conflicts by rejecting mutations
--     when versions do not match the latest version at the server.
--
-- -   __AUTOMERGE__: Resolve conflicts with the Automerge conflict
--     resolution strategy.
--
-- -   __LAMBDA__: Resolve conflicts with a Lambda function supplied in the
--     LambdaConflictHandlerConfig.
syncConfig_conflictHandler :: Lens.Lens' SyncConfig (Prelude.Maybe ConflictHandlerType)
syncConfig_conflictHandler :: (Maybe ConflictHandlerType -> f (Maybe ConflictHandlerType))
-> SyncConfig -> f SyncConfig
syncConfig_conflictHandler = (SyncConfig -> Maybe ConflictHandlerType)
-> (SyncConfig -> Maybe ConflictHandlerType -> SyncConfig)
-> Lens
     SyncConfig
     SyncConfig
     (Maybe ConflictHandlerType)
     (Maybe ConflictHandlerType)
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 Conflict Detection strategy to use.
--
-- -   __VERSION__: Detect conflicts based on object versions for this
--     resolver.
--
-- -   __NONE__: Do not detect conflicts when executing this resolver.
syncConfig_conflictDetection :: Lens.Lens' SyncConfig (Prelude.Maybe ConflictDetectionType)
syncConfig_conflictDetection :: (Maybe ConflictDetectionType -> f (Maybe ConflictDetectionType))
-> SyncConfig -> f SyncConfig
syncConfig_conflictDetection = (SyncConfig -> Maybe ConflictDetectionType)
-> (SyncConfig -> Maybe ConflictDetectionType -> SyncConfig)
-> Lens
     SyncConfig
     SyncConfig
     (Maybe ConflictDetectionType)
     (Maybe ConflictDetectionType)
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 @LambdaConflictHandlerConfig@ when configuring LAMBDA as the
-- Conflict Handler.
syncConfig_lambdaConflictHandlerConfig :: Lens.Lens' SyncConfig (Prelude.Maybe LambdaConflictHandlerConfig)
syncConfig_lambdaConflictHandlerConfig :: (Maybe LambdaConflictHandlerConfig
 -> f (Maybe LambdaConflictHandlerConfig))
-> SyncConfig -> f SyncConfig
syncConfig_lambdaConflictHandlerConfig = (SyncConfig -> Maybe LambdaConflictHandlerConfig)
-> (SyncConfig -> Maybe LambdaConflictHandlerConfig -> SyncConfig)
-> Lens
     SyncConfig
     SyncConfig
     (Maybe LambdaConflictHandlerConfig)
     (Maybe 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 Core.FromJSON SyncConfig where
  parseJSON :: Value -> Parser SyncConfig
parseJSON =
    String
-> (Object -> Parser SyncConfig) -> Value -> Parser SyncConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SyncConfig"
      ( \Object
x ->
          Maybe ConflictHandlerType
-> Maybe ConflictDetectionType
-> Maybe LambdaConflictHandlerConfig
-> SyncConfig
SyncConfig'
            (Maybe ConflictHandlerType
 -> Maybe ConflictDetectionType
 -> Maybe LambdaConflictHandlerConfig
 -> SyncConfig)
-> Parser (Maybe ConflictHandlerType)
-> Parser
     (Maybe ConflictDetectionType
      -> Maybe LambdaConflictHandlerConfig -> SyncConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe ConflictHandlerType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"conflictHandler")
            Parser
  (Maybe ConflictDetectionType
   -> Maybe LambdaConflictHandlerConfig -> SyncConfig)
-> Parser (Maybe ConflictDetectionType)
-> Parser (Maybe LambdaConflictHandlerConfig -> SyncConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ConflictDetectionType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"conflictDetection")
            Parser (Maybe LambdaConflictHandlerConfig -> SyncConfig)
-> Parser (Maybe LambdaConflictHandlerConfig) -> Parser SyncConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe LambdaConflictHandlerConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"lambdaConflictHandlerConfig")
      )

instance Prelude.Hashable SyncConfig

instance Prelude.NFData SyncConfig

instance Core.ToJSON SyncConfig where
  toJSON :: SyncConfig -> Value
toJSON SyncConfig' {Maybe ConflictDetectionType
Maybe ConflictHandlerType
Maybe LambdaConflictHandlerConfig
lambdaConflictHandlerConfig :: Maybe LambdaConflictHandlerConfig
conflictDetection :: Maybe ConflictDetectionType
conflictHandler :: Maybe ConflictHandlerType
$sel:lambdaConflictHandlerConfig:SyncConfig' :: SyncConfig -> Maybe LambdaConflictHandlerConfig
$sel:conflictDetection:SyncConfig' :: SyncConfig -> Maybe ConflictDetectionType
$sel:conflictHandler:SyncConfig' :: SyncConfig -> Maybe ConflictHandlerType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"conflictHandler" Text -> ConflictHandlerType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (ConflictHandlerType -> Pair)
-> Maybe ConflictHandlerType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ConflictHandlerType
conflictHandler,
            (Text
"conflictDetection" Text -> ConflictDetectionType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (ConflictDetectionType -> Pair)
-> Maybe ConflictDetectionType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ConflictDetectionType
conflictDetection,
            (Text
"lambdaConflictHandlerConfig" Text -> LambdaConflictHandlerConfig -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (LambdaConflictHandlerConfig -> Pair)
-> Maybe LambdaConflictHandlerConfig -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe LambdaConflictHandlerConfig
lambdaConflictHandlerConfig
          ]
      )