{-# 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.LexV2Models.Types.IntentFilter
-- 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.LexV2Models.Types.IntentFilter where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.LexV2Models.Types.IntentFilterName
import Amazonka.LexV2Models.Types.IntentFilterOperator
import qualified Amazonka.Prelude as Prelude

-- | Filters the response from the @ListIntents@ operation.
--
-- /See:/ 'newIntentFilter' smart constructor.
data IntentFilter = IntentFilter'
  { -- | The name of the field to use for the filter.
    IntentFilter -> IntentFilterName
name :: IntentFilterName,
    -- | The value to use for the filter.
    IntentFilter -> NonEmpty Text
values :: Prelude.NonEmpty Prelude.Text,
    -- | The operator to use for the filter. Specify @EQ@ when the @ListIntents@
    -- operation should return only aliases that equal the specified value.
    -- Specify @CO@ when the @ListIntents@ operation should return aliases that
    -- contain the specified value.
    IntentFilter -> IntentFilterOperator
operator :: IntentFilterOperator
  }
  deriving (IntentFilter -> IntentFilter -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IntentFilter -> IntentFilter -> Bool
$c/= :: IntentFilter -> IntentFilter -> Bool
== :: IntentFilter -> IntentFilter -> Bool
$c== :: IntentFilter -> IntentFilter -> Bool
Prelude.Eq, ReadPrec [IntentFilter]
ReadPrec IntentFilter
Int -> ReadS IntentFilter
ReadS [IntentFilter]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IntentFilter]
$creadListPrec :: ReadPrec [IntentFilter]
readPrec :: ReadPrec IntentFilter
$creadPrec :: ReadPrec IntentFilter
readList :: ReadS [IntentFilter]
$creadList :: ReadS [IntentFilter]
readsPrec :: Int -> ReadS IntentFilter
$creadsPrec :: Int -> ReadS IntentFilter
Prelude.Read, Int -> IntentFilter -> ShowS
[IntentFilter] -> ShowS
IntentFilter -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IntentFilter] -> ShowS
$cshowList :: [IntentFilter] -> ShowS
show :: IntentFilter -> String
$cshow :: IntentFilter -> String
showsPrec :: Int -> IntentFilter -> ShowS
$cshowsPrec :: Int -> IntentFilter -> ShowS
Prelude.Show, forall x. Rep IntentFilter x -> IntentFilter
forall x. IntentFilter -> Rep IntentFilter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IntentFilter x -> IntentFilter
$cfrom :: forall x. IntentFilter -> Rep IntentFilter x
Prelude.Generic)

-- |
-- Create a value of 'IntentFilter' 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', 'intentFilter_name' - The name of the field to use for the filter.
--
-- 'values', 'intentFilter_values' - The value to use for the filter.
--
-- 'operator', 'intentFilter_operator' - The operator to use for the filter. Specify @EQ@ when the @ListIntents@
-- operation should return only aliases that equal the specified value.
-- Specify @CO@ when the @ListIntents@ operation should return aliases that
-- contain the specified value.
newIntentFilter ::
  -- | 'name'
  IntentFilterName ->
  -- | 'values'
  Prelude.NonEmpty Prelude.Text ->
  -- | 'operator'
  IntentFilterOperator ->
  IntentFilter
newIntentFilter :: IntentFilterName
-> NonEmpty Text -> IntentFilterOperator -> IntentFilter
newIntentFilter IntentFilterName
pName_ NonEmpty Text
pValues_ IntentFilterOperator
pOperator_ =
  IntentFilter'
    { $sel:name:IntentFilter' :: IntentFilterName
name = IntentFilterName
pName_,
      $sel:values:IntentFilter' :: NonEmpty Text
values = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pValues_,
      $sel:operator:IntentFilter' :: IntentFilterOperator
operator = IntentFilterOperator
pOperator_
    }

