{-# 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.CognitoSync.Types.RecordPatch
-- 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.CognitoSync.Types.RecordPatch where

import Amazonka.CognitoSync.Types.Operation
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

-- | An update operation for a record.
--
-- /See:/ 'newRecordPatch' smart constructor.
data RecordPatch = RecordPatch'
  { -- | The last modified date of the client device.
    RecordPatch -> Maybe POSIX
deviceLastModifiedDate :: Prelude.Maybe Data.POSIX,
    -- | The value associated with the record patch.
    RecordPatch -> Maybe Text
value :: Prelude.Maybe Prelude.Text,
    -- | An operation, either replace or remove.
    RecordPatch -> Operation
op :: Operation,
    -- | The key associated with the record patch.
    RecordPatch -> Text
key :: Prelude.Text,
    -- | Last known server sync count for this record. Set to 0 if unknown.
    RecordPatch -> Integer
syncCount :: Prelude.Integer
  }
  deriving (RecordPatch -> RecordPatch -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RecordPatch -> RecordPatch -> Bool
$c/= :: RecordPatch -> RecordPatch -> Bool
== :: RecordPatch -> RecordPatch -> Bool
$c== :: RecordPatch -> RecordPatch -> Bool
Prelude.Eq, ReadPrec [RecordPatch]
ReadPrec RecordPatch
Int -> ReadS RecordPatch
ReadS [RecordPatch]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RecordPatch]
$creadListPrec :: ReadPrec [RecordPatch]
readPrec :: ReadPrec RecordPatch
$creadPrec :: ReadPrec RecordPatch
readList :: ReadS [RecordPatch]
$creadList :: ReadS [RecordPatch]
readsPrec :: Int -> ReadS RecordPatch
$creadsPrec :: Int -> ReadS RecordPatch
Prelude.Read, Int -> RecordPatch -> ShowS
[RecordPatch] -> ShowS
RecordPatch -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RecordPatch] -> ShowS
$cshowList :: [RecordPatch] -> ShowS
show :: RecordPatch -> String
$cshow :: RecordPatch -> String
showsPrec :: Int -> RecordPatch -> ShowS
$cshowsPrec :: Int -> RecordPatch -> ShowS
Prelude.Show, forall x. Rep RecordPatch x -> RecordPatch
forall x. RecordPatch -> Rep RecordPatch x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RecordPatch x -> RecordPatch
$cfrom :: forall x. RecordPatch -> Rep RecordPatch x
Prelude.Generic)

-- |
-- Create a value of 'RecordPatch' 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:
--
-- 'deviceLastModifiedDate', 'recordPatch_deviceLastModifiedDate' - The last modified date of the client device.
--
-- 'value', 'recordPatch_value' - The value associated with the record patch.
--
-- 'op', 'recordPatch_op' - An operation, either replace or remove.
--
-- 'key', 'recordPatch_key' - The key associated with the record patch.
--
-- 'syncCount', 'recordPatch_syncCount' - Last known server sync count for this record. Set to 0 if unknown.
newRecordPatch ::
  -- | 'op'
  Operation ->
  -- | 'key'
  Prelude.Text ->
  -- | 'syncCount'
  Prelude.Integer ->
  RecordPatch
newRecordPatch :: Operation -> Text -> Integer -> RecordPatch
newRecordPatch Operation
pOp_ Text
pKey_ Integer
pSyncCount_ =
  RecordPatch'
    { $sel:deviceLastModifiedDate:RecordPatch' :: Maybe POSIX
deviceLastModifiedDate =
        forall a. Maybe a
Prelude.Nothing,
      $sel:value:RecordPatch' :: Maybe Text
value = forall a. Maybe a
Prelude.Nothing,
      $sel:op:RecordPatch' :: Operation
op = Operation
pOp_,
      $sel:key:RecordPatch' :: Text
key = Text
pKey_,
      $sel:syncCount:RecordPatch' :: Integer
syncCount = Integer
pSyncCount_
    }

-- | The last modified date of the client device.
recordPatch_deviceLastModifiedDate :: Lens.Lens' RecordPatch (Prelude.Maybe Prelude.UTCTime)
recordPatch_deviceLastModifiedDate :: Lens' RecordPatch (Maybe UTCTime)
recordPatch_deviceLastModifiedDate = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RecordPatch' {Maybe POSIX
deviceLastModifiedDate :: Maybe POSIX
$sel:deviceLastModifiedDate:RecordPatch' :: RecordPatch -> Maybe POSIX
deviceLastModifiedDate} -> Maybe POSIX
deviceLastModifiedDate) (\s :: RecordPatch
s@RecordPatch' {} Maybe POSIX
a -> RecordPatch
s {$sel:deviceLastModifiedDate:RecordPatch' :: Maybe POSIX
deviceLastModifiedDate = Maybe POSIX
a} :: RecordPatch) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | The value associated with the record patch.
recordPatch_value :: Lens.Lens' RecordPatch (Prelude.Maybe Prelude.Text)
recordPatch_value :: Lens' RecordPatch (Maybe Text)
recordPatch_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RecordPatch' {Maybe Text
value :: Maybe Text
$sel:value:RecordPatch' :: RecordPatch -> Maybe Text
value} -> Maybe Text
value) (\s :: RecordPatch
s@RecordPatch' {} Maybe Text
a -> RecordPatch
s {$sel:value:RecordPatch' :: Maybe Text
value = Maybe Text
a} :: RecordPatch)

