{-# 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.CustomerProfiles.Types.ConflictResolution
-- 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.CustomerProfiles.Types.ConflictResolution where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import Amazonka.CustomerProfiles.Types.ConflictResolvingModel
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | How the auto-merging process should resolve conflicts between different
-- profiles.
--
-- /See:/ 'newConflictResolution' smart constructor.
data ConflictResolution = ConflictResolution'
  { -- | The @ObjectType@ name that is used to resolve profile merging conflicts
    -- when choosing @SOURCE@ as the @ConflictResolvingModel@.
    ConflictResolution -> Maybe Text
sourceName :: Prelude.Maybe Prelude.Text,
    -- | How the auto-merging process should resolve conflicts between different
    -- profiles.
    --
    -- -   @RECENCY@: Uses the data that was most recently updated.
    --
    -- -   @SOURCE@: Uses the data from a specific source. For example, if a
    --     company has been aquired or two departments have merged, data from
    --     the specified source is used. If two duplicate profiles are from the
    --     same source, then @RECENCY@ is used again.
    ConflictResolution -> ConflictResolvingModel
conflictResolvingModel :: ConflictResolvingModel
  }
  deriving (ConflictResolution -> ConflictResolution -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConflictResolution -> ConflictResolution -> Bool
$c/= :: ConflictResolution -> ConflictResolution -> Bool
== :: ConflictResolution -> ConflictResolution -> Bool
$c== :: ConflictResolution -> ConflictResolution -> Bool
Prelude.Eq, ReadPrec [ConflictResolution]
ReadPrec ConflictResolution
Int -> ReadS ConflictResolution
ReadS [ConflictResolution]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ConflictResolution]
$creadListPrec :: ReadPrec [ConflictResolution]
readPrec :: ReadPrec ConflictResolution
$creadPrec :: ReadPrec ConflictResolution
readList :: ReadS [ConflictResolution]
$creadList :: ReadS [ConflictResolution]
readsPrec :: Int -> ReadS ConflictResolution
$creadsPrec :: Int -> ReadS ConflictResolution
Prelude.Read, Int -> ConflictResolution -> ShowS
[ConflictResolution] -> ShowS
ConflictResolution -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConflictResolution] -> ShowS
$cshowList :: [ConflictResolution] -> ShowS
show :: ConflictResolution -> String
$cshow :: ConflictResolution -> String
showsPrec :: Int -> ConflictResolution -> ShowS
$cshowsPrec :: Int -> ConflictResolution -> ShowS
Prelude.Show, forall x. Rep ConflictResolution x -> ConflictResolution
forall x. ConflictResolution -> Rep ConflictResolution x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ConflictResolution x -> ConflictResolution
$cfrom :: forall x. ConflictResolution -> Rep ConflictResolution x
Prelude.Generic)

-- |
-- Create a value of 'ConflictResolution' 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:
--
-- 'sourceName', 'conflictResolution_sourceName' - The @ObjectType@ name that is used to resolve profile merging conflicts
-- when choosing @SOURCE@ as the @ConflictResolvingModel@.
--
-- 'conflictResolvingModel', 'conflictResolution_conflictResolvingModel' - How the auto-merging process should resolve conflicts between different
-- profiles.
--
-- -   @RECENCY@: Uses the data that was most recently updated.
--
-- -   @SOURCE@: Uses the data from a specific source. For example, if a
--     company has been aquired or two departments have merged, data from
--     the specified source is used. If two duplicate profiles are from the
--     same source, then @RECENCY@ is used again.
newConflictResolution ::
  -- | 'conflictResolvingModel'
  ConflictResolvingModel ->
  ConflictResolution
newConflictResolution :: ConflictResolvingModel -> ConflictResolution
newConflictResolution ConflictResolvingModel
pConflictResolvingModel_ =
  ConflictResolution'
    { $sel:sourceName:ConflictResolution' :: Maybe Text
sourceName = forall a. Maybe a
Prelude.Nothing,
      $sel:conflictResolvingModel:ConflictResolution' :: ConflictResolvingModel
conflictResolvingModel = ConflictResolvingModel
pConflictResolvingModel_
    }

