{-# 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.DataBrew.Types.ConditionExpression
-- 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.DataBrew.Types.ConditionExpression where

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

-- | Represents an individual condition that evaluates to true or false.
--
-- Conditions are used with recipe actions. The action is only performed
-- for column values where the condition evaluates to true.
--
-- If a recipe requires more than one condition, then the recipe must
-- specify multiple @ConditionExpression@ elements. Each condition is
-- applied to the rows in a dataset first, before the recipe action is
-- performed.
--
-- /See:/ 'newConditionExpression' smart constructor.
data ConditionExpression = ConditionExpression'
  { -- | A value that the condition must evaluate to for the condition to
    -- succeed.
    ConditionExpression -> Maybe Text
value :: Prelude.Maybe Prelude.Text,
    -- | A specific condition to apply to a recipe action. For more information,
    -- see
    -- <https://docs.aws.amazon.com/databrew/latest/dg/recipes.html#recipes.structure Recipe structure>
    -- in the /Glue DataBrew Developer Guide/.
    ConditionExpression -> Text
condition :: Prelude.Text,
    -- | A column to apply this condition to.
    ConditionExpression -> Text
targetColumn :: Prelude.Text
  }
  deriving (ConditionExpression -> ConditionExpression -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConditionExpression -> ConditionExpression -> Bool
$c/= :: ConditionExpression -> ConditionExpression -> Bool
== :: ConditionExpression -> ConditionExpression -> Bool
$c== :: ConditionExpression -> ConditionExpression -> Bool
Prelude.Eq, ReadPrec [ConditionExpression]
ReadPrec ConditionExpression
Int -> ReadS ConditionExpression
ReadS [ConditionExpression]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ConditionExpression]
$creadListPrec :: ReadPrec [ConditionExpression]
readPrec :: ReadPrec ConditionExpression
$creadPrec :: ReadPrec ConditionExpression
readList :: ReadS [ConditionExpression]
$creadList :: ReadS [ConditionExpression]
readsPrec :: Int -> ReadS ConditionExpression
$creadsPrec :: Int -> ReadS ConditionExpression
Prelude.Read, Int -> ConditionExpression -> ShowS
[ConditionExpression] -> ShowS
ConditionExpression -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConditionExpression] -> ShowS
$cshowList :: [ConditionExpression] -> ShowS
show :: ConditionExpression -> String
$cshow :: ConditionExpression -> String
showsPrec :: Int -> ConditionExpression -> ShowS
$cshowsPrec :: Int -> ConditionExpression -> ShowS
Prelude.Show, forall x. Rep ConditionExpression x -> ConditionExpression
forall x. ConditionExpression -> Rep ConditionExpression x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ConditionExpression x -> ConditionExpression
$cfrom :: forall x. ConditionExpression -> Rep ConditionExpression x
Prelude.Generic)

-- |
-- Create a value of 'ConditionExpression' 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:
--
-- 'value', 'conditionExpression_value' - A value that the condition must evaluate to for the condition to
-- succeed.
--
-- 'condition', 'conditionExpression_condition' - A specific condition to apply to a recipe action. For more information,
-- see
-- <https://docs.aws.amazon.com/databrew/latest/dg/recipes.html#recipes.structure Recipe structure>
-- in the /Glue DataBrew Developer Guide/.
--
-- 'targetColumn', 'conditionExpression_targetColumn' - A column to apply this condition to.
newConditionExpression ::
  -- | 'condition'
  Prelude.Text ->
  -- | 'targetColumn'
  Prelude.Text ->
  ConditionExpression
newConditionExpression :: Text -> Text -> ConditionExpression
newConditionExpression Text
pCondition_ Text
pTargetColumn_ =
  ConditionExpression'
    { $sel:value:ConditionExpression' :: Maybe Text
value = forall a. Maybe a
Prelude.Nothing,
      $sel:condition:ConditionExpression' :: Text
condition = Text
pCondition_,
      $sel:targetColumn:ConditionExpression' :: Text
targetColumn = Text
pTargetColumn_
    }

