{-# 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.SDB.Types.UpdateCondition
-- 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.SDB.Types.UpdateCondition where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Specifies the conditions under which data should be updated. If an
-- update condition is specified for a request, the data will only be
-- updated if the condition is satisfied. For example, if an attribute with
-- a specific name and value exists, or if a specific attribute doesn\'t
-- exist.
--
-- /See:/ 'newUpdateCondition' smart constructor.
data UpdateCondition = UpdateCondition'
  { -- | A value specifying whether or not the specified attribute must exist
    -- with the specified value in order for the update condition to be
    -- satisfied. Specify @true@ if the attribute must exist for the update
    -- condition to be satisfied. Specify @false@ if the attribute should not
    -- exist in order for the update condition to be satisfied.
    UpdateCondition -> Maybe Bool
exists :: Prelude.Maybe Prelude.Bool,
    -- | The value of an attribute. This value can only be specified when the
    -- @Exists@ parameter is equal to @true@.
    UpdateCondition -> Maybe Text
value :: Prelude.Maybe Prelude.Text,
    -- | The name of the attribute involved in the condition.
    UpdateCondition -> Maybe Text
name :: Prelude.Maybe Prelude.Text
  }
  deriving (UpdateCondition -> UpdateCondition -> Bool
(UpdateCondition -> UpdateCondition -> Bool)
-> (UpdateCondition -> UpdateCondition -> Bool)
-> Eq UpdateCondition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateCondition -> UpdateCondition -> Bool
$c/= :: UpdateCondition -> UpdateCondition -> Bool
== :: UpdateCondition -> UpdateCondition -> Bool
$c== :: UpdateCondition -> UpdateCondition -> Bool
Prelude.Eq, ReadPrec [UpdateCondition]
ReadPrec UpdateCondition
Int -> ReadS UpdateCondition
ReadS [UpdateCondition]
(Int -> ReadS UpdateCondition)
-> ReadS [UpdateCondition]
-> ReadPrec UpdateCondition
-> ReadPrec [UpdateCondition]
-> Read UpdateCondition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateCondition]
$creadListPrec :: ReadPrec [UpdateCondition]
readPrec :: ReadPrec UpdateCondition
$creadPrec :: ReadPrec UpdateCondition
readList :: ReadS [UpdateCondition]
$creadList :: ReadS [UpdateCondition]
readsPrec :: Int -> ReadS UpdateCondition
$creadsPrec :: Int -> ReadS UpdateCondition
Prelude.Read, Int -> UpdateCondition -> ShowS
[UpdateCondition] -> ShowS
UpdateCondition -> String
(Int -> UpdateCondition -> ShowS)
-> (UpdateCondition -> String)
-> ([UpdateCondition] -> ShowS)
-> Show UpdateCondition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateCondition] -> ShowS
$cshowList :: [UpdateCondition] -> ShowS
show :: UpdateCondition -> String
$cshow :: UpdateCondition -> String
showsPrec :: Int -> UpdateCondition -> ShowS
$cshowsPrec :: Int -> UpdateCondition -> ShowS
Prelude.Show, (forall x. UpdateCondition -> Rep UpdateCondition x)
-> (forall x. Rep UpdateCondition x -> UpdateCondition)
-> Generic UpdateCondition
forall x. Rep UpdateCondition x -> UpdateCondition
forall x. UpdateCondition -> Rep UpdateCondition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateCondition x -> UpdateCondition
$cfrom :: forall x. UpdateCondition -> Rep UpdateCondition x
Prelude.Generic)

-- |
-- Create a value of 'UpdateCondition' 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:
--
-- 'exists', 'updateCondition_exists' - A value specifying whether or not the specified attribute must exist
-- with the specified value in order for the update condition to be
-- satisfied. Specify @true@ if the attribute must exist for the update
-- condition to be satisfied. Specify @false@ if the attribute should not
-- exist in order for the update condition to be satisfied.
--
-- 'value', 'updateCondition_value' - The value of an attribute. This value can only be specified when the
-- @Exists@ parameter is equal to @true@.
--
-- 'name', 'updateCondition_name' - The name of the attribute involved in the condition.
newUpdateCondition ::
  UpdateCondition
