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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(FilterExpression -> FilterExpression -> Bool)
-> (FilterExpression -> FilterExpression -> Bool)
-> Eq FilterExpression
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]
(Int -> ReadS FilterExpression)
-> ReadS [FilterExpression]
-> ReadPrec FilterExpression
-> ReadPrec [FilterExpression]
-> Read 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
(Int -> FilterExpression -> ShowS)
-> (FilterExpression -> String)
-> ([FilterExpression] -> ShowS)
-> Show FilterExpression
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. FilterExpression -> Rep FilterExpression x)
-> (forall x. Rep FilterExpression x -> FilterExpression)
-> Generic FilterExpression
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' :: Text -> HashMap Text Text -> FilterExpression
FilterExpression'
    { $sel:expression:FilterExpression' :: Text
expression = Text
pExpression_,
      $sel:valuesMap:FilterExpression' :: HashMap Text Text
valuesMap = HashMap Text Text
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 :: (Text -> f Text) -> FilterExpression -> f FilterExpression
filterExpression_expression = (FilterExpression -> Text)
-> (FilterExpression -> Text -> FilterExpression)
-> Lens FilterExpression FilterExpression Text Text
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 :: (HashMap Text Text -> f (HashMap Text Text))
-> FilterExpression -> f FilterExpression
filterExpression_valuesMap = (FilterExpression -> HashMap Text Text)
-> (FilterExpression -> HashMap Text Text -> FilterExpression)
-> Lens
     FilterExpression
     FilterExpression
     (HashMap Text Text)
     (HashMap Text Text)
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) ((HashMap Text Text -> f (HashMap Text Text))
 -> FilterExpression -> f FilterExpression)
-> ((HashMap Text Text -> f (HashMap Text Text))
    -> HashMap Text Text -> f (HashMap Text Text))
-> (HashMap Text Text -> f (HashMap Text Text))
-> FilterExpression
-> f FilterExpression
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (HashMap Text Text -> f (HashMap Text Text))
-> HashMap Text Text -> f (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable FilterExpression

instance Prelude.NFData FilterExpression

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Expression" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
expression),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ValuesMap" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HashMap Text Text
valuesMap)
          ]
      )