-- | The @ObjectType@ name that is used to resolve profile merging conflicts
-- when choosing @SOURCE@ as the @ConflictResolvingModel@.
conflictResolution_sourceName :: Lens.Lens' ConflictResolution (Prelude.Maybe Prelude.Text)
conflictResolution_sourceName :: Lens' ConflictResolution (Maybe Text)
conflictResolution_sourceName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConflictResolution' {Maybe Text
sourceName :: Maybe Text
$sel:sourceName:ConflictResolution' :: ConflictResolution -> Maybe Text
sourceName} -> Maybe Text
sourceName) (\s :: ConflictResolution
s@ConflictResolution' {} Maybe Text
a -> ConflictResolution
s {$sel:sourceName:ConflictResolution' :: Maybe Text
sourceName = Maybe Text
a} :: ConflictResolution)

-- | How the auto-merging process should resolve conflicts between different
-- profiles.
--
-- -   @RECENCY@: Uses the data that was most recently updated.
--
-- -   @SOURCE@: Uses the data from a specific source. For example, if a
--     company has been aquired or two departments have merged, data from
--     the specified source is used. If two duplicate profiles are from the
--     same source, then @RECENCY@ is used again.
conflictResolution_conflictResolvingModel :: Lens.Lens' ConflictResolution ConflictResolvingModel
conflictResolution_conflictResolvingModel :: Lens' ConflictResolution ConflictResolvingModel
conflictResolution_conflictResolvingModel = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConflictResolution' {ConflictResolvingModel
conflictResolvingModel :: ConflictResolvingModel
$sel:conflictResolvingModel:ConflictResolution' :: ConflictResolution -> ConflictResolvingModel
conflictResolvingModel} -> ConflictResolvingModel
conflictResolvingModel) (\s :: ConflictResolution
s@ConflictResolution' {} ConflictResolvingModel
a -> ConflictResolution
s {$sel:conflictResolvingModel:ConflictResolution' :: ConflictResolvingModel
conflictResolvingModel = ConflictResolvingModel
a} :: ConflictResolution)

instance Data.FromJSON ConflictResolution where
  parseJSON :: Value -> Parser ConflictResolution
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ConflictResolution"
      ( \Object
x ->
          Maybe Text -> ConflictResolvingModel -> ConflictResolution
ConflictResolution'
            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
"SourceName")
            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
"ConflictResolvingModel")
      )

instance Prelude.Hashable ConflictResolution where
  hashWithSalt :: Int -> ConflictResolution -> Int
hashWithSalt Int
_salt ConflictResolution' {Maybe Text
ConflictResolvingModel
conflictResolvingModel :: ConflictResolvingModel
sourceName :: Maybe Text
$sel:conflictResolvingModel:ConflictResolution' :: ConflictResolution -> ConflictResolvingModel
$sel:sourceName:ConflictResolution' :: ConflictResolution -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
sourceName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ConflictResolvingModel
conflictResolvingModel

instance Prelude.NFData ConflictResolution where
  rnf :: ConflictResolution -> ()
rnf ConflictResolution' {Maybe Text
ConflictResolvingModel
conflictResolvingModel :: ConflictResolvingModel
sourceName :: Maybe Text
$sel:conflictResolvingModel:ConflictResolution' :: ConflictResolution -> ConflictResolvingModel
$sel:sourceName:ConflictResolution' :: ConflictResolution -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
sourceName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ConflictResolvingModel
conflictResolvingModel

instance Data.ToJSON ConflictResolution where
  toJSON :: ConflictResolution -> Value
toJSON ConflictResolution' {Maybe Text
ConflictResolvingModel
conflictResolvingModel :: ConflictResolvingModel
sourceName :: Maybe Text
$sel:conflictResolvingModel:ConflictResolution' :: ConflictResolution -> ConflictResolvingModel
$sel:sourceName:ConflictResolution' :: ConflictResolution -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"SourceName" 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
sourceName,
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"ConflictResolvingModel"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ConflictResolvingModel
conflictResolvingModel
              )
          ]
      )