{-# 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.SageMaker.Types.SearchExpression
-- 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.SageMaker.Types.SearchExpression where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SageMaker.Types.BooleanOperator
import Amazonka.SageMaker.Types.Filter
import Amazonka.SageMaker.Types.NestedFilters

-- | A multi-expression that searches for the specified resource or resources
-- in a search. All resource objects that satisfy the expression\'s
-- condition are included in the search results. You must specify at least
-- one subexpression, filter, or nested filter. A @SearchExpression@ can
-- contain up to twenty elements.
--
-- A @SearchExpression@ contains the following components:
--
-- -   A list of @Filter@ objects. Each filter defines a simple Boolean
--     expression comprised of a resource property name, Boolean operator,
--     and value.
--
-- -   A list of @NestedFilter@ objects. Each nested filter defines a list
--     of Boolean expressions using a list of resource properties. A nested
--     filter is satisfied if a single object in the list satisfies all
--     Boolean expressions.
--
-- -   A list of @SearchExpression@ objects. A search expression object can
--     be nested in a list of search expression objects.
--
-- -   A Boolean operator: @And@ or @Or@.
--
-- /See:/ 'newSearchExpression' smart constructor.
data SearchExpression = SearchExpression'
  { -- | A list of search expression objects.
    SearchExpression -> Maybe (NonEmpty SearchExpression)
subExpressions :: Prelude.Maybe (Prelude.NonEmpty SearchExpression),
    -- | A Boolean operator used to evaluate the search expression. If you want
    -- every conditional statement in all lists to be satisfied for the entire
    -- search expression to be true, specify @And@. If only a single
    -- conditional statement needs to be true for the entire search expression
    -- to be true, specify @Or@. The default value is @And@.
    SearchExpression -> Maybe BooleanOperator
operator :: Prelude.Maybe BooleanOperator,
    -- | A list of filter objects.
    SearchExpression -> Maybe (NonEmpty Filter)
filters :: Prelude.Maybe (Prelude.NonEmpty Filter),
    -- | A list of nested filter objects.
    SearchExpression -> Maybe (NonEmpty NestedFilters)
nestedFilters :: Prelude.Maybe (Prelude.NonEmpty NestedFilters)
  }
  deriving (SearchExpression -> SearchExpression -> Bool
(SearchExpression -> SearchExpression -> Bool)
-> (SearchExpression -> SearchExpression -> Bool)
-> Eq SearchExpression
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SearchExpression -> SearchExpression -> Bool
$c/= :: SearchExpression -> SearchExpression -> Bool
== :: SearchExpression -> SearchExpression -> Bool
$c== :: SearchExpression -> SearchExpression -> Bool
Prelude.Eq, ReadPrec [SearchExpression]
ReadPrec SearchExpression
Int -> ReadS SearchExpression
ReadS [SearchExpression]
(Int -> ReadS SearchExpression)
-> ReadS [SearchExpression]
-> ReadPrec SearchExpression
-> ReadPrec [SearchExpression]
-> Read SearchExpression
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SearchExpression]
$creadListPrec :: ReadPrec [SearchExpression]
readPrec :: ReadPrec SearchExpression
$creadPrec :: ReadPrec SearchExpression
readList :: ReadS [SearchExpression]
$creadList :: ReadS [SearchExpression]
readsPrec :: Int -> ReadS SearchExpression
$creadsPrec :: Int -> ReadS SearchExpression
Prelude.Read, Int -> SearchExpression -> ShowS
[SearchExpression] -> ShowS
SearchExpression -> String
(Int -> SearchExpression -> ShowS)
-> (SearchExpression -> String)
-> ([SearchExpression] -> ShowS)
-> Show SearchExpression
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SearchExpression] -> ShowS
$cshowList :: [SearchExpression] -> ShowS
show :: SearchExpression -> String
$cshow :: SearchExpression -> String
showsPrec :: Int -> SearchExpression -> ShowS
$cshowsPrec :: Int -> SearchExpression -> ShowS
Prelude.Show, (forall x. SearchExpression -> Rep SearchExpression x)
-> (forall x. Rep SearchExpression x -> SearchExpression)
-> Generic SearchExpression
forall x. Rep SearchExpression x -> SearchExpression
forall x. SearchExpression -> Rep SearchExpression x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SearchExpression x -> SearchExpression
$cfrom :: forall x. SearchExpression -> Rep SearchExpression x
Prelude.Generic)

