{-# 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.ChimeSDKMessaging.Types.SearchField
-- 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.ChimeSDKMessaging.Types.SearchField where

import Amazonka.ChimeSDKMessaging.Types.SearchFieldKey
import Amazonka.ChimeSDKMessaging.Types.SearchFieldOperator
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | A @Field@ of the channel that you want to search.
--
-- /See:/ 'newSearchField' smart constructor.
data SearchField = SearchField'
  { -- | An @enum@ value that indicates the key to search the channel on.
    -- @MEMBERS@ allows you to search channels based on memberships. You can
    -- use it with the @EQUALS@ operator to get channels whose memberships are
    -- equal to the specified values, and with the @INCLUDES@ operator to get
    -- channels whose memberships include the specified values.
    SearchField -> SearchFieldKey
key :: SearchFieldKey,
    -- | The values that you want to search for, a list of strings. The values
    -- must be @AppInstanceUserArns@ specified as a list of strings.
    --
    -- This operation isn\'t supported for @AppInstanceUsers@ with large number
    -- of memberships.
    SearchField -> NonEmpty Text
values :: Prelude.NonEmpty Prelude.Text,
    -- | The operator used to compare field values, currently @EQUALS@ or
    -- @INCLUDES@. Use the @EQUALS@ operator to find channels whose memberships
    -- equal the specified values. Use the @INCLUDES@ operator to find channels
    -- whose memberships include the specified values.
    SearchField -> SearchFieldOperator
operator :: SearchFieldOperator
  }
  deriving (SearchField -> SearchField -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SearchField -> SearchField -> Bool
$c/= :: SearchField -> SearchField -> Bool
== :: SearchField -> SearchField -> Bool
$c== :: SearchField -> SearchField -> Bool
Prelude.Eq, ReadPrec [SearchField]
ReadPrec SearchField
Int -> ReadS SearchField
ReadS [SearchField]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SearchField]
$creadListPrec :: ReadPrec [SearchField]
readPrec :: ReadPrec SearchField
$creadPrec :: ReadPrec SearchField
readList :: ReadS [SearchField]
$creadList :: ReadS [SearchField]
readsPrec :: Int -> ReadS SearchField
$creadsPrec :: Int -> ReadS SearchField
Prelude.Read, Int -> SearchField -> ShowS
[SearchField] -> ShowS
SearchField -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SearchField] -> ShowS
$cshowList :: [SearchField] -> ShowS
show :: SearchField -> String
$cshow :: SearchField -> String
showsPrec :: Int -> SearchField -> ShowS
$cshowsPrec :: Int -> SearchField -> ShowS
Prelude.Show, forall x. Rep SearchField x -> SearchField
forall x. SearchField -> Rep SearchField x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SearchField x -> SearchField
$cfrom :: forall x. SearchField -> Rep SearchField x
Prelude.Generic)

-- |
-- Create a value of 'SearchField' 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', 'searchField_key' - An @enum@ value that indicates the key to search the channel on.
-- @MEMBERS@ allows you to search channels based on memberships. You can
-- use it with the @EQUALS@ operator to get channels whose memberships are
-- equal to the specified values, and with the @INCLUDES@ operator to get
-- channels whose memberships include the specified values.
--
-- 'values', 'searchField_values' - The values that you want to search for, a list of strings. The values
-- must be @AppInstanceUserArns@ specified as a list of strings.
--
-- This operation isn\'t supported for @AppInstanceUsers@ with large number
-- of memberships.
--
-- 'operator', 'searchField_operator' - The operator used to compare field values, currently @EQUALS@ or
-- @INCLUDES@. Use the @EQUALS@ operator to find channels whose memberships
-- equal the specified values. Use the @INCLUDES@ operator to find channels
-- whose memberships include the specified values.
newSearchField ::
  -- | 'key'
  SearchFieldKey ->
  -- | 'values'
  Prelude.NonEmpty Prelude.Text ->
  -- | 'operator'
  SearchFieldOperator ->
  SearchField
newSearchField :: SearchFieldKey
-> NonEmpty Text -> SearchFieldOperator -> SearchField
newSearchField SearchFieldKey
pKey_ NonEmpty Text
pValues_ SearchFieldOperator
pOperator_ =
  SearchField'
    { $sel:key:SearchField' :: SearchFieldKey
key = SearchFieldKey
pKey_,
      $sel:values:SearchField' :: 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:SearchField' :: SearchFieldOperator
operator = SearchFieldOperator
pOperator_
    }