newUpdateCondition :: UpdateCondition
newUpdateCondition =
  UpdateCondition' :: Maybe Bool -> Maybe Text -> Maybe Text -> UpdateCondition
UpdateCondition'
    { $sel:exists:UpdateCondition' :: Maybe Bool
exists = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:value:UpdateCondition' :: Maybe Text
value = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:UpdateCondition' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | A value specifying whether or not the specified attribute must exist
-- with the specified value in order for the update condition to be
-- satisfied. Specify @true@ if the attribute must exist for the update
-- condition to be satisfied. Specify @false@ if the attribute should not
-- exist in order for the update condition to be satisfied.
updateCondition_exists :: Lens.Lens' UpdateCondition (Prelude.Maybe Prelude.Bool)
updateCondition_exists :: (Maybe Bool -> f (Maybe Bool))
-> UpdateCondition -> f UpdateCondition
updateCondition_exists = (UpdateCondition -> Maybe Bool)
-> (UpdateCondition -> Maybe Bool -> UpdateCondition)
-> Lens UpdateCondition UpdateCondition (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateCondition' {Maybe Bool
exists :: Maybe Bool
$sel:exists:UpdateCondition' :: UpdateCondition -> Maybe Bool
exists} -> Maybe Bool
exists) (\s :: UpdateCondition
s@UpdateCondition' {} Maybe Bool
a -> UpdateCondition
s {$sel:exists:UpdateCondition' :: Maybe Bool
exists = Maybe Bool
a} :: UpdateCondition)

-- | The value of an attribute. This value can only be specified when the
-- @Exists@ parameter is equal to @true@.
updateCondition_value :: Lens.Lens' UpdateCondition (Prelude.Maybe Prelude.Text)
updateCondition_value :: (Maybe Text -> f (Maybe Text))
-> UpdateCondition -> f UpdateCondition
updateCondition_value = (UpdateCondition -> Maybe Text)
-> (UpdateCondition -> Maybe Text -> UpdateCondition)
-> Lens UpdateCondition UpdateCondition (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateCondition' {Maybe Text
value :: Maybe Text
$sel:value:UpdateCondition' :: UpdateCondition -> Maybe Text
value} -> Maybe Text
value) (\s :: UpdateCondition
s@UpdateCondition' {} Maybe Text
a -> UpdateCondition
s {$sel:value:UpdateCondition' :: Maybe Text
value = Maybe Text
a} :: UpdateCondition)

-- | The name of the attribute involved in the condition.
updateCondition_name :: Lens.Lens' UpdateCondition (Prelude.Maybe Prelude.Text)
updateCondition_name :: (Maybe Text -> f (Maybe Text))
-> UpdateCondition -> f UpdateCondition
updateCondition_name = (UpdateCondition -> Maybe Text)
-> (UpdateCondition -> Maybe Text -> UpdateCondition)
-> Lens UpdateCondition UpdateCondition (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateCondition' {Maybe Text
name :: Maybe Text
$sel:name:UpdateCondition' :: UpdateCondition -> Maybe Text
name} -> Maybe Text
name) (\s :: UpdateCondition
s@UpdateCondition' {} Maybe Text
a -> UpdateCondition
s {$sel:name:UpdateCondition' :: Maybe Text
name = Maybe Text
a} :: UpdateCondition)

instance Prelude.Hashable UpdateCondition

instance Prelude.NFData UpdateCondition

instance Core.ToQuery UpdateCondition where
  toQuery :: UpdateCondition -> QueryString
toQuery UpdateCondition' {Maybe Bool
Maybe Text
name :: Maybe Text
value :: Maybe Text
exists :: Maybe Bool
$sel:name:UpdateCondition' :: UpdateCondition -> Maybe Text
$sel:value:UpdateCondition' :: UpdateCondition -> Maybe Text
$sel:exists:UpdateCondition' :: UpdateCondition -> Maybe Bool
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Exists" ByteString -> Maybe Bool -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Bool
exists,
        ByteString
"Value" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
value,
        ByteString
"Name" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
name
      ]