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

import Amazonka.CognitoSync.Types.Operation
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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 Core.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
(RecordPatch -> RecordPatch -> Bool)
-> (RecordPatch -> RecordPatch -> Bool) -> Eq RecordPatch
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]
(Int -> ReadS RecordPatch)
-> ReadS [RecordPatch]
-> ReadPrec RecordPatch
-> ReadPrec [RecordPatch]
-> Read 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
(Int -> RecordPatch -> ShowS)
-> (RecordPatch -> String)
-> ([RecordPatch] -> ShowS)
-> Show RecordPatch
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. RecordPatch -> Rep RecordPatch x)
-> (forall x. Rep RecordPatch x -> RecordPatch)
-> Generic RecordPatch
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' :: Maybe POSIX
-> Maybe Text -> Operation -> Text -> Integer -> RecordPatch
RecordPatch'
    { $sel:deviceLastModifiedDate:RecordPatch' :: Maybe POSIX
deviceLastModifiedDate =
        Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:value:RecordPatch' :: Maybe Text
value = Maybe Text
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 :: (Maybe UTCTime -> f (Maybe UTCTime))
-> RecordPatch -> f RecordPatch
recordPatch_deviceLastModifiedDate = (RecordPatch -> Maybe POSIX)
-> (RecordPatch -> Maybe POSIX -> RecordPatch)
-> Lens RecordPatch RecordPatch (Maybe POSIX) (Maybe POSIX)
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) ((Maybe POSIX -> f (Maybe POSIX)) -> RecordPatch -> f RecordPatch)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> RecordPatch
-> f RecordPatch
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The value associated with the record patch.
recordPatch_value :: Lens.Lens' RecordPatch (Prelude.Maybe Prelude.Text)
recordPatch_value :: (Maybe Text -> f (Maybe Text)) -> RecordPatch -> f RecordPatch
recordPatch_value = (RecordPatch -> Maybe Text)
-> (RecordPatch -> Maybe Text -> RecordPatch)
-> Lens RecordPatch RecordPatch (Maybe Text) (Maybe Text)
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 :: (Operation -> f Operation) -> RecordPatch -> f RecordPatch
recordPatch_op = (RecordPatch -> Operation)
-> (RecordPatch -> Operation -> RecordPatch)
-> Lens RecordPatch RecordPatch Operation Operation
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 :: (Text -> f Text) -> RecordPatch -> f RecordPatch
recordPatch_key = (RecordPatch -> Text)
-> (RecordPatch -> Text -> RecordPatch)
-> Lens RecordPatch RecordPatch Text Text
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 :: (Integer -> f Integer) -> RecordPatch -> f RecordPatch
recordPatch_syncCount = (RecordPatch -> Integer)
-> (RecordPatch -> Integer -> RecordPatch)
-> Lens RecordPatch RecordPatch Integer Integer
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

instance Prelude.NFData RecordPatch

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"DeviceLastModifiedDate" Text -> POSIX -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (POSIX -> Pair) -> Maybe POSIX -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe POSIX
deviceLastModifiedDate,
            (Text
"Value" 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
value,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Op" Text -> Operation -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Operation
op),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Key" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
key),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"SyncCount" Text -> Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Integer
syncCount)
          ]
      )