-- | The name of the field to use for the filter.
intentFilter_name :: Lens.Lens' IntentFilter IntentFilterName
intentFilter_name :: Lens' IntentFilter IntentFilterName
intentFilter_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IntentFilter' {IntentFilterName
name :: IntentFilterName
$sel:name:IntentFilter' :: IntentFilter -> IntentFilterName
name} -> IntentFilterName
name) (\s :: IntentFilter
s@IntentFilter' {} IntentFilterName
a -> IntentFilter
s {$sel:name:IntentFilter' :: IntentFilterName
name = IntentFilterName
a} :: IntentFilter)

-- | The value to use for the filter.
intentFilter_values :: Lens.Lens' IntentFilter (Prelude.NonEmpty Prelude.Text)
intentFilter_values :: Lens' IntentFilter (NonEmpty Text)
intentFilter_values = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IntentFilter' {NonEmpty Text
values :: NonEmpty Text
$sel:values:IntentFilter' :: IntentFilter -> NonEmpty Text
values} -> NonEmpty Text
values) (\s :: IntentFilter
s@IntentFilter' {} NonEmpty Text
a -> IntentFilter
s {$sel:values:IntentFilter' :: NonEmpty Text
values = NonEmpty Text
a} :: IntentFilter) 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

-- | The operator to use for the filter. Specify @EQ@ when the @ListIntents@
-- operation should return only aliases that equal the specified value.
-- Specify @CO@ when the @ListIntents@ operation should return aliases that
-- contain the specified value.
intentFilter_operator :: Lens.Lens' IntentFilter IntentFilterOperator
intentFilter_operator :: Lens' IntentFilter IntentFilterOperator
intentFilter_operator = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IntentFilter' {IntentFilterOperator
operator :: IntentFilterOperator
$sel:operator:IntentFilter' :: IntentFilter -> IntentFilterOperator
operator} -> IntentFilterOperator
operator) (\s :: IntentFilter
s@IntentFilter' {} IntentFilterOperator
a -> IntentFilter
s {$sel:operator:IntentFilter' :: IntentFilterOperator
operator = IntentFilterOperator
a} :: IntentFilter)

instance Prelude.Hashable IntentFilter where
  hashWithSalt :: Int -> IntentFilter -> Int
hashWithSalt Int
_salt IntentFilter' {NonEmpty Text
IntentFilterName
IntentFilterOperator
operator :: IntentFilterOperator
values :: NonEmpty Text
name :: IntentFilterName
$sel:operator:IntentFilter' :: IntentFilter -> IntentFilterOperator
$sel:values:IntentFilter' :: IntentFilter -> NonEmpty Text
$sel:name:IntentFilter' :: IntentFilter -> IntentFilterName
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` IntentFilterName
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
values
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` IntentFilterOperator
operator

instance Prelude.NFData IntentFilter where
  rnf :: IntentFilter -> ()
rnf IntentFilter' {NonEmpty Text
IntentFilterName
IntentFilterOperator
operator :: IntentFilterOperator
values :: NonEmpty Text
name :: IntentFilterName
$sel:operator:IntentFilter' :: IntentFilter -> IntentFilterOperator
$sel:values:IntentFilter' :: IntentFilter -> NonEmpty Text
$sel:name:IntentFilter' :: IntentFilter -> IntentFilterName
..} =
    forall a. NFData a => a -> ()
Prelude.rnf IntentFilterName
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Text
values
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf IntentFilterOperator
operator

instance Data.ToJSON IntentFilter where
  toJSON :: IntentFilter -> Value
toJSON IntentFilter' {NonEmpty Text
IntentFilterName
IntentFilterOperator
operator :: IntentFilterOperator
values :: NonEmpty Text
name :: IntentFilterName
$sel:operator:IntentFilter' :: IntentFilter -> IntentFilterOperator
$sel:values:IntentFilter' :: IntentFilter -> NonEmpty Text
$sel:name:IntentFilter' :: IntentFilter -> IntentFilterName
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= IntentFilterName
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"values" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
values),
            forall a. a -> Maybe a
Prelude.Just (Key
"operator" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= IntentFilterOperator
operator)
          ]
      )