{-# 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.PivotTableSortBy
-- 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.PivotTableSortBy 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.ColumnSort
import Amazonka.QuickSight.Types.DataPathSort
import Amazonka.QuickSight.Types.FieldSort

-- | The sort by field for the field sort options.
--
-- /See:/ 'newPivotTableSortBy' smart constructor.
data PivotTableSortBy = PivotTableSortBy'
  { -- | The column sort (field id, direction) for the pivot table sort by
    -- options.
    PivotTableSortBy -> Maybe ColumnSort
column :: Prelude.Maybe ColumnSort,
    -- | The data path sort (data path value, direction) for the pivot table sort
    -- by options.
    PivotTableSortBy -> Maybe DataPathSort
dataPath :: Prelude.Maybe DataPathSort,
    -- | The field sort (field id, direction) for the pivot table sort by
    -- options.
    PivotTableSortBy -> Maybe FieldSort
field :: Prelude.Maybe FieldSort
  }
  deriving (PivotTableSortBy -> PivotTableSortBy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PivotTableSortBy -> PivotTableSortBy -> Bool
$c/= :: PivotTableSortBy -> PivotTableSortBy -> Bool
== :: PivotTableSortBy -> PivotTableSortBy -> Bool
$c== :: PivotTableSortBy -> PivotTableSortBy -> Bool
Prelude.Eq, Int -> PivotTableSortBy -> ShowS
[PivotTableSortBy] -> ShowS
PivotTableSortBy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PivotTableSortBy] -> ShowS
$cshowList :: [PivotTableSortBy] -> ShowS
show :: PivotTableSortBy -> String
$cshow :: PivotTableSortBy -> String
showsPrec :: Int -> PivotTableSortBy -> ShowS
$cshowsPrec :: Int -> PivotTableSortBy -> ShowS
Prelude.Show, forall x. Rep PivotTableSortBy x -> PivotTableSortBy
forall x. PivotTableSortBy -> Rep PivotTableSortBy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PivotTableSortBy x -> PivotTableSortBy
$cfrom :: forall x. PivotTableSortBy -> Rep PivotTableSortBy x
Prelude.Generic)

-- |
-- Create a value of 'PivotTableSortBy' 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:
--
-- 'column', 'pivotTableSortBy_column' - The column sort (field id, direction) for the pivot table sort by
-- options.
--
-- 'dataPath', 'pivotTableSortBy_dataPath' - The data path sort (data path value, direction) for the pivot table sort
-- by options.
--
-- 'field', 'pivotTableSortBy_field' - The field sort (field id, direction) for the pivot table sort by
-- options.
newPivotTableSortBy ::
  PivotTableSortBy
newPivotTableSortBy :: PivotTableSortBy
newPivotTableSortBy =
  PivotTableSortBy'
    { $sel:column:PivotTableSortBy' :: Maybe ColumnSort
column = forall a. Maybe a
Prelude.Nothing,
      $sel:dataPath:PivotTableSortBy' :: Maybe DataPathSort
dataPath = forall a. Maybe a
Prelude.Nothing,
      $sel:field:PivotTableSortBy' :: Maybe FieldSort
field = forall a. Maybe a
Prelude.Nothing
    }

-- | The column sort (field id, direction) for the pivot table sort by
-- options.
pivotTableSortBy_column :: Lens.Lens' PivotTableSortBy (Prelude.Maybe ColumnSort)
pivotTableSortBy_column :: Lens' PivotTableSortBy (Maybe ColumnSort)
pivotTableSortBy_column = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PivotTableSortBy' {Maybe ColumnSort
column :: Maybe ColumnSort
$sel:column:PivotTableSortBy' :: PivotTableSortBy -> Maybe ColumnSort
column} -> Maybe ColumnSort
column) (\s :: PivotTableSortBy
s@PivotTableSortBy' {} Maybe ColumnSort
a -> PivotTableSortBy
s {$sel:column:PivotTableSortBy' :: Maybe ColumnSort
column = Maybe ColumnSort
a} :: PivotTableSortBy)

