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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Forecast.Types.FilterConditionString
import qualified Amazonka.Prelude as Prelude

-- | Describes a filter for choosing a subset of objects. Each filter
-- consists of a condition and a match statement. The condition is either
-- @IS@ or @IS_NOT@, which specifies whether to include or exclude the
-- objects that match the statement, respectively. The match statement
-- consists of a key and a value.
--
-- /See:/ 'newFilter' smart constructor.
data Filter = Filter'
  { -- | The name of the parameter to filter on.
    Filter -> Text
key :: Prelude.Text,
    -- | The value to match.
    Filter -> Text
value :: Prelude.Text,
    -- | The condition to apply. To include the objects that match the statement,
    -- specify @IS@. To exclude matching objects, specify @IS_NOT@.
    Filter -> FilterConditionString
condition :: FilterConditionString
  }
  deriving (Filter -> Filter -> Bool
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]
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
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. 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:
--
-- 'key', 'filter_key' - The name of the parameter to filter on.
--
-- 'value', 'filter_value' - The value to match.
--
-- 'condition', 'filter_condition' - The condition to apply. To include the objects that match the statement,
-- specify @IS@. To exclude matching objects, specify @IS_NOT@.
newFilter ::
  -- | 'key'
  Prelude.Text ->
  -- | 'value'
  Prelude.Text ->
  -- | 'condition'
  FilterConditionString ->
  Filter
newFilter :: Text -> Text -> FilterConditionString -> Filter
newFilter Text
pKey_ Text
pValue_ FilterConditionString
pCondition_ =
  Filter'
    { $sel:key:Filter' :: Text
key = Text
pKey_,
      $sel:value:Filter' :: Text
value = Text
pValue_,
      $sel:condition:Filter' :: FilterConditionString
condition = FilterConditionString
pCondition_
    }

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

-- | The value to match.
filter_value :: Lens.Lens' Filter Prelude.Text
filter_value :: Lens' Filter Text
filter_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Filter' {Text
value :: Text
$sel:value:Filter' :: Filter -> Text
value} -> Text
value) (\s :: Filter
s@Filter' {} Text
a -> Filter
s {$sel:value:Filter' :: Text
value = Text
a} :: Filter)

-- | The condition to apply. To include the objects that match the statement,
-- specify @IS@. To exclude matching objects, specify @IS_NOT@.
filter_condition :: Lens.Lens' Filter FilterConditionString
filter_condition :: Lens' Filter FilterConditionString
filter_condition = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Filter' {FilterConditionString
condition :: FilterConditionString
$sel:condition:Filter' :: Filter -> FilterConditionString
condition} -> FilterConditionString
condition) (\s :: Filter
s@Filter' {} FilterConditionString
a -> Filter
s {$sel:condition:Filter' :: FilterConditionString
condition = FilterConditionString
a} :: Filter)

instance Prelude.Hashable Filter where
  hashWithSalt :: Int -> Filter -> Int
hashWithSalt Int
_salt Filter' {Text
FilterConditionString
condition :: FilterConditionString
value :: Text
key :: Text
$sel:condition:Filter' :: Filter -> FilterConditionString
$sel:value:Filter' :: Filter -> Text
$sel:key:Filter' :: Filter -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
key
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
value
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` FilterConditionString
condition

instance Prelude.NFData Filter where
  rnf :: Filter -> ()
rnf Filter' {Text
FilterConditionString
condition :: FilterConditionString
value :: Text
key :: Text
$sel:condition:Filter' :: Filter -> FilterConditionString
$sel:value:Filter' :: Filter -> Text
$sel:key:Filter' :: Filter -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
key
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
value
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf FilterConditionString
condition

instance Data.ToJSON Filter where
  toJSON :: Filter -> Value
toJSON Filter' {Text
FilterConditionString
condition :: FilterConditionString
value :: Text
key :: Text
$sel:condition:Filter' :: Filter -> FilterConditionString
$sel:value:Filter' :: Filter -> Text
$sel:key:Filter' :: Filter -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Key" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
key),
            forall a. a -> Maybe a
Prelude.Just (Key
"Value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
value),
            forall a. a -> Maybe a
Prelude.Just (Key
"Condition" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= FilterConditionString
condition)
          ]
      )