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

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

-- | Data needed to create a single row in a table as part of the
-- BatchCreateTableRows request.
--
-- /See:/ 'newUpdateRowData' smart constructor.
data UpdateRowData = UpdateRowData'
  { -- | The id of the row that needs to be updated.
    UpdateRowData -> Text
rowId :: Prelude.Text,
    -- | A map representing the cells to update in the given 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.
    UpdateRowData -> HashMap Text CellInput
cellsToUpdate :: Prelude.HashMap Prelude.Text CellInput
  }
  deriving (UpdateRowData -> UpdateRowData -> Bool
(UpdateRowData -> UpdateRowData -> Bool)
-> (UpdateRowData -> UpdateRowData -> Bool) -> Eq UpdateRowData
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateRowData -> UpdateRowData -> Bool
$c/= :: UpdateRowData -> UpdateRowData -> Bool
== :: UpdateRowData -> UpdateRowData -> Bool
$c== :: UpdateRowData -> UpdateRowData -> Bool
Prelude.Eq, Int -> UpdateRowData -> ShowS
[UpdateRowData] -> ShowS
UpdateRowData -> String
(Int -> UpdateRowData -> ShowS)
-> (UpdateRowData -> String)
-> ([UpdateRowData] -> ShowS)
-> Show UpdateRowData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateRowData] -> ShowS
$cshowList :: [UpdateRowData] -> ShowS
show :: UpdateRowData -> String
$cshow :: UpdateRowData -> String
showsPrec :: Int -> UpdateRowData -> ShowS
$cshowsPrec :: Int -> UpdateRowData -> ShowS
Prelude.Show, (forall x. UpdateRowData -> Rep UpdateRowData x)
-> (forall x. Rep UpdateRowData x -> UpdateRowData)
-> Generic UpdateRowData
forall x. Rep UpdateRowData x -> UpdateRowData
forall x. UpdateRowData -> Rep UpdateRowData x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateRowData x -> UpdateRowData
$cfrom :: forall x. UpdateRowData -> Rep UpdateRowData x
Prelude.Generic)

-- |
-- Create a value of 'UpdateRowData' 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:
--
-- 'rowId', 'updateRowData_rowId' - The id of the row that needs to be updated.
--
-- 'cellsToUpdate', 'updateRowData_cellsToUpdate' - A map representing the cells to update in the given 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.
newUpdateRowData ::
  -- | 'rowId'
  Prelude.Text ->
  UpdateRowData
newUpdateRowData :: Text -> UpdateRowData
newUpdateRowData Text
pRowId_ =
  UpdateRowData' :: Text -> HashMap Text CellInput -> UpdateRowData
UpdateRowData'
    { $sel:rowId:UpdateRowData' :: Text
rowId = Text
pRowId_,
      $sel:cellsToUpdate:UpdateRowData' :: HashMap Text CellInput
cellsToUpdate = HashMap Text CellInput
forall a. Monoid a => a
Prelude.mempty
    }

-- | The id of the row that needs to be updated.
updateRowData_rowId :: Lens.Lens' UpdateRowData Prelude.Text
updateRowData_rowId :: (Text -> f Text) -> UpdateRowData -> f UpdateRowData
updateRowData_rowId = (UpdateRowData -> Text)
-> (UpdateRowData -> Text -> UpdateRowData)
-> Lens UpdateRowData UpdateRowData Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateRowData' {Text
rowId :: Text
$sel:rowId:UpdateRowData' :: UpdateRowData -> Text
rowId} -> Text
rowId) (\s :: UpdateRowData
s@UpdateRowData' {} Text
a -> UpdateRowData
s {$sel:rowId:UpdateRowData' :: Text
rowId = Text
a} :: UpdateRowData)

-- | A map representing the cells to update in the given 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.
updateRowData_cellsToUpdate :: Lens.Lens' UpdateRowData (Prelude.HashMap Prelude.Text CellInput)
updateRowData_cellsToUpdate :: (HashMap Text CellInput -> f (HashMap Text CellInput))
-> UpdateRowData -> f UpdateRowData
updateRowData_cellsToUpdate = (UpdateRowData -> HashMap Text CellInput)
-> (UpdateRowData -> HashMap Text CellInput -> UpdateRowData)
-> Lens
     UpdateRowData
     UpdateRowData
     (HashMap Text CellInput)
     (HashMap Text CellInput)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateRowData' {HashMap Text CellInput
cellsToUpdate :: HashMap Text CellInput
$sel:cellsToUpdate:UpdateRowData' :: UpdateRowData -> HashMap Text CellInput
cellsToUpdate} -> HashMap Text CellInput
cellsToUpdate) (\s :: UpdateRowData
s@UpdateRowData' {} HashMap Text CellInput
a -> UpdateRowData
s {$sel:cellsToUpdate:UpdateRowData' :: HashMap Text CellInput
cellsToUpdate = HashMap Text CellInput
a} :: UpdateRowData) ((HashMap Text CellInput -> f (HashMap Text CellInput))
 -> UpdateRowData -> f UpdateRowData)
-> ((HashMap Text CellInput -> f (HashMap Text CellInput))
    -> HashMap Text CellInput -> f (HashMap Text CellInput))
-> (HashMap Text CellInput -> f (HashMap Text CellInput))
-> UpdateRowData
-> f UpdateRowData
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 UpdateRowData

instance Prelude.NFData UpdateRowData

instance Core.ToJSON UpdateRowData where
  toJSON :: UpdateRowData -> Value
toJSON UpdateRowData' {Text
HashMap Text CellInput
cellsToUpdate :: HashMap Text CellInput
rowId :: Text
$sel:cellsToUpdate:UpdateRowData' :: UpdateRowData -> HashMap Text CellInput
$sel:rowId:UpdateRowData' :: UpdateRowData -> 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
"rowId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
rowId),
            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)
          ]
      )