{-# 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.Discovery.Types.Filter
-- 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.Discovery.Types.Filter where

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

-- | A filter that can use conditional operators.
--
-- For more information about filters, see
-- <https://docs.aws.amazon.com/application-discovery/latest/userguide/discovery-api-queries.html Querying Discovered Configuration Items>
-- in the /AWS Application Discovery Service User Guide/.
--
-- /See:/ 'newFilter' smart constructor.
data Filter = Filter'
  { -- | The name of the filter.
    Filter -> Text
name :: Prelude.Text,
    -- | A string value on which to filter. For example, if you choose the
    -- @destinationServer.osVersion@ filter name, you could specify @Ubuntu@
    -- for the value.
    Filter -> [Text]
values :: [Prelude.Text],
    -- | A conditional operator. The following operators are valid: EQUALS,
    -- NOT_EQUALS, CONTAINS, NOT_CONTAINS. If you specify multiple filters, the
    -- system utilizes all filters as though concatenated by /AND/. If you
    -- specify multiple values for a particular filter, the system
    -- differentiates the values using /OR/. Calling either
    -- /DescribeConfigurations/ or /ListConfigurations/ returns attributes of
    -- matching configuration items.
    Filter -> Text
condition :: Prelude.Text
  }
  deriving (Filter -> Filter -> Bool
(Filter -> Filter -> Bool)
-> (Filter -> Filter -> Bool) -> Eq Filter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Filter -> Filter -> Bool
$c/= :: Filter -> Filter -> Bool
== :: Filter -> Filter -> Bool
$c== :: Filter -> Filter -> Bool
Prelude.Eq, ReadPrec [Filter]
ReadPrec Filter
Int -> ReadS Filter
ReadS [Filter]
(Int -> ReadS Filter)
-> ReadS [Filter]
-> ReadPrec Filter
-> ReadPrec [Filter]
-> Read Filter
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Filter]
$creadListPrec :: ReadPrec [Filter]
readPrec :: ReadPrec Filter
$creadPrec :: ReadPrec Filter
readList :: ReadS [Filter]
$creadList :: ReadS [Filter]
readsPrec :: Int -> ReadS Filter
$creadsPrec :: Int -> ReadS Filter
Prelude.Read, Int -> Filter -> ShowS
[Filter] -> ShowS
Filter -> String
(Int -> Filter -> ShowS)
-> (Filter -> String) -> ([Filter] -> ShowS) -> Show Filter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Filter] -> ShowS
$cshowList :: [Filter] -> ShowS
show :: Filter -> String
$cshow :: Filter -> String
showsPrec :: Int -> Filter -> ShowS
$cshowsPrec :: Int -> Filter -> ShowS
Prelude.Show, (forall x. Filter -> Rep Filter x)
-> (forall x. Rep Filter x -> Filter) -> Generic Filter
forall x. Rep Filter x -> Filter
forall x. Filter -> Rep Filter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Filter x -> Filter
$cfrom :: forall x. Filter -> Rep Filter x
Prelude.Generic)

-- |
-- Create a value of 'Filter' 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:
--
-- 'name', 'filter_name' - The name of the filter.
--
-- 'values', 'filter_values' - A string value on which to filter. For example, if you choose the
-- @destinationServer.osVersion@ filter name, you could specify @Ubuntu@
-- for the value.
--
-- 'condition', 'filter_condition' - A conditional operator. The following operators are valid: EQUALS,
-- NOT_EQUALS, CONTAINS, NOT_CONTAINS. If you specify multiple filters, the
-- system utilizes all filters as though concatenated by /AND/. If you
-- specify multiple values for a particular filter, the system
-- differentiates the values using /OR/. Calling either
-- /DescribeConfigurations/ or /ListConfigurations/ returns attributes of
-- matching configuration items.
newFilter ::
  -- | 'name'
  Prelude.Text ->
  -- | 'condition'
  Prelude.Text ->
  Filter
newFilter :: Text -> Text -> Filter
newFilter Text
pName_ Text
pCondition_ =
  Filter' :: Text -> [Text] -> Text -> Filter
Filter'
    { $sel:name:Filter' :: Text
name = Text
pName_,
      $sel:values:Filter' :: [Text]
values = [Text]
forall a. Monoid a => a
Prelude.mempty,
      $sel:condition:Filter' :: Text
condition = Text
pCondition_
    }

-- | The name of the filter.
filter_name :: Lens.Lens' Filter Prelude.Text
filter_name :: (Text -> f Text) -> Filter -> f Filter
filter_name = (Filter -> Text)
-> (Filter -> Text -> Filter) -> Lens Filter Filter Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Filter' {Text
name :: Text
$sel:name:Filter' :: Filter -> Text
name} -> Text
name) (\s :: Filter
s@Filter' {} Text
a -> Filter
s {$sel:name:Filter' :: Text
name = Text
a} :: Filter)

-- | A string value on which to filter. For example, if you choose the
-- @destinationServer.osVersion@ filter name, you could specify @Ubuntu@
-- for the value.
filter_values :: Lens.Lens' Filter [Prelude.Text]
filter_values :: ([Text] -> f [Text]) -> Filter -> f Filter
filter_values = (Filter -> [Text])
-> (Filter -> [Text] -> Filter) -> Lens Filter Filter [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Filter' {[Text]
values :: [Text]
$sel:values:Filter' :: Filter -> [Text]
values} -> [Text]
values) (\s :: Filter
s@Filter' {} [Text]
a -> Filter
s {$sel:values:Filter' :: [Text]
values = [Text]
a} :: Filter) (([Text] -> f [Text]) -> Filter -> f Filter)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> Filter
-> f Filter
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A conditional operator. The following operators are valid: EQUALS,
-- NOT_EQUALS, CONTAINS, NOT_CONTAINS. If you specify multiple filters, the
-- system utilizes all filters as though concatenated by /AND/. If you
-- specify multiple values for a particular filter, the system
-- differentiates the values using /OR/. Calling either
-- /DescribeConfigurations/ or /ListConfigurations/ returns attributes of
-- matching configuration items.
filter_condition :: Lens.Lens' Filter Prelude.Text
filter_condition :: (Text -> f Text) -> Filter -> f Filter
filter_condition = (Filter -> Text)
-> (Filter -> Text -> Filter) -> Lens Filter Filter Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Filter' {Text
condition :: Text
$sel:condition:Filter' :: Filter -> Text
condition} -> Text
condition) (\s :: Filter
s@Filter' {} Text
a -> Filter
s {$sel:condition:Filter' :: Text
condition = Text
a} :: Filter)

instance Prelude.Hashable Filter

instance Prelude.NFData Filter

instance Core.ToJSON Filter where
  toJSON :: Filter -> Value
toJSON Filter' {[Text]
Text
condition :: Text
values :: [Text]
name :: Text
$sel:condition:Filter' :: Filter -> Text
$sel:values:Filter' :: Filter -> [Text]
$sel:name:Filter' :: Filter -> 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
"name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"values" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
values),
            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)
          ]
      )