-- |
-- Create a value of 'SearchExpression' 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:
--
-- 'subExpressions', 'searchExpression_subExpressions' - A list of search expression objects.
--
-- 'operator', 'searchExpression_operator' - A Boolean operator used to evaluate the search expression. If you want
-- every conditional statement in all lists to be satisfied for the entire
-- search expression to be true, specify @And@. If only a single
-- conditional statement needs to be true for the entire search expression
-- to be true, specify @Or@. The default value is @And@.
--
-- 'filters', 'searchExpression_filters' - A list of filter objects.
--
-- 'nestedFilters', 'searchExpression_nestedFilters' - A list of nested filter objects.
newSearchExpression ::
  SearchExpression
newSearchExpression :: SearchExpression
newSearchExpression =
  SearchExpression' :: Maybe (NonEmpty SearchExpression)
-> Maybe BooleanOperator
-> Maybe (NonEmpty Filter)
-> Maybe (NonEmpty NestedFilters)
-> SearchExpression
SearchExpression'
    { $sel:subExpressions:SearchExpression' :: Maybe (NonEmpty SearchExpression)
subExpressions = Maybe (NonEmpty SearchExpression)
forall a. Maybe a
Prelude.Nothing,
      $sel:operator:SearchExpression' :: Maybe BooleanOperator
operator = Maybe BooleanOperator
forall a. Maybe a
Prelude.Nothing,
      $sel:filters:SearchExpression' :: Maybe (NonEmpty Filter)
filters = Maybe (NonEmpty Filter)
forall a. Maybe a
Prelude.Nothing,
      $sel:nestedFilters:SearchExpression' :: Maybe (NonEmpty NestedFilters)
nestedFilters = Maybe (NonEmpty NestedFilters)
forall a. Maybe a
Prelude.Nothing
    }

-- | A list of search expression objects.
searchExpression_subExpressions :: Lens.Lens' SearchExpression (Prelude.Maybe (Prelude.NonEmpty SearchExpression))
searchExpression_subExpressions :: (Maybe (NonEmpty SearchExpression)
 -> f (Maybe (NonEmpty SearchExpression)))
-> SearchExpression -> f SearchExpression
searchExpression_subExpressions = (SearchExpression -> Maybe (NonEmpty SearchExpression))
-> (SearchExpression
    -> Maybe (NonEmpty SearchExpression) -> SearchExpression)
-> Lens
     SearchExpression
     SearchExpression
     (Maybe (NonEmpty SearchExpression))
     (Maybe (NonEmpty SearchExpression))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchExpression' {Maybe (NonEmpty SearchExpression)
subExpressions :: Maybe (NonEmpty SearchExpression)
$sel:subExpressions:SearchExpression' :: SearchExpression -> Maybe (NonEmpty SearchExpression)
subExpressions} -> Maybe (NonEmpty SearchExpression)
subExpressions) (\s :: SearchExpression
s@SearchExpression' {} Maybe (NonEmpty SearchExpression)
a -> SearchExpression
s {$sel:subExpressions:SearchExpression' :: Maybe (NonEmpty SearchExpression)
subExpressions = Maybe (NonEmpty SearchExpression)
a} :: SearchExpression) ((Maybe (NonEmpty SearchExpression)
  -> f (Maybe (NonEmpty SearchExpression)))
 -> SearchExpression -> f SearchExpression)
-> ((Maybe (NonEmpty SearchExpression)
     -> f (Maybe (NonEmpty SearchExpression)))
    -> Maybe (NonEmpty SearchExpression)
    -> f (Maybe (NonEmpty SearchExpression)))
-> (Maybe (NonEmpty SearchExpression)
    -> f (Maybe (NonEmpty SearchExpression)))