-- | A value that the condition must evaluate to for the condition to
-- succeed.
conditionExpression_value :: Lens.Lens' ConditionExpression (Prelude.Maybe Prelude.Text)
conditionExpression_value :: Lens' ConditionExpression (Maybe Text)
conditionExpression_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConditionExpression' {Maybe Text
value :: Maybe Text
$sel:value:ConditionExpression' :: ConditionExpression -> Maybe Text
value} -> Maybe Text
value) (\s :: ConditionExpression
s@ConditionExpression' {} Maybe Text
a -> ConditionExpression
s {$sel:value:ConditionExpression' :: Maybe Text
value = Maybe Text
a} :: ConditionExpression)

-- | A specific condition to apply to a recipe action. For more information,
-- see
-- <https://docs.aws.amazon.com/databrew/latest/dg/recipes.html#recipes.structure Recipe structure>
-- in the /Glue DataBrew Developer Guide/.
conditionExpression_condition :: Lens.Lens' ConditionExpression Prelude.Text
conditionExpression_condition :: Lens' ConditionExpression Text
conditionExpression_condition = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConditionExpression' {Text
condition :: Text
$sel:condition:ConditionExpression' :: ConditionExpression -> Text
condition} -> Text
condition) (\s :: ConditionExpression
s@ConditionExpression' {} Text
a -> ConditionExpression
s {$sel:condition:ConditionExpression' :: Text
condition = Text
a} :: ConditionExpression)

-- | A column to apply this condition to.
conditionExpression_targetColumn :: Lens.Lens' ConditionExpression Prelude.Text
conditionExpression_targetColumn :: Lens' ConditionExpression Text
conditionExpression_targetColumn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConditionExpression' {Text
targetColumn :: Text
$sel:targetColumn:ConditionExpression' :: ConditionExpression -> Text
targetColumn} -> Text
targetColumn) (\s :: ConditionExpression
s@ConditionExpression' {} Text
a -> ConditionExpression
s {$sel:targetColumn:ConditionExpression' :: Text
targetColumn = Text
a} :: ConditionExpression)

instance Data.FromJSON ConditionExpression where
  parseJSON :: Value -> Parser ConditionExpression
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ConditionExpression"
      ( \Object
x ->
          Maybe Text -> Text -> Text -> ConditionExpression
ConditionExpression'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Value")
            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
"Condition")
            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
"TargetColumn")
      )

instance Prelude.Hashable ConditionExpression where
  hashWithSalt :: Int -> ConditionExpression -> Int
hashWithSalt Int
_salt ConditionExpression' {Maybe Text
Text
targetColumn :: Text
condition :: Text
value :: Maybe Text
$sel:targetColumn:ConditionExpression' :: ConditionExpression -> Text
$sel:condition:ConditionExpression' :: ConditionExpression -> Text
$sel:value:ConditionExpression' :: ConditionExpression -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
value
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
condition
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
targetColumn

instance Prelude.NFData ConditionExpression where
  rnf :: ConditionExpression -> ()
rnf ConditionExpression' {Maybe Text
Text
targetColumn :: Text
condition :: Text
value :: Maybe Text
$sel:targetColumn:ConditionExpression' :: ConditionExpression -> Text
$sel:condition:ConditionExpression' :: ConditionExpression -> Text
$sel:value:ConditionExpression' :: ConditionExpression -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
value
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
condition
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
targetColumn

instance Data.ToJSON ConditionExpression where
  toJSON :: ConditionExpression -> Value
toJSON ConditionExpression' {Maybe Text
Text
targetColumn :: Text
condition :: Text
value :: Maybe Text
$sel:targetColumn:ConditionExpression' :: ConditionExpression -> Text
$sel:condition:ConditionExpression' :: ConditionExpression -> Text
$sel:value:ConditionExpression' :: ConditionExpression -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
value,
            forall a. a -> Maybe a
Prelude.Just (Key
"Condition" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
condition),
            forall a. a -> Maybe a
Prelude.Just (Key
"TargetColumn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
targetColumn)
          ]
      )