{-# 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.UpsertRowData
-- 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.UpsertRowData where

import qualified Amazonka.Core as Core
import Amazonka.HoneyCode.Types.CellInput
import Amazonka.HoneyCode.Types.Filter
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Data needed to upsert rows in a table as part of a single item in the
-- BatchUpsertTableRows request.
--
-- /See:/ 'newUpsertRowData' smart constructor.
data UpsertRowData = UpsertRowData'
  { -- | An external identifier that represents a single item in the request that
    -- is being upserted as part of the BatchUpsertTableRows request. This can
    -- be any string that you can use to identify the item in the request. The
    -- BatchUpsertTableRows API puts the batch item id in the results to allow
    -- you to link data in the request to data in the results.
    UpsertRowData -> Text
batchItemId :: Prelude.Text,
    -- | The filter formula to use to find existing matching rows to update. The
    -- formula needs to return zero or more rows. If the formula returns 0
    -- rows, then a new row will be appended in the target table. If the
    -- formula returns one or more rows, then the returned rows will be
    -- updated.
    --
    -- Note that the filter formula needs to return rows from the target table
    -- for the upsert operation to succeed. If the filter formula has a syntax
    -- error or it doesn\'t evaluate to zero or more rows in the target table
    -- for any one item in the input list, then the entire BatchUpsertTableRows
    -- request fails and no updates are made to the table.
    UpsertRowData -> Filter
filter' :: Filter,
    -- | A map representing the cells to update for the matching rows or an
    -- appended row. The key is the column id of the cell and the value is the
    -- CellInput object that represents the data to set in that cell.
    UpsertRowData -> HashMap Text CellInput
cellsToUpdate :: Prelude.HashMap Prelude.Text CellInput
  }
  deriving (UpsertRowData -> UpsertRowData -> Bool
(UpsertRowData -> UpsertRowData -> Bool)
-> (UpsertRowData -> UpsertRowData -> Bool) -> Eq UpsertRowData
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpsertRowData -> UpsertRowData -> Bool
$c/= :: UpsertRowData -> UpsertRowData -> Bool
== :: UpsertRowData -> UpsertRowData -> Bool
$c== :: UpsertRowData -> UpsertRowData -> Bool
Prelude.Eq, Int -> UpsertRowData -> ShowS
[UpsertRowData] -> ShowS
UpsertRowData -> String
(Int -> UpsertRowData -> ShowS)
-> (UpsertRowData -> String)
-> ([UpsertRowData] -> ShowS)
-> Show UpsertRowData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpsertRowData] -> ShowS
$cshowList :: [UpsertRowData] -> ShowS
show :: UpsertRowData -> String
$cshow :: UpsertRowData -> String
showsPrec :: Int -> UpsertRowData -> ShowS
$cshowsPrec :: Int -> UpsertRowData -> ShowS
Prelude.Show, (forall x. UpsertRowData -> Rep UpsertRowData x)
-> (forall x. Rep UpsertRowData x -> UpsertRowData)
-> Generic UpsertRowData
forall x. Rep UpsertRowData x -> UpsertRowData
forall x. UpsertRowData -> Rep UpsertRowData x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpsertRowData x -> UpsertRowData
$cfrom :: forall x. UpsertRowData -> Rep UpsertRowData x
Prelude.Generic)

-- |
-- Create a value of 'UpsertRowData' 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:
--
-- 'batchItemId', 'upsertRowData_batchItemId' - An external identifier that represents a single item in the request that
-- is being upserted as part of the BatchUpsertTableRows request. This can
-- be any string that you can use to identify the item in the request. The
-- BatchUpsertTableRows API puts the batch item id in the results to allow
-- you to link data in the request to data in the results.
--
-- 'filter'', 'upsertRowData_filter' - The filter formula to use to find existing matching rows to update. The
-- formula needs to return zero or more rows. If the formula returns 0
-- rows, then a new row will be appended in the target table. If the
-- formula returns one or more rows, then the returned rows will be
-- updated.
--
-- Note that the filter formula needs to return rows from the target table
-- for the upsert operation to succeed. If the filter formula has a syntax
-- error or it doesn\'t evaluate to zero or more rows in the target table
-- for any one item in the input list, then the entire BatchUpsertTableRows
-- request fails and no updates are made to the table.
--
-- 'cellsToUpdate', 'upsertRowData_cellsToUpdate' - A map representing the cells to update for the matching rows or an
-- appended row. The key is the column id of the cell and the value is the
-- CellInput object that represents the data to set in that cell.
newUpsertRowData ::
  -- | 'batchItemId'
  Prelude.Text ->
  -- | 'filter''
  Filter ->
  UpsertRowData
newUpsertRowData :: Text -> Filter -> UpsertRowData
newUpsertRowData Text
pBatchItemId_ Filter
pFilter_ =
  UpsertRowData' :: Text -> Filter -> HashMap Text CellInput -> UpsertRowData
UpsertRowData'
    { $sel:batchItemId:UpsertRowData' :: Text
batchItemId = Text
pBatchItemId_,
      $sel:filter':UpsertRowData' :: Filter
filter' = Filter
pFilter_,
      $sel:cellsToUpdate:UpsertRowData' :: HashMap Text CellInput
cellsToUpdate = HashMap Text CellInput
forall a. Monoid a => a
Prelude.mempty
    }