-- | The data path sort (data path value, direction) for the pivot table sort
-- by options.
pivotTableSortBy_dataPath :: Lens.Lens' PivotTableSortBy (Prelude.Maybe DataPathSort)
pivotTableSortBy_dataPath :: Lens' PivotTableSortBy (Maybe DataPathSort)
pivotTableSortBy_dataPath = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PivotTableSortBy' {Maybe DataPathSort
dataPath :: Maybe DataPathSort
$sel:dataPath:PivotTableSortBy' :: PivotTableSortBy -> Maybe DataPathSort
dataPath} -> Maybe DataPathSort
dataPath) (\s :: PivotTableSortBy
s@PivotTableSortBy' {} Maybe DataPathSort
a -> PivotTableSortBy
s {$sel:dataPath:PivotTableSortBy' :: Maybe DataPathSort
dataPath = Maybe DataPathSort
a} :: PivotTableSortBy)

-- | The field sort (field id, direction) for the pivot table sort by
-- options.
pivotTableSortBy_field :: Lens.Lens' PivotTableSortBy (Prelude.Maybe FieldSort)
pivotTableSortBy_field :: Lens' PivotTableSortBy (Maybe FieldSort)
pivotTableSortBy_field = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PivotTableSortBy' {Maybe FieldSort
field :: Maybe FieldSort
$sel:field:PivotTableSortBy' :: PivotTableSortBy -> Maybe FieldSort
field} -> Maybe FieldSort
field) (\s :: PivotTableSortBy
s@PivotTableSortBy' {} Maybe FieldSort
a -> PivotTableSortBy
s {$sel:field:PivotTableSortBy' :: Maybe FieldSort
field = Maybe FieldSort
a} :: PivotTableSortBy)

instance Data.FromJSON PivotTableSortBy where
  parseJSON :: Value -> Parser PivotTableSortBy
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PivotTableSortBy"
      ( \Object
x ->
          Maybe ColumnSort
-> Maybe DataPathSort -> Maybe FieldSort -> PivotTableSortBy
PivotTableSortBy'
            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
"Column")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"DataPath")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Field")
      )

instance Prelude.Hashable PivotTableSortBy where
  hashWithSalt :: Int -> PivotTableSortBy -> Int
hashWithSalt Int
_salt PivotTableSortBy' {Maybe FieldSort
Maybe DataPathSort
Maybe ColumnSort
field :: Maybe FieldSort
dataPath :: Maybe DataPathSort
column :: Maybe ColumnSort
$sel:field:PivotTableSortBy' :: PivotTableSortBy -> Maybe FieldSort
$sel:dataPath:PivotTableSortBy' :: PivotTableSortBy -> Maybe DataPathSort
$sel:column:PivotTableSortBy' :: PivotTableSortBy -> Maybe ColumnSort
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ColumnSort
column
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe DataPathSort
dataPath
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe FieldSort
field

instance Prelude.NFData PivotTableSortBy where
  rnf :: PivotTableSortBy -> ()
rnf PivotTableSortBy' {Maybe FieldSort
Maybe DataPathSort
Maybe ColumnSort
field :: Maybe FieldSort
dataPath :: Maybe DataPathSort
column :: Maybe ColumnSort
$sel:field:PivotTableSortBy' :: PivotTableSortBy -> Maybe FieldSort
$sel:dataPath:PivotTableSortBy' :: PivotTableSortBy -> Maybe DataPathSort
$sel:column:PivotTableSortBy' :: PivotTableSortBy -> Maybe ColumnSort
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ColumnSort
column
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe DataPathSort
dataPath
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe FieldSort
field

instance Data.ToJSON PivotTableSortBy where
  toJSON :: PivotTableSortBy -> Value
toJSON PivotTableSortBy' {Maybe FieldSort
Maybe DataPathSort
Maybe ColumnSort
field :: Maybe FieldSort
dataPath :: Maybe DataPathSort
column :: Maybe ColumnSort
$sel:field:PivotTableSortBy' :: PivotTableSortBy -> Maybe FieldSort
$sel:dataPath:PivotTableSortBy' :: PivotTableSortBy -> Maybe DataPathSort
$sel:column:PivotTableSortBy' :: PivotTableSortBy -> Maybe ColumnSort
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Column" 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 ColumnSort
column,
            (Key
"DataPath" 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 DataPathSort
dataPath,
            (Key
"Field" 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 FieldSort
field
          ]
      )