-> SearchExpression
-> f SearchExpression
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty SearchExpression)
  (NonEmpty SearchExpression)
  (NonEmpty SearchExpression)
  (NonEmpty SearchExpression)
-> Iso
     (Maybe (NonEmpty SearchExpression))
     (Maybe (NonEmpty SearchExpression))
     (Maybe (NonEmpty SearchExpression))
     (Maybe (NonEmpty SearchExpression))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (NonEmpty SearchExpression)
  (NonEmpty SearchExpression)
  (NonEmpty SearchExpression)
  (NonEmpty SearchExpression)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A Boolean operator used to evaluate the search expression. If you want
-- every conditional statement in all lists to be satisfied for the entire
-- search expression to be true, specify @And@. If only a single
-- conditional statement needs to be true for the entire search expression
-- to be true, specify @Or@. The default value is @And@.
searchExpression_operator :: Lens.Lens' SearchExpression (Prelude.Maybe BooleanOperator)
searchExpression_operator :: (Maybe BooleanOperator -> f (Maybe BooleanOperator))
-> SearchExpression -> f SearchExpression
searchExpression_operator = (SearchExpression -> Maybe BooleanOperator)
-> (SearchExpression -> Maybe BooleanOperator -> SearchExpression)
-> Lens
     SearchExpression
     SearchExpression
     (Maybe BooleanOperator)
     (Maybe BooleanOperator)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchExpression' {Maybe BooleanOperator
operator :: Maybe BooleanOperator
$sel:operator:SearchExpression' :: SearchExpression -> Maybe BooleanOperator
operator} -> Maybe BooleanOperator
operator) (\s :: SearchExpression
s@SearchExpression' {} Maybe BooleanOperator
a -> SearchExpression
s {$sel:operator:SearchExpression' :: Maybe BooleanOperator
operator = Maybe BooleanOperator
a} :: SearchExpression)

-- | A list of filter objects.
searchExpression_filters :: Lens.Lens' SearchExpression (Prelude.Maybe (Prelude.NonEmpty Filter))
searchExpression_filters :: (Maybe (NonEmpty Filter) -> f (Maybe (NonEmpty Filter)))
-> SearchExpression -> f SearchExpression
searchExpression_filters = (SearchExpression -> Maybe (NonEmpty Filter))
-> (SearchExpression
    -> Maybe (NonEmpty Filter) -> SearchExpression)
-> Lens
     SearchExpression
     SearchExpression
     (Maybe (NonEmpty Filter))
     (Maybe (NonEmpty Filter))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchExpression' {Maybe (NonEmpty Filter)
filters :: Maybe (NonEmpty Filter)
$sel:filters:SearchExpression' :: SearchExpression -> Maybe (NonEmpty Filter)
filters} -> Maybe (NonEmpty Filter)
filters) (\s :: SearchExpression
s@SearchExpression' {} Maybe (NonEmpty Filter)
a -> SearchExpression
s {$sel:filters:SearchExpression' :: Maybe (NonEmpty Filter)
filters = Maybe (NonEmpty Filter)
a} :: SearchExpression) ((Maybe (NonEmpty Filter) -> f (Maybe (NonEmpty Filter)))
 -> SearchExpression -> f SearchExpression)
-> ((Maybe (NonEmpty Filter) -> f (Maybe (NonEmpty Filter)))
    -> Maybe (NonEmpty Filter) -> f (Maybe (NonEmpty Filter)))
-> (Maybe (NonEmpty Filter) -> f (Maybe (NonEmpty Filter)))
-> SearchExpression
-> f SearchExpression
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Filter)
  (NonEmpty Filter)
  (NonEmpty Filter)
  (NonEmpty Filter)
-> Iso
     (Maybe (NonEmpty Filter))
     (Maybe (NonEmpty Filter))
     (Maybe (NonEmpty Filter))
     (Maybe (NonEmpty Filter))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (NonEmpty Filter)
  (NonEmpty Filter)
  (NonEmpty Filter)
  (NonEmpty Filter)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A list of nested filter objects.
searchExpression_nestedFilters :: Lens.Lens' SearchExpression (Prelude.Maybe (Prelude.NonEmpty NestedFilters))
searchExpression_nestedFilters :: (Maybe (NonEmpty NestedFilters)
 -> f (Maybe (NonEmpty NestedFilters)))
