{-# 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.PredefinedHierarchy
-- 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.PredefinedHierarchy 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.ColumnIdentifier
import Amazonka.QuickSight.Types.DrillDownFilter

-- | The option that determines the hierarchy of the fields that are defined
-- during data preparation. These fields are available to use in any
-- analysis that uses the data source.
--
-- /See:/ 'newPredefinedHierarchy' smart constructor.
data PredefinedHierarchy = PredefinedHierarchy'
  { -- | The option that determines the drill down filters for the predefined
    -- hierarchy.
    PredefinedHierarchy -> Maybe [DrillDownFilter]
drillDownFilters :: Prelude.Maybe [DrillDownFilter],
    -- | The hierarchy ID of the predefined hierarchy.
    PredefinedHierarchy -> Text
hierarchyId :: Prelude.Text,
    -- | The list of columns that define the predefined hierarchy.
    PredefinedHierarchy -> NonEmpty ColumnIdentifier
columns :: Prelude.NonEmpty ColumnIdentifier
  }
  deriving (PredefinedHierarchy -> PredefinedHierarchy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PredefinedHierarchy -> PredefinedHierarchy -> Bool
$c/= :: PredefinedHierarchy -> PredefinedHierarchy -> Bool
== :: PredefinedHierarchy -> PredefinedHierarchy -> Bool
$c== :: PredefinedHierarchy -> PredefinedHierarchy -> Bool
Prelude.Eq, ReadPrec [PredefinedHierarchy]
ReadPrec PredefinedHierarchy
Int -> ReadS PredefinedHierarchy
ReadS [PredefinedHierarchy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PredefinedHierarchy]
$creadListPrec :: ReadPrec [PredefinedHierarchy]
readPrec :: ReadPrec PredefinedHierarchy
$creadPrec :: ReadPrec PredefinedHierarchy
readList :: ReadS [PredefinedHierarchy]
$creadList :: ReadS [PredefinedHierarchy]
readsPrec :: Int -> ReadS PredefinedHierarchy
$creadsPrec :: Int -> ReadS PredefinedHierarchy
Prelude.Read, Int -> PredefinedHierarchy -> ShowS
[PredefinedHierarchy] -> ShowS
PredefinedHierarchy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PredefinedHierarchy] -> ShowS
$cshowList :: [PredefinedHierarchy] -> ShowS
show :: PredefinedHierarchy -> String
$cshow :: PredefinedHierarchy -> String
showsPrec :: Int -> PredefinedHierarchy -> ShowS
$cshowsPrec :: Int -> PredefinedHierarchy -> ShowS
Prelude.Show, forall x. Rep PredefinedHierarchy x -> PredefinedHierarchy
forall x. PredefinedHierarchy -> Rep PredefinedHierarchy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PredefinedHierarchy x -> PredefinedHierarchy
$cfrom :: forall x. PredefinedHierarchy -> Rep PredefinedHierarchy x
Prelude.Generic)

-- |
-- Create a value of 'PredefinedHierarchy' 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:
--
-- 'drillDownFilters', 'predefinedHierarchy_drillDownFilters' - The option that determines the drill down filters for the predefined
-- hierarchy.
--
-- 'hierarchyId', 'predefinedHierarchy_hierarchyId' - The hierarchy ID of the predefined hierarchy.
--
-- 'columns', 'predefinedHierarchy_columns' - The list of columns that define the predefined hierarchy.
newPredefinedHierarchy ::
  -- | 'hierarchyId'
  Prelude.Text ->
  -- | 'columns'
  Prelude.NonEmpty ColumnIdentifier ->
  PredefinedHierarchy
newPredefinedHierarchy :: Text -> NonEmpty ColumnIdentifier -> PredefinedHierarchy
newPredefinedHierarchy Text
pHierarchyId_ NonEmpty ColumnIdentifier
pColumns_ =
  PredefinedHierarchy'
    { $sel:drillDownFilters:PredefinedHierarchy' :: Maybe [DrillDownFilter]
drillDownFilters =
        forall a. Maybe a
Prelude.Nothing,
      $sel:hierarchyId:PredefinedHierarchy' :: Text
hierarchyId = Text
pHierarchyId_,
      $sel:columns:PredefinedHierarchy' :: NonEmpty ColumnIdentifier
columns = 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 ColumnIdentifier
pColumns_
    }