-- | An external identifier that represents a single item in the request that
-- is being upserted as part of the BatchUpsertTableRows request. This can
-- be any string that you can use to identify the item in the request. The
-- BatchUpsertTableRows API puts the batch item id in the results to allow
-- you to link data in the request to data in the results.
upsertRowData_batchItemId :: Lens.Lens' UpsertRowData Prelude.Text
upsertRowData_batchItemId :: (Text -> f Text) -> UpsertRowData -> f UpsertRowData
upsertRowData_batchItemId = (UpsertRowData -> Text)
-> (UpsertRowData -> Text -> UpsertRowData)
-> Lens UpsertRowData UpsertRowData Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpsertRowData' {Text
batchItemId :: Text
$sel:batchItemId:UpsertRowData' :: UpsertRowData -> Text
batchItemId} -> Text
batchItemId) (\s :: UpsertRowData
s@UpsertRowData' {} Text
a -> UpsertRowData
s {$sel:batchItemId:UpsertRowData' :: Text
batchItemId = Text
a} :: UpsertRowData)

-- | The filter formula to use to find existing matching rows to update. The
-- formula needs to return zero or more rows. If the formula returns 0
-- rows, then a new row will be appended in the target table. If the
-- formula returns one or more rows, then the returned rows will be
-- updated.
--
-- Note that the filter formula needs to return rows from the target table
-- for the upsert operation to succeed. If the filter formula has a syntax
-- error or it doesn\'t evaluate to zero or more rows in the target table
-- for any one item in the input list, then the entire BatchUpsertTableRows
-- request fails and no updates are made to the table.
upsertRowData_filter :: Lens.Lens' UpsertRowData Filter
upsertRowData_filter :: (Filter -> f Filter) -> UpsertRowData -> f UpsertRowData
upsertRowData_filter = (UpsertRowData -> Filter)
-> (UpsertRowData -> Filter -> UpsertRowData)
-> Lens UpsertRowData UpsertRowData Filter Filter
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpsertRowData' {Filter
filter' :: Filter
$sel:filter':UpsertRowData' :: UpsertRowData -> Filter
filter'} -> Filter
filter') (\s :: UpsertRowData
s@UpsertRowData' {} Filter
a -> UpsertRowData
s {$sel:filter':UpsertRowData' :: Filter
filter' = Filter
a} :: UpsertRowData)

-- | A map representing the cells to update for the matching rows or an
-- appended row. The key is the column id of the cell and the value is the
-- CellInput object that represents the data to set in that cell.
upsertRowData_cellsToUpdate :: Lens.Lens' UpsertRowData (Prelude.HashMap Prelude.Text CellInput)
upsertRowData_cellsToUpdate :: (HashMap Text CellInput -> f (HashMap Text CellInput))
-> UpsertRowData -> f UpsertRowData
upsertRowData_cellsToUpdate = (UpsertRowData -> HashMap Text CellInput)
-> (UpsertRowData -> HashMap Text CellInput -> UpsertRowData)
-> Lens
     UpsertRowData
     UpsertRowData
     (HashMap Text CellInput)
     (HashMap Text CellInput)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpsertRowData' {HashMap Text CellInput
cellsToUpdate :: HashMap Text CellInput
$sel:cellsToUpdate:UpsertRowData' :: UpsertRowData -> HashMap Text CellInput
cellsToUpdate} -> HashMap Text CellInput
cellsToUpdate) (\s :: UpsertRowData
s@UpsertRowData' {} HashMap Text CellInput
a -> UpsertRowData
s {$sel:cellsToUpdate:UpsertRowData' :: HashMap Text CellInput
cellsToUpdate = HashMap Text CellInput
a} :: UpsertRowData) ((HashMap Text CellInput -> f (HashMap Text CellInput))
 -> UpsertRowData -> f UpsertRowData)
-> ((HashMap Text CellInput -> f (HashMap Text CellInput))
    -> HashMap Text CellInput -> f (HashMap Text CellInput))
-> (HashMap Text CellInput -> f (HashMap Text CellInput))
-> UpsertRowData
-> f UpsertRowData
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (HashMap Text CellInput -> f (HashMap Text CellInput))
-> HashMap Text CellInput -> f (HashMap Text CellInput)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.Hashable UpsertRowData

instance Prelude.NFData UpsertRowData

instance Core.ToJSON UpsertRowData where
  toJSON :: UpsertRowData -> Value
toJSON UpsertRowData' {Text
HashMap Text CellInput
Filter
cellsToUpdate :: HashMap Text CellInput
filter' :: Filter
batchItemId :: Text
$sel:cellsToUpdate:UpsertRowData' :: UpsertRowData -> HashMap Text CellInput
$sel:filter':UpsertRowData' :: UpsertRowData -> Filter
$sel:batchItemId:UpsertRowData' :: UpsertRowData -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"batchItemId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
batchItemId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"filter" Text -> Filter -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Filter
filter'),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"cellsToUpdate" Text -> HashMap Text CellInput -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HashMap Text CellInput
cellsToUpdate)
          ]
      )