-> SearchExpression -> f SearchExpression
searchExpression_nestedFilters = (SearchExpression -> Maybe (NonEmpty NestedFilters))
-> (SearchExpression
    -> Maybe (NonEmpty NestedFilters) -> SearchExpression)
-> Lens
     SearchExpression
     SearchExpression
     (Maybe (NonEmpty NestedFilters))
     (Maybe (NonEmpty NestedFilters))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchExpression' {Maybe (NonEmpty NestedFilters)
nestedFilters :: Maybe (NonEmpty NestedFilters)
$sel:nestedFilters:SearchExpression' :: SearchExpression -> Maybe (NonEmpty NestedFilters)
nestedFilters} -> Maybe (NonEmpty NestedFilters)
nestedFilters) (\s :: SearchExpression
s@SearchExpression' {} Maybe (NonEmpty NestedFilters)
a -> SearchExpression
s {$sel:nestedFilters:SearchExpression' :: Maybe (NonEmpty NestedFilters)
nestedFilters = Maybe (NonEmpty NestedFilters)
a} :: SearchExpression) ((Maybe (NonEmpty NestedFilters)
  -> f (Maybe (NonEmpty NestedFilters)))
 -> SearchExpression -> f SearchExpression)
-> ((Maybe (NonEmpty NestedFilters)
     -> f (Maybe (NonEmpty NestedFilters)))
    -> Maybe (NonEmpty NestedFilters)
    -> f (Maybe (NonEmpty NestedFilters)))
-> (Maybe (NonEmpty NestedFilters)
    -> f (Maybe (NonEmpty NestedFilters)))
-> SearchExpression
-> f SearchExpression
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty NestedFilters)
  (NonEmpty NestedFilters)
  (NonEmpty NestedFilters)
  (NonEmpty NestedFilters)
-> Iso
     (Maybe (NonEmpty NestedFilters))
     (Maybe (NonEmpty NestedFilters))
     (Maybe (NonEmpty NestedFilters))
     (Maybe (NonEmpty NestedFilters))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (NonEmpty NestedFilters)
  (NonEmpty NestedFilters)
  (NonEmpty NestedFilters)
  (NonEmpty NestedFilters)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.Hashable SearchExpression

instance Prelude.NFData SearchExpression

instance Core.ToJSON SearchExpression where
  toJSON :: SearchExpression -> Value
toJSON SearchExpression' {Maybe (NonEmpty Filter)
Maybe (NonEmpty NestedFilters)
Maybe (NonEmpty SearchExpression)
Maybe BooleanOperator
nestedFilters :: Maybe (NonEmpty NestedFilters)
filters :: Maybe (NonEmpty Filter)
operator :: Maybe BooleanOperator
subExpressions :: Maybe (NonEmpty SearchExpression)
$sel:nestedFilters:SearchExpression' :: SearchExpression -> Maybe (NonEmpty NestedFilters)
$sel:filters:SearchExpression' :: SearchExpression -> Maybe (NonEmpty Filter)
$sel:operator:SearchExpression' :: SearchExpression -> Maybe BooleanOperator
$sel:subExpressions:SearchExpression' :: SearchExpression -> Maybe (NonEmpty SearchExpression)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"SubExpressions" Text -> NonEmpty SearchExpression -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (NonEmpty SearchExpression -> Pair)
-> Maybe (NonEmpty SearchExpression) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty SearchExpression)
subExpressions,
            (Text
"Operator" Text -> BooleanOperator -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (BooleanOperator -> Pair) -> Maybe BooleanOperator -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe BooleanOperator
operator,
            (Text
"Filters" Text -> NonEmpty Filter -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NonEmpty Filter -> Pair) -> Maybe (NonEmpty Filter) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Filter)
filters,
            (Text
"NestedFilters" Text -> NonEmpty NestedFilters -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NonEmpty NestedFilters -> Pair)
-> Maybe (NonEmpty NestedFilters) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty NestedFilters)
nestedFilters
          ]
      )