-- | The option that determines the drill down filters for the predefined
-- hierarchy.
predefinedHierarchy_drillDownFilters :: Lens.Lens' PredefinedHierarchy (Prelude.Maybe [DrillDownFilter])
predefinedHierarchy_drillDownFilters :: Lens' PredefinedHierarchy (Maybe [DrillDownFilter])
predefinedHierarchy_drillDownFilters = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PredefinedHierarchy' {Maybe [DrillDownFilter]
drillDownFilters :: Maybe [DrillDownFilter]
$sel:drillDownFilters:PredefinedHierarchy' :: PredefinedHierarchy -> Maybe [DrillDownFilter]
drillDownFilters} -> Maybe [DrillDownFilter]
drillDownFilters) (\s :: PredefinedHierarchy
s@PredefinedHierarchy' {} Maybe [DrillDownFilter]
a -> PredefinedHierarchy
s {$sel:drillDownFilters:PredefinedHierarchy' :: Maybe [DrillDownFilter]
drillDownFilters = Maybe [DrillDownFilter]
a} :: PredefinedHierarchy) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The hierarchy ID of the predefined hierarchy.
predefinedHierarchy_hierarchyId :: Lens.Lens' PredefinedHierarchy Prelude.Text
predefinedHierarchy_hierarchyId :: Lens' PredefinedHierarchy Text
predefinedHierarchy_hierarchyId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PredefinedHierarchy' {Text
hierarchyId :: Text
$sel:hierarchyId:PredefinedHierarchy' :: PredefinedHierarchy -> Text
hierarchyId} -> Text
hierarchyId) (\s :: PredefinedHierarchy
s@PredefinedHierarchy' {} Text
a -> PredefinedHierarchy
s {$sel:hierarchyId:PredefinedHierarchy' :: Text
hierarchyId = Text
a} :: PredefinedHierarchy)

-- | The list of columns that define the predefined hierarchy.
predefinedHierarchy_columns :: Lens.Lens' PredefinedHierarchy (Prelude.NonEmpty ColumnIdentifier)
predefinedHierarchy_columns :: Lens' PredefinedHierarchy (NonEmpty ColumnIdentifier)
predefinedHierarchy_columns = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PredefinedHierarchy' {NonEmpty ColumnIdentifier
columns :: NonEmpty ColumnIdentifier
$sel:columns:PredefinedHierarchy' :: PredefinedHierarchy -> NonEmpty ColumnIdentifier
columns} -> NonEmpty ColumnIdentifier
columns) (\s :: PredefinedHierarchy
s@PredefinedHierarchy' {} NonEmpty ColumnIdentifier
a -> PredefinedHierarchy
s {$sel:columns:PredefinedHierarchy' :: NonEmpty ColumnIdentifier
columns = NonEmpty ColumnIdentifier
a} :: PredefinedHierarchy) 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

instance Data.FromJSON PredefinedHierarchy where
  parseJSON :: Value -> Parser PredefinedHierarchy
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PredefinedHierarchy"
      ( \Object
x ->
          Maybe [DrillDownFilter]
-> Text -> NonEmpty ColumnIdentifier -> PredefinedHierarchy
PredefinedHierarchy'
            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
"DrillDownFilters"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
            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
"HierarchyId")
            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
"Columns")
      )

instance Prelude.Hashable PredefinedHierarchy where
  hashWithSalt :: Int -> PredefinedHierarchy -> Int
hashWithSalt Int
_salt PredefinedHierarchy' {Maybe [DrillDownFilter]
NonEmpty ColumnIdentifier
Text
columns :: NonEmpty ColumnIdentifier
hierarchyId :: Text
drillDownFilters :: Maybe [DrillDownFilter]
$sel:columns:PredefinedHierarchy' :: PredefinedHierarchy -> NonEmpty ColumnIdentifier
$sel:hierarchyId:PredefinedHierarchy' :: PredefinedHierarchy -> Text
$sel:drillDownFilters:PredefinedHierarchy' :: PredefinedHierarchy -> Maybe [DrillDownFilter]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [DrillDownFilter]
drillDownFilters
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
hierarchyId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty ColumnIdentifier
columns

instance Prelude.NFData PredefinedHierarchy where
  rnf :: PredefinedHierarchy -> ()
rnf PredefinedHierarchy' {Maybe [DrillDownFilter]
NonEmpty ColumnIdentifier
Text
columns :: NonEmpty ColumnIdentifier
hierarchyId :: Text
drillDownFilters :: Maybe [DrillDownFilter]
$sel:columns:PredefinedHierarchy' :: PredefinedHierarchy -> NonEmpty ColumnIdentifier
$sel:hierarchyId:PredefinedHierarchy' :: PredefinedHierarchy -> Text
$sel:drillDownFilters:PredefinedHierarchy' :: PredefinedHierarchy -> Maybe [DrillDownFilter]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [DrillDownFilter]
drillDownFilters
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
hierarchyId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty ColumnIdentifier
columns

instance Data.ToJSON PredefinedHierarchy where
  toJSON :: PredefinedHierarchy -> Value
toJSON PredefinedHierarchy' {Maybe [DrillDownFilter]
NonEmpty ColumnIdentifier
Text
columns :: NonEmpty ColumnIdentifier
hierarchyId :: Text
drillDownFilters :: Maybe [DrillDownFilter]
$sel:columns:PredefinedHierarchy' :: PredefinedHierarchy -> NonEmpty ColumnIdentifier
$sel:hierarchyId:PredefinedHierarchy' :: PredefinedHierarchy -> Text
$sel:drillDownFilters:PredefinedHierarchy' :: PredefinedHierarchy -> Maybe [DrillDownFilter]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"DrillDownFilters" 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 [DrillDownFilter]
drillDownFilters,
            forall a. a -> Maybe a
Prelude.Just (Key
"HierarchyId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
hierarchyId),
            forall a. a -> Maybe a
Prelude.Just (Key
"Columns" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty ColumnIdentifier
columns)
          ]
      )