{-# 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.ExplicitHierarchy
-- 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.ExplicitHierarchy 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 built
-- within a visual\'s field wells. These fields can\'t be duplicated to
-- other visuals.
--
-- /See:/ 'newExplicitHierarchy' smart constructor.
data ExplicitHierarchy = ExplicitHierarchy'
  { -- | The option that determines the drill down filters for the explicit
    -- hierarchy.
    ExplicitHierarchy -> Maybe [DrillDownFilter]
drillDownFilters :: Prelude.Maybe [DrillDownFilter],
    -- | The hierarchy ID of the explicit hierarchy.
    ExplicitHierarchy -> Text
hierarchyId :: Prelude.Text,
    -- | The list of columns that define the explicit hierarchy.
    ExplicitHierarchy -> NonEmpty ColumnIdentifier
columns :: Prelude.NonEmpty ColumnIdentifier
  }
  deriving (ExplicitHierarchy -> ExplicitHierarchy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExplicitHierarchy -> ExplicitHierarchy -> Bool
$c/= :: ExplicitHierarchy -> ExplicitHierarchy -> Bool
== :: ExplicitHierarchy -> ExplicitHierarchy -> Bool
$c== :: ExplicitHierarchy -> ExplicitHierarchy -> Bool
Prelude.Eq, ReadPrec [ExplicitHierarchy]
ReadPrec ExplicitHierarchy
Int -> ReadS ExplicitHierarchy
ReadS [ExplicitHierarchy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ExplicitHierarchy]
$creadListPrec :: ReadPrec [ExplicitHierarchy]
readPrec :: ReadPrec ExplicitHierarchy
$creadPrec :: ReadPrec ExplicitHierarchy
readList :: ReadS [ExplicitHierarchy]
$creadList :: ReadS [ExplicitHierarchy]
readsPrec :: Int -> ReadS ExplicitHierarchy
$creadsPrec :: Int -> ReadS ExplicitHierarchy
Prelude.Read, Int -> ExplicitHierarchy -> ShowS
[ExplicitHierarchy] -> ShowS
ExplicitHierarchy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExplicitHierarchy] -> ShowS
$cshowList :: [ExplicitHierarchy] -> ShowS
show :: ExplicitHierarchy -> String
$cshow :: ExplicitHierarchy -> String
showsPrec :: Int -> ExplicitHierarchy -> ShowS
$cshowsPrec :: Int -> ExplicitHierarchy -> ShowS
Prelude.Show, forall x. Rep ExplicitHierarchy x -> ExplicitHierarchy
forall x. ExplicitHierarchy -> Rep ExplicitHierarchy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ExplicitHierarchy x -> ExplicitHierarchy
$cfrom :: forall x. ExplicitHierarchy -> Rep ExplicitHierarchy x
Prelude.Generic)

-- |
-- Create a value of 'ExplicitHierarchy' 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', 'explicitHierarchy_drillDownFilters' - The option that determines the drill down filters for the explicit
-- hierarchy.
--
-- 'hierarchyId', 'explicitHierarchy_hierarchyId' - The hierarchy ID of the explicit hierarchy.
--
-- 'columns', 'explicitHierarchy_columns' - The list of columns that define the explicit hierarchy.
newExplicitHierarchy ::
  -- | 'hierarchyId'
  Prelude.Text ->
  -- | 'columns'
  Prelude.NonEmpty ColumnIdentifier ->
  ExplicitHierarchy
