{-# 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.FilterExpression
-- 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.FilterExpression 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 a structure for defining parameter conditions. Supported
-- conditions are described here:
-- <https://docs.aws.amazon.com/databrew/latest/dg/datasets.multiple-files.html#conditions.for.dynamic.datasets Supported conditions for dynamic datasets>
-- in the /Glue DataBrew Developer Guide/.
--
-- /See:/ 'newFilterExpression' smart constructor.
data FilterExpression = FilterExpression'
  { -- | The expression which includes condition names followed by substitution
    -- variables, possibly grouped and combined with other conditions. For
    -- example, \"(starts_with :prefix1 or starts_with :prefix2) and (ends_with
    -- :suffix1 or ends_with :suffix2)\". Substitution variables should start
    -- with \':\' symbol.
    FilterExpression -> Text
expression :: Prelude.Text,
    -- | The map of substitution variable names to their values used in this
    -- filter expression.
    FilterExpression -> HashMap Text Text
valuesMap :: Prelude.HashMap Prelude.Text Prelude.Text
  }
  deriving (FilterExpression -> FilterExpression -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FilterExpression -> FilterExpression -> Bool
$c/= :: FilterExpression -> FilterExpression -> Bool
== :: FilterExpression -> FilterExpression -> Bool
$c== :: FilterExpression -> FilterExpression -> Bool
Prelude.Eq, ReadPrec [FilterExpression]
ReadPrec FilterExpression
Int -> ReadS FilterExpression
ReadS [FilterExpression]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FilterExpression]
$creadListPrec :: ReadPrec [FilterExpression]
readPrec :: ReadPrec FilterExpression
$creadPrec :: ReadPrec FilterExpression
readList :: ReadS [FilterExpression]
$creadList :: ReadS [FilterExpression]
readsPrec :: Int -> ReadS FilterExpression
$creadsPrec :: Int -> ReadS FilterExpression
Prelude.Read, Int -> FilterExpression -> ShowS
[FilterExpression] -> ShowS
FilterExpression -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FilterExpression] -> ShowS
$cshowList :: [FilterExpression] -> ShowS
show :: FilterExpression -> String
$cshow :: FilterExpression -> String
showsPrec :: Int -> FilterExpression -> ShowS
$cshowsPrec :: Int -> FilterExpression -> ShowS
Prelude.Show, forall x. Rep FilterExpression x -> FilterExpression
forall x. FilterExpression -> Rep FilterExpression x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FilterExpression x -> FilterExpression
$cfrom :: forall x. FilterExpression -> Rep FilterExpression x
Prelude.Generic)

-- |
-- Create a value of 'FilterExpression' 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:
--
-- 'expression', 'filterExpression_expression' - The expression which includes condition names followed by substitution
-- variables, possibly grouped and combined with other conditions. For
-- example, \"(starts_with :prefix1 or starts_with :prefix2) and (ends_with
-- :suffix1 or ends_with :suffix2)\". Substitution variables should start
-- with \':\' symbol.
--
-- 'valuesMap', 'filterExpression_valuesMap' - The map of substitution variable names to their values used in this
-- filter expression.
newFilterExpression ::
  -- | 'expression'
  Prelude.Text ->
  FilterExpression
newFilterExpression :: Text -> FilterExpression
newFilterExpression Text
pExpression_ =
  FilterExpression'
    { $sel:expression:FilterExpression' :: Text
expression = Text
pExpression_,
      $sel:valuesMap:FilterExpression' :: HashMap Text Text
valuesMap = forall a. Monoid a => a
Prelude.mempty
    }

-- | The expression which includes condition names followed by substitution
-- variables, possibly grouped and combined with other conditions. For
-- example, \"(starts_with :prefix1 or starts_with :prefix2) and (ends_with
-- :suffix1 or ends_with :suffix2)\". Substitution variables should start
-- with \':\' symbol.
filterExpression_expression :: Lens.Lens' FilterExpression Prelude.Text
filterExpression_expression :: Lens' FilterExpression Text
filterExpression_expression = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FilterExpression' {Text
expression :: Text
$sel:expression:FilterExpression' :: FilterExpression -> Text
expression} -> Text
expression) (\s :: FilterExpression
s@FilterExpression' {} Text
a -> FilterExpression
s {$sel:expression:FilterExpression' :: Text
expression = Text
a} :: FilterExpression)

-- | The map of substitution variable names to their values used in this
-- filter expression.
filterExpression_valuesMap :: Lens.Lens' FilterExpression (Prelude.HashMap Prelude.Text Prelude.Text)
filterExpression_valuesMap :: Lens' FilterExpression (HashMap Text Text)
filterExpression_valuesMap = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FilterExpression' {HashMap Text Text
valuesMap :: HashMap Text Text
$sel:valuesMap:FilterExpression' :: FilterExpression -> HashMap Text Text
valuesMap} -> HashMap Text Text
valuesMap) (\s :: FilterExpression
s@FilterExpression' {} HashMap Text Text
a -> FilterExpression
s {$sel:valuesMap:FilterExpression' :: HashMap Text Text
valuesMap = HashMap Text Text
a} :: FilterExpression) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON FilterExpression where
  parseJSON :: Value -> Parser FilterExpression
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"FilterExpression"
      ( \Object
x ->
          Text -> HashMap Text Text -> FilterExpression
FilterExpression'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Expression")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"ValuesMap" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable FilterExpression where
  hashWithSalt :: Int -> FilterExpression -> Int
hashWithSalt Int
_salt FilterExpression' {Text
HashMap Text Text
valuesMap :: HashMap Text Text
expression :: Text
$sel:valuesMap:FilterExpression' :: FilterExpression -> HashMap Text Text
$sel:expression:FilterExpression' :: FilterExpression -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
expression
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` HashMap Text Text
valuesMap

instance Prelude.NFData FilterExpression where
  rnf :: FilterExpression -> ()
rnf FilterExpression' {Text
HashMap Text Text
valuesMap :: HashMap Text Text
expression :: Text
$sel:valuesMap:FilterExpression' :: FilterExpression -> HashMap Text Text
$sel:expression:FilterExpression' :: FilterExpression -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
expression
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf HashMap Text Text
valuesMap

instance Data.ToJSON FilterExpression where
  toJSON :: FilterExpression -> Value
toJSON FilterExpression' {Text
HashMap Text Text
valuesMap :: HashMap Text Text
expression :: Text
$sel:valuesMap:FilterExpression' :: FilterExpression -> HashMap Text Text
$sel:expression:FilterExpression' :: FilterExpression -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Expression" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
expression),
            forall a. a -> Maybe a
Prelude.Just (Key
"ValuesMap" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= HashMap Text Text
valuesMap)
          ]
      )