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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(ConditionExpression -> ConditionExpression -> Bool)
-> (ConditionExpression -> ConditionExpression -> Bool)
-> Eq ConditionExpression
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]
(Int -> ReadS ConditionExpression)
-> ReadS [ConditionExpression]
-> ReadPrec ConditionExpression
-> ReadPrec [ConditionExpression]
-> Read 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
(Int -> ConditionExpression -> ShowS)
-> (ConditionExpression -> String)
-> ([ConditionExpression] -> ShowS)
-> Show ConditionExpression
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. ConditionExpression -> Rep ConditionExpression x)
-> (forall x. Rep ConditionExpression x -> ConditionExpression)
-> Generic ConditionExpression
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' :: Maybe Text -> Text -> Text -> ConditionExpression
ConditionExpression'
    { $sel:value:ConditionExpression' :: Maybe Text
value = Maybe Text
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 :: (Maybe Text -> f (Maybe Text))
-> ConditionExpression -> f ConditionExpression
conditionExpression_value = (ConditionExpression -> Maybe Text)
-> (ConditionExpression -> Maybe Text -> ConditionExpression)
-> Lens
     ConditionExpression ConditionExpression (Maybe Text) (Maybe Text)
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 :: (Text -> f Text) -> ConditionExpression -> f ConditionExpression
conditionExpression_condition = (ConditionExpression -> Text)
-> (ConditionExpression -> Text -> ConditionExpression)
-> Lens ConditionExpression ConditionExpression Text Text
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 :: (Text -> f Text) -> ConditionExpression -> f ConditionExpression
conditionExpression_targetColumn = (ConditionExpression -> Text)
-> (ConditionExpression -> Text -> ConditionExpression)
-> Lens ConditionExpression ConditionExpression Text Text
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 Core.FromJSON ConditionExpression where
  parseJSON :: Value -> Parser ConditionExpression
parseJSON =
    String
-> (Object -> Parser ConditionExpression)
-> Value
-> Parser ConditionExpression
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ConditionExpression"
      ( \Object
x ->
          Maybe Text -> Text -> Text -> ConditionExpression
ConditionExpression'
            (Maybe Text -> Text -> Text -> ConditionExpression)
-> Parser (Maybe Text)
-> Parser (Text -> Text -> ConditionExpression)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Value")
            Parser (Text -> Text -> ConditionExpression)
-> Parser Text -> Parser (Text -> ConditionExpression)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Condition")
            Parser (Text -> ConditionExpression)
-> Parser Text -> Parser ConditionExpression
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"TargetColumn")
      )

instance Prelude.Hashable ConditionExpression

instance Prelude.NFData ConditionExpression

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Value" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
value,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Condition" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
condition),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"TargetColumn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
targetColumn)
          ]
      )