{-# 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.QuickSight.Types.CategoryFilter
-- 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.QuickSight.Types.CategoryFilter where

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
import Amazonka.QuickSight.Types.CategoryFilterConfiguration
import Amazonka.QuickSight.Types.ColumnIdentifier

-- | A @CategoryFilter@ filters text values.
--
-- For more information, see
-- <https://docs.aws.amazon.com/quicksight/latest/user/add-a-text-filter-data-prep.html Adding text filters>
-- in the /Amazon QuickSight User Guide/.
--
-- /See:/ 'newCategoryFilter' smart constructor.
data CategoryFilter = CategoryFilter'
  { -- | The configuration for a @CategoryFilter@.
    CategoryFilter -> Maybe CategoryFilterConfiguration
configuration :: Prelude.Maybe CategoryFilterConfiguration,
    -- | An identifier that uniquely identifies a filter within a dashboard,
    -- analysis, or template.
    CategoryFilter -> Text
filterId :: Prelude.Text,
    -- | The column that the filter is applied to.
    CategoryFilter -> ColumnIdentifier
column :: ColumnIdentifier
  }
  deriving (CategoryFilter -> CategoryFilter -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CategoryFilter -> CategoryFilter -> Bool
$c/= :: CategoryFilter -> CategoryFilter -> Bool
== :: CategoryFilter -> CategoryFilter -> Bool
$c== :: CategoryFilter -> CategoryFilter -> Bool
Prelude.Eq, ReadPrec [CategoryFilter]
ReadPrec CategoryFilter
Int -> ReadS CategoryFilter
ReadS [CategoryFilter]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CategoryFilter]
$creadListPrec :: ReadPrec [CategoryFilter]
readPrec :: ReadPrec CategoryFilter
$creadPrec :: ReadPrec CategoryFilter
readList :: ReadS [CategoryFilter]
$creadList :: ReadS [CategoryFilter]
readsPrec :: Int -> ReadS CategoryFilter
$creadsPrec :: Int -> ReadS CategoryFilter
Prelude.Read, Int -> CategoryFilter -> ShowS
[CategoryFilter] -> ShowS
CategoryFilter -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CategoryFilter] -> ShowS
$cshowList :: [CategoryFilter] -> ShowS
show :: CategoryFilter -> String
$cshow :: CategoryFilter -> String
showsPrec :: Int -> CategoryFilter -> ShowS
$cshowsPrec :: Int -> CategoryFilter -> ShowS
Prelude.Show, forall x. Rep CategoryFilter x -> CategoryFilter
forall x. CategoryFilter -> Rep CategoryFilter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CategoryFilter x -> CategoryFilter
$cfrom :: forall x. CategoryFilter -> Rep CategoryFilter x
Prelude.Generic)

-- |
-- Create a value of 'CategoryFilter' 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:
--
-- 'configuration', 'categoryFilter_configuration' - The configuration for a @CategoryFilter@.
--
-- 'filterId', 'categoryFilter_filterId' - An identifier that uniquely identifies a filter within a dashboard,
-- analysis, or template.
--
-- 'column', 'categoryFilter_column' - The column that the filter is applied to.
newCategoryFilter ::
  -- | 'filterId'
  Prelude.Text ->
  -- | 'column'
  ColumnIdentifier ->
  CategoryFilter
newCategoryFilter :: Text -> ColumnIdentifier -> CategoryFilter
newCategoryFilter Text
pFilterId_ ColumnIdentifier
pColumn_ =
  CategoryFilter'
    { $sel:configuration:CategoryFilter' :: Maybe CategoryFilterConfiguration
configuration = forall a. Maybe a
Prelude.Nothing,
      $sel:filterId:CategoryFilter' :: Text
filterId = Text
pFilterId_,
      $sel:column:CategoryFilter' :: ColumnIdentifier
column = ColumnIdentifier
pColumn_
    }

-- | The configuration for a @CategoryFilter@.
categoryFilter_configuration :: Lens.Lens' CategoryFilter (Prelude.Maybe CategoryFilterConfiguration)
categoryFilter_configuration :: Lens' CategoryFilter (Maybe CategoryFilterConfiguration)
categoryFilter_configuration = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CategoryFilter' {Maybe CategoryFilterConfiguration
configuration :: Maybe CategoryFilterConfiguration
$sel:configuration:CategoryFilter' :: CategoryFilter -> Maybe CategoryFilterConfiguration
configuration} -> Maybe CategoryFilterConfiguration
configuration) (\s :: CategoryFilter
s@CategoryFilter' {} Maybe CategoryFilterConfiguration
a -> CategoryFilter
s {$sel:configuration:CategoryFilter' :: Maybe CategoryFilterConfiguration
configuration = Maybe CategoryFilterConfiguration
a} :: CategoryFilter)

