{-# 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.HoneyCode.Types.UpsertRowsResult
-- 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.HoneyCode.Types.UpsertRowsResult where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.HoneyCode.Types.UpsertAction
import qualified Amazonka.Prelude as Prelude

-- | An object that represents the result of a single upsert row request.
--
-- /See:/ 'newUpsertRowsResult' smart constructor.
data UpsertRowsResult = UpsertRowsResult'
  { -- | The list of row ids that were changed as part of an upsert row
    -- operation. If the upsert resulted in an update, this list could
    -- potentially contain multiple rows that matched the filter and hence got
    -- updated. If the upsert resulted in an append, this list would only have
    -- the single row that was appended.
    UpsertRowsResult -> NonEmpty Text
rowIds :: Prelude.NonEmpty Prelude.Text,
    -- | The result of the upsert action.
    UpsertRowsResult -> UpsertAction
upsertAction :: UpsertAction
  }
  deriving (UpsertRowsResult -> UpsertRowsResult -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpsertRowsResult -> UpsertRowsResult -> Bool
$c/= :: UpsertRowsResult -> UpsertRowsResult -> Bool
== :: UpsertRowsResult -> UpsertRowsResult -> Bool
$c== :: UpsertRowsResult -> UpsertRowsResult -> Bool
Prelude.Eq, ReadPrec [UpsertRowsResult]
ReadPrec UpsertRowsResult
Int -> ReadS UpsertRowsResult
ReadS [UpsertRowsResult]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpsertRowsResult]
$creadListPrec :: ReadPrec [UpsertRowsResult]
readPrec :: ReadPrec UpsertRowsResult
$creadPrec :: ReadPrec UpsertRowsResult
readList :: ReadS [UpsertRowsResult]
$creadList :: ReadS [UpsertRowsResult]
readsPrec :: Int -> ReadS UpsertRowsResult
$creadsPrec :: Int -> ReadS UpsertRowsResult
Prelude.Read, Int -> UpsertRowsResult -> ShowS
[UpsertRowsResult] -> ShowS
UpsertRowsResult -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpsertRowsResult] -> ShowS
$cshowList :: [UpsertRowsResult] -> ShowS
show :: UpsertRowsResult -> String
$cshow :: UpsertRowsResult -> String
showsPrec :: Int -> UpsertRowsResult -> ShowS
$cshowsPrec :: Int -> UpsertRowsResult -> ShowS
Prelude.Show, forall x. Rep UpsertRowsResult x -> UpsertRowsResult
forall x. UpsertRowsResult -> Rep UpsertRowsResult x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpsertRowsResult x -> UpsertRowsResult
$cfrom :: forall x. UpsertRowsResult -> Rep UpsertRowsResult x
Prelude.Generic)

-- |
-- Create a value of 'UpsertRowsResult' 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:
--
-- 'rowIds', 'upsertRowsResult_rowIds' - The list of row ids that were changed as part of an upsert row
-- operation. If the upsert resulted in an update, this list could
-- potentially contain multiple rows that matched the filter and hence got
-- updated. If the upsert resulted in an append, this list would only have
-- the single row that was appended.
--
-- 'upsertAction', 'upsertRowsResult_upsertAction' - The result of the upsert action.
newUpsertRowsResult ::
  -- | 'rowIds'
  Prelude.NonEmpty Prelude.Text ->
  -- | 'upsertAction'
  UpsertAction ->
  UpsertRowsResult
newUpsertRowsResult :: NonEmpty Text -> UpsertAction -> UpsertRowsResult
newUpsertRowsResult NonEmpty Text
pRowIds_ UpsertAction
pUpsertAction_ =
  UpsertRowsResult'
    { $sel:rowIds:UpsertRowsResult' :: NonEmpty Text
rowIds =
        forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pRowIds_,
      $sel:upsertAction:UpsertRowsResult' :: UpsertAction
upsertAction = UpsertAction
pUpsertAction_
    }

-- | The list of row ids that were changed as part of an upsert row
-- operation. If the upsert resulted in an update, this list could
-- potentially contain multiple rows that matched the filter and hence got
-- updated. If the upsert resulted in an append, this list would only have
-- the single row that was appended.
upsertRowsResult_rowIds :: Lens.Lens' UpsertRowsResult (Prelude.NonEmpty Prelude.Text)
upsertRowsResult_rowIds :: Lens' UpsertRowsResult (NonEmpty Text)
upsertRowsResult_rowIds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpsertRowsResult' {NonEmpty Text
rowIds :: NonEmpty Text
$sel:rowIds:UpsertRowsResult' :: UpsertRowsResult -> NonEmpty Text
rowIds} -> NonEmpty Text
rowIds) (\s :: UpsertRowsResult
s@UpsertRowsResult' {} NonEmpty Text
a -> UpsertRowsResult
s {$sel:rowIds:UpsertRowsResult' :: NonEmpty Text
rowIds = NonEmpty Text
a} :: UpsertRowsResult) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The result of the upsert action.
upsertRowsResult_upsertAction :: Lens.Lens' UpsertRowsResult UpsertAction
upsertRowsResult_upsertAction :: Lens' UpsertRowsResult UpsertAction
upsertRowsResult_upsertAction = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpsertRowsResult' {UpsertAction
upsertAction :: UpsertAction
$sel:upsertAction:UpsertRowsResult' :: UpsertRowsResult -> UpsertAction
upsertAction} -> UpsertAction
upsertAction) (\s :: UpsertRowsResult
s@UpsertRowsResult' {} UpsertAction
a -> UpsertRowsResult
s {$sel:upsertAction:UpsertRowsResult' :: UpsertAction
upsertAction = UpsertAction
a} :: UpsertRowsResult)

instance Data.FromJSON UpsertRowsResult where
  parseJSON :: Value -> Parser UpsertRowsResult
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"UpsertRowsResult"
      ( \Object
x ->
          NonEmpty Text -> UpsertAction -> UpsertRowsResult
UpsertRowsResult'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"rowIds")
            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
"upsertAction")
      )

instance Prelude.Hashable UpsertRowsResult where
  hashWithSalt :: Int -> UpsertRowsResult -> Int
hashWithSalt Int
_salt UpsertRowsResult' {NonEmpty Text
UpsertAction
upsertAction :: UpsertAction
rowIds :: NonEmpty Text
$sel:upsertAction:UpsertRowsResult' :: UpsertRowsResult -> UpsertAction
$sel:rowIds:UpsertRowsResult' :: UpsertRowsResult -> NonEmpty Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
rowIds
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` UpsertAction
upsertAction

instance Prelude.NFData UpsertRowsResult where
  rnf :: UpsertRowsResult -> ()
rnf UpsertRowsResult' {NonEmpty Text
UpsertAction
upsertAction :: UpsertAction
rowIds :: NonEmpty Text
$sel:upsertAction:UpsertRowsResult' :: UpsertRowsResult -> UpsertAction
$sel:rowIds:UpsertRowsResult' :: UpsertRowsResult -> NonEmpty Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Text
rowIds
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf UpsertAction
upsertAction