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

import qualified Amazonka.Core as Core
import Amazonka.HoneyCode.Types.UpsertAction
import qualified Amazonka.Lens as Lens
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
(UpsertRowsResult -> UpsertRowsResult -> Bool)
-> (UpsertRowsResult -> UpsertRowsResult -> Bool)
-> Eq UpsertRowsResult
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]
(Int -> ReadS UpsertRowsResult)
-> ReadS [UpsertRowsResult]
-> ReadPrec UpsertRowsResult
-> ReadPrec [UpsertRowsResult]
-> Read 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
(Int -> UpsertRowsResult -> ShowS)
-> (UpsertRowsResult -> String)
-> ([UpsertRowsResult] -> ShowS)
-> Show UpsertRowsResult
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. UpsertRowsResult -> Rep UpsertRowsResult x)
-> (forall x. Rep UpsertRowsResult x -> UpsertRowsResult)
-> Generic UpsertRowsResult
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' :: NonEmpty Text -> UpsertAction -> UpsertRowsResult
UpsertRowsResult'
    { $sel:rowIds:UpsertRowsResult' :: NonEmpty Text
rowIds =
        Tagged (NonEmpty Text) (Identity (NonEmpty Text))
-> Tagged (NonEmpty Text) (Identity (NonEmpty Text))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Text) (Identity (NonEmpty Text))
 -> Tagged (NonEmpty Text) (Identity (NonEmpty Text)))
-> NonEmpty Text -> NonEmpty Text
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 :: (NonEmpty Text -> f (NonEmpty Text))
-> UpsertRowsResult -> f UpsertRowsResult
upsertRowsResult_rowIds = (UpsertRowsResult -> NonEmpty Text)
-> (UpsertRowsResult -> NonEmpty Text -> UpsertRowsResult)
-> Lens
     UpsertRowsResult UpsertRowsResult (NonEmpty Text) (NonEmpty Text)
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) ((NonEmpty Text -> f (NonEmpty Text))
 -> UpsertRowsResult -> f UpsertRowsResult)
-> ((NonEmpty Text -> f (NonEmpty Text))
    -> NonEmpty Text -> f (NonEmpty Text))
-> (NonEmpty Text -> f (NonEmpty Text))
-> UpsertRowsResult
-> f UpsertRowsResult
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Text -> f (NonEmpty Text))
-> NonEmpty Text -> f (NonEmpty Text)
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 :: (UpsertAction -> f UpsertAction)
-> UpsertRowsResult -> f UpsertRowsResult
upsertRowsResult_upsertAction = (UpsertRowsResult -> UpsertAction)
-> (UpsertRowsResult -> UpsertAction -> UpsertRowsResult)
-> Lens UpsertRowsResult UpsertRowsResult UpsertAction 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 Core.FromJSON UpsertRowsResult where
  parseJSON :: Value -> Parser UpsertRowsResult
parseJSON =
    String
-> (Object -> Parser UpsertRowsResult)
-> Value
-> Parser UpsertRowsResult
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"UpsertRowsResult"
      ( \Object
x ->
          NonEmpty Text -> UpsertAction -> UpsertRowsResult
UpsertRowsResult'
            (NonEmpty Text -> UpsertAction -> UpsertRowsResult)
-> Parser (NonEmpty Text)
-> Parser (UpsertAction -> UpsertRowsResult)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (NonEmpty Text)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"rowIds")
            Parser (UpsertAction -> UpsertRowsResult)
-> Parser UpsertAction -> Parser UpsertRowsResult
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser UpsertAction
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"upsertAction")
      )

instance Prelude.Hashable UpsertRowsResult

instance Prelude.NFData UpsertRowsResult