-- | An @enum@ value that indicates the key to search the channel on.
-- @MEMBERS@ allows you to search channels based on memberships. You can
-- use it with the @EQUALS@ operator to get channels whose memberships are
-- equal to the specified values, and with the @INCLUDES@ operator to get
-- channels whose memberships include the specified values.
searchField_key :: Lens.Lens' SearchField SearchFieldKey
searchField_key :: Lens' SearchField SearchFieldKey
searchField_key = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchField' {SearchFieldKey
key :: SearchFieldKey
$sel:key:SearchField' :: SearchField -> SearchFieldKey
key} -> SearchFieldKey
key) (\s :: SearchField
s@SearchField' {} SearchFieldKey
a -> SearchField
s {$sel:key:SearchField' :: SearchFieldKey
key = SearchFieldKey
a} :: SearchField)

-- | The values that you want to search for, a list of strings. The values
-- must be @AppInstanceUserArns@ specified as a list of strings.
--
-- This operation isn\'t supported for @AppInstanceUsers@ with large number
-- of memberships.
searchField_values :: Lens.Lens' SearchField (Prelude.NonEmpty Prelude.Text)
searchField_values :: Lens' SearchField (NonEmpty Text)
searchField_values = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchField' {NonEmpty Text
values :: NonEmpty Text
$sel:values:SearchField' :: SearchField -> NonEmpty Text
values} -> NonEmpty Text
values) (\s :: SearchField
s@SearchField' {} NonEmpty Text
a -> SearchField
s {$sel:values:SearchField' :: NonEmpty Text
values = NonEmpty Text
a} :: SearchField) 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 used to compare field values, currently @EQUALS@ or
-- @INCLUDES@. Use the @EQUALS@ operator to find channels whose memberships
-- equal the specified values. Use the @INCLUDES@ operator to find channels
-- whose memberships include the specified values.
searchField_operator :: Lens.Lens' SearchField SearchFieldOperator
searchField_operator :: Lens' SearchField SearchFieldOperator
searchField_operator = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchField' {SearchFieldOperator
operator :: SearchFieldOperator
$sel:operator:SearchField' :: SearchField -> SearchFieldOperator
operator} -> SearchFieldOperator
operator) (\s :: SearchField
s@SearchField' {} SearchFieldOperator
a -> SearchField
s {$sel:operator:SearchField' :: SearchFieldOperator
operator = SearchFieldOperator
a} :: SearchField)

instance Prelude.Hashable SearchField where
  hashWithSalt :: Int -> SearchField -> Int
hashWithSalt Int
_salt SearchField' {NonEmpty Text
SearchFieldKey
SearchFieldOperator
operator :: SearchFieldOperator
values :: NonEmpty Text
key :: SearchFieldKey
$sel:operator:SearchField' :: SearchField -> SearchFieldOperator
$sel:values:SearchField' :: SearchField -> NonEmpty Text
$sel:key:SearchField' :: SearchField -> SearchFieldKey
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` SearchFieldKey
key
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
values
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` SearchFieldOperator
operator

instance Prelude.NFData SearchField where
  rnf :: SearchField -> ()
rnf SearchField' {NonEmpty Text
SearchFieldKey
SearchFieldOperator
operator :: SearchFieldOperator
values :: NonEmpty Text
key :: SearchFieldKey
$sel:operator:SearchField' :: SearchField -> SearchFieldOperator
$sel:values:SearchField' :: SearchField -> NonEmpty Text
$sel:key:SearchField' :: SearchField -> SearchFieldKey
..} =
    forall a. NFData a => a -> ()
Prelude.rnf SearchFieldKey
key
      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 SearchFieldOperator
operator

instance Data.ToJSON SearchField where
  toJSON :: SearchField -> Value
toJSON SearchField' {NonEmpty Text
SearchFieldKey
SearchFieldOperator
operator :: SearchFieldOperator
values :: NonEmpty Text
key :: SearchFieldKey
$sel:operator:SearchField' :: SearchField -> SearchFieldOperator
$sel:values:SearchField' :: SearchField -> NonEmpty Text
$sel:key:SearchField' :: SearchField -> SearchFieldKey
..} =
    [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..= SearchFieldKey
key),
            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..= SearchFieldOperator
operator)
          ]
      )