newExplicitHierarchy :: Text -> NonEmpty ColumnIdentifier -> ExplicitHierarchy
newExplicitHierarchy Text
pHierarchyId_ NonEmpty ColumnIdentifier
pColumns_ =
  ExplicitHierarchy'
    { $sel:drillDownFilters:ExplicitHierarchy' :: Maybe [DrillDownFilter]
drillDownFilters =
        forall a. Maybe a
Prelude.Nothing,
      $sel:hierarchyId:ExplicitHierarchy' :: Text
hierarchyId = Text
pHierarchyId_,
      $sel:columns:ExplicitHierarchy' :: 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 explicit
-- hierarchy.
explicitHierarchy_drillDownFilters :: Lens.Lens' ExplicitHierarchy (Prelude.Maybe [DrillDownFilter])
explicitHierarchy_drillDownFilters :: Lens' ExplicitHierarchy (Maybe [DrillDownFilter])
explicitHierarchy_drillDownFilters = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExplicitHierarchy' {Maybe [DrillDownFilter]
drillDownFilters :: Maybe [DrillDownFilter]
$sel:drillDownFilters:ExplicitHierarchy' :: ExplicitHierarchy -> Maybe [DrillDownFilter]
drillDownFilters} -> Maybe [DrillDownFilter]
drillDownFilters) (\s :: ExplicitHierarchy
s@ExplicitHierarchy' {} Maybe [DrillDownFilter]
a -> ExplicitHierarchy
s {$sel:drillDownFilters:ExplicitHierarchy' :: Maybe [DrillDownFilter]
drillDownFilters = Maybe [DrillDownFilter]
a} :: ExplicitHierarchy) 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 explicit hierarchy.
explicitHierarchy_hierarchyId :: Lens.Lens' ExplicitHierarchy Prelude.Text
explicitHierarchy_hierarchyId :: Lens' ExplicitHierarchy Text
explicitHierarchy_hierarchyId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExplicitHierarchy' {Text
hierarchyId :: Text
$sel:hierarchyId:ExplicitHierarchy' :: ExplicitHierarchy -> Text
hierarchyId} -> Text
hierarchyId) (\s :: ExplicitHierarchy
s@ExplicitHierarchy' {} Text
a -> ExplicitHierarchy
s {$sel:hierarchyId:ExplicitHierarchy' :: Text
hierarchyId = Text
a} :: ExplicitHierarchy)

-- | The list of columns that define the explicit hierarchy.
explicitHierarchy_columns :: Lens.Lens' ExplicitHierarchy (Prelude.NonEmpty ColumnIdentifier)
explicitHierarchy_columns :: Lens' ExplicitHierarchy (NonEmpty ColumnIdentifier)
explicitHierarchy_columns = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExplicitHierarchy' {NonEmpty ColumnIdentifier
columns :: NonEmpty ColumnIdentifier
$sel:columns:ExplicitHierarchy' :: ExplicitHierarchy -> NonEmpty ColumnIdentifier
columns} -> NonEmpty ColumnIdentifier
columns) (\s :: ExplicitHierarchy
s@ExplicitHierarchy' {} NonEmpty ColumnIdentifier
a -> ExplicitHierarchy
s {$sel:columns:ExplicitHierarchy' :: NonEmpty ColumnIdentifier
columns = NonEmpty ColumnIdentifier
a} :: ExplicitHierarchy) 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 ExplicitHierarchy where
  parseJSON :: Value -> Parser ExplicitHierarchy
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ExplicitHierarchy"
      ( \Object
x ->
          Maybe [DrillDownFilter]
-> Text -> NonEmpty ColumnIdentifier -> ExplicitHierarchy
ExplicitHierarchy'
            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 ExplicitHierarchy where
  hashWithSalt :: Int -> ExplicitHierarchy -> Int
hashWithSalt Int
_salt ExplicitHierarchy' {Maybe [DrillDownFilter]
NonEmpty ColumnIdentifier
Text
columns :: NonEmpty ColumnIdentifier
hierarchyId :: Text
drillDownFilters :: Maybe [DrillDownFilter]
$sel:columns:ExplicitHierarchy' :: ExplicitHierarchy -> NonEmpty ColumnIdentifier
$sel:hierarchyId:ExplicitHierarchy' :: ExplicitHierarchy -> Text
$sel:drillDownFilters:ExplicitHierarchy' :: ExplicitHierarchy -> 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 ExplicitHierarchy where
  rnf :: ExplicitHierarchy -> ()
rnf ExplicitHierarchy' {Maybe [DrillDownFilter]
NonEmpty ColumnIdentifier
Text
columns :: NonEmpty ColumnIdentifier
hierarchyId :: Text
drillDownFilters :: Maybe [DrillDownFilter]
$sel:columns:ExplicitHierarchy' :: ExplicitHierarchy -> NonEmpty ColumnIdentifier
$sel:hierarchyId:ExplicitHierarchy' :: ExplicitHierarchy -> Text
$sel:drillDownFilters:ExplicitHierarchy' :: ExplicitHierarchy -> 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 ExplicitHierarchy where
  toJSON :: ExplicitHierarchy -> Value
toJSON ExplicitHierarchy' {Maybe [DrillDownFilter]
NonEmpty ColumnIdentifier
Text
columns :: NonEmpty ColumnIdentifier
hierarchyId :: Text
drillDownFilters :: Maybe [DrillDownFilter]
$sel:columns:ExplicitHierarchy' :: ExplicitHierarchy -> NonEmpty ColumnIdentifier
$sel:hierarchyId:ExplicitHierarchy' :: ExplicitHierarchy -> Text
$sel:drillDownFilters:ExplicitHierarchy' :: ExplicitHierarchy -> 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)
          ]
      )