-- | An operation, either replace or remove.
recordPatch_op :: Lens.Lens' RecordPatch Operation
recordPatch_op :: Lens' RecordPatch Operation
recordPatch_op = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RecordPatch' {Operation
op :: Operation
$sel:op:RecordPatch' :: RecordPatch -> Operation
op} -> Operation
op) (\s :: RecordPatch
s@RecordPatch' {} Operation
a -> RecordPatch
s {$sel:op:RecordPatch' :: Operation
op = Operation
a} :: RecordPatch)

-- | The key associated with the record patch.
recordPatch_key :: Lens.Lens' RecordPatch Prelude.Text
recordPatch_key :: Lens' RecordPatch Text
recordPatch_key = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RecordPatch' {Text
key :: Text
$sel:key:RecordPatch' :: RecordPatch -> Text
key} -> Text
key) (\s :: RecordPatch
s@RecordPatch' {} Text
a -> RecordPatch
s {$sel:key:RecordPatch' :: Text
key = Text
a} :: RecordPatch)

-- | Last known server sync count for this record. Set to 0 if unknown.
recordPatch_syncCount :: Lens.Lens' RecordPatch Prelude.Integer
recordPatch_syncCount :: Lens' RecordPatch Integer
recordPatch_syncCount = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RecordPatch' {Integer
syncCount :: Integer
$sel:syncCount:RecordPatch' :: RecordPatch -> Integer
syncCount} -> Integer
syncCount) (\s :: RecordPatch
s@RecordPatch' {} Integer
a -> RecordPatch
s {$sel:syncCount:RecordPatch' :: Integer
syncCount = Integer
a} :: RecordPatch)

instance Prelude.Hashable RecordPatch where
  hashWithSalt :: Int -> RecordPatch -> Int
hashWithSalt Int
_salt RecordPatch' {Integer
Maybe Text
Maybe POSIX
Text
Operation
syncCount :: Integer
key :: Text
op :: Operation
value :: Maybe Text
deviceLastModifiedDate :: Maybe POSIX
$sel:syncCount:RecordPatch' :: RecordPatch -> Integer
$sel:key:RecordPatch' :: RecordPatch -> Text
$sel:op:RecordPatch' :: RecordPatch -> Operation
$sel:value:RecordPatch' :: RecordPatch -> Maybe Text
$sel:deviceLastModifiedDate:RecordPatch' :: RecordPatch -> Maybe POSIX
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
deviceLastModifiedDate
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
value
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Operation
op
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
key
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Integer
syncCount

instance Prelude.NFData RecordPatch where
  rnf :: RecordPatch -> ()
rnf RecordPatch' {Integer
Maybe Text
Maybe POSIX
Text
Operation
syncCount :: Integer
key :: Text
op :: Operation
value :: Maybe Text
deviceLastModifiedDate :: Maybe POSIX
$sel:syncCount:RecordPatch' :: RecordPatch -> Integer
$sel:key:RecordPatch' :: RecordPatch -> Text
$sel:op:RecordPatch' :: RecordPatch -> Operation
$sel:value:RecordPatch' :: RecordPatch -> Maybe Text
$sel:deviceLastModifiedDate:RecordPatch' :: RecordPatch -> Maybe POSIX
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
deviceLastModifiedDate
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
value
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Operation
op
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
key
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Integer
syncCount

instance Data.ToJSON RecordPatch where
  toJSON :: RecordPatch -> Value
toJSON RecordPatch' {Integer
Maybe Text
Maybe POSIX
Text
Operation
syncCount :: Integer
key :: Text
op :: Operation
value :: Maybe Text
deviceLastModifiedDate :: Maybe POSIX
$sel:syncCount:RecordPatch' :: RecordPatch -> Integer
$sel:key:RecordPatch' :: RecordPatch -> Text
$sel:op:RecordPatch' :: RecordPatch -> Operation
$sel:value:RecordPatch' :: RecordPatch -> Maybe Text
$sel:deviceLastModifiedDate:RecordPatch' :: RecordPatch -> Maybe POSIX
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"DeviceLastModifiedDate" 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 POSIX
deviceLastModifiedDate,
            (Key
"Value" 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
value,
            forall a. a -> Maybe a
Prelude.Just (Key
"Op" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Operation
op),
            forall a. a -> Maybe a
Prelude.Just (Key
"Key" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
key),
            forall a. a -> Maybe a
Prelude.Just (Key
"SyncCount" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Integer
syncCount)
          ]
      )