-- | An identifier that uniquely identifies a filter within a dashboard,
-- analysis, or template.
categoryFilter_filterId :: Lens.Lens' CategoryFilter Prelude.Text
categoryFilter_filterId :: Lens' CategoryFilter Text
categoryFilter_filterId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CategoryFilter' {Text
filterId :: Text
$sel:filterId:CategoryFilter' :: CategoryFilter -> Text
filterId} -> Text
filterId) (\s :: CategoryFilter
s@CategoryFilter' {} Text
a -> CategoryFilter
s {$sel:filterId:CategoryFilter' :: Text
filterId = Text
a} :: CategoryFilter)

-- | The column that the filter is applied to.
categoryFilter_column :: Lens.Lens' CategoryFilter ColumnIdentifier
categoryFilter_column :: Lens' CategoryFilter ColumnIdentifier
categoryFilter_column = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CategoryFilter' {ColumnIdentifier
column :: ColumnIdentifier
$sel:column:CategoryFilter' :: CategoryFilter -> ColumnIdentifier
column} -> ColumnIdentifier
column) (\s :: CategoryFilter
s@CategoryFilter' {} ColumnIdentifier
a -> CategoryFilter
s {$sel:column:CategoryFilter' :: ColumnIdentifier
column = ColumnIdentifier
a} :: CategoryFilter)

instance Data.FromJSON CategoryFilter where
  parseJSON :: Value -> Parser CategoryFilter
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CategoryFilter"
      ( \Object
x ->
          Maybe CategoryFilterConfiguration
-> Text -> ColumnIdentifier -> CategoryFilter
CategoryFilter'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Configuration")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"FilterId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Column")
      )

instance Prelude.Hashable CategoryFilter where
  hashWithSalt :: Int -> CategoryFilter -> Int
hashWithSalt Int
_salt CategoryFilter' {Maybe CategoryFilterConfiguration
Text
ColumnIdentifier
column :: ColumnIdentifier
filterId :: Text
configuration :: Maybe CategoryFilterConfiguration
$sel:column:CategoryFilter' :: CategoryFilter -> ColumnIdentifier
$sel:filterId:CategoryFilter' :: CategoryFilter -> Text
$sel:configuration:CategoryFilter' :: CategoryFilter -> Maybe CategoryFilterConfiguration
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CategoryFilterConfiguration
configuration
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
filterId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ColumnIdentifier
column

instance Prelude.NFData CategoryFilter where
  rnf :: CategoryFilter -> ()
rnf CategoryFilter' {Maybe CategoryFilterConfiguration
Text
ColumnIdentifier
column :: ColumnIdentifier
filterId :: Text
configuration :: Maybe CategoryFilterConfiguration
$sel:column:CategoryFilter' :: CategoryFilter -> ColumnIdentifier
$sel:filterId:CategoryFilter' :: CategoryFilter -> Text
$sel:configuration:CategoryFilter' :: CategoryFilter -> Maybe CategoryFilterConfiguration
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe CategoryFilterConfiguration
configuration
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
filterId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ColumnIdentifier
column

instance Data.ToJSON CategoryFilter where
  toJSON :: CategoryFilter -> Value
toJSON CategoryFilter' {Maybe CategoryFilterConfiguration
Text
ColumnIdentifier
column :: ColumnIdentifier
filterId :: Text
configuration :: Maybe CategoryFilterConfiguration
$sel:column:CategoryFilter' :: CategoryFilter -> ColumnIdentifier
$sel:filterId:CategoryFilter' :: CategoryFilter -> Text
$sel:configuration:CategoryFilter' :: CategoryFilter -> Maybe CategoryFilterConfiguration
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Configuration" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe CategoryFilterConfiguration
configuration,
            forall a. a -> Maybe a
Prelude.Just (Key
"FilterId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
filterId),
            forall a. a -> Maybe a
Prelude.Just (Key
"Column" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ColumnIdentifier
column)
          ]
      )