{-# 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.FieldSortOptions
-- 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.FieldSortOptions 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.FieldSort

-- | The field sort options in a chart configuration.
--
-- /See:/ 'newFieldSortOptions' smart constructor.
data FieldSortOptions = FieldSortOptions'
  { -- | The sort configuration for a column that is not used in a field well.
    FieldSortOptions -> Maybe ColumnSort
columnSort :: Prelude.Maybe ColumnSort,
    -- | The sort configuration for a field in a field well.
    FieldSortOptions -> Maybe FieldSort
fieldSort :: Prelude.Maybe FieldSort
  }
  deriving (FieldSortOptions -> FieldSortOptions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FieldSortOptions -> FieldSortOptions -> Bool
$c/= :: FieldSortOptions -> FieldSortOptions -> Bool
== :: FieldSortOptions -> FieldSortOptions -> Bool
$c== :: FieldSortOptions -> FieldSortOptions -> Bool
Prelude.Eq, ReadPrec [FieldSortOptions]
ReadPrec FieldSortOptions
Int -> ReadS FieldSortOptions
ReadS [FieldSortOptions]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FieldSortOptions]
$creadListPrec :: ReadPrec [FieldSortOptions]
readPrec :: ReadPrec FieldSortOptions
$creadPrec :: ReadPrec FieldSortOptions
readList :: ReadS [FieldSortOptions]
$creadList :: ReadS [FieldSortOptions]
readsPrec :: Int -> ReadS FieldSortOptions
$creadsPrec :: Int -> ReadS FieldSortOptions
Prelude.Read, Int -> FieldSortOptions -> ShowS
[FieldSortOptions] -> ShowS
FieldSortOptions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FieldSortOptions] -> ShowS
$cshowList :: [FieldSortOptions] -> ShowS
show :: FieldSortOptions -> String
$cshow :: FieldSortOptions -> String
showsPrec :: Int -> FieldSortOptions -> ShowS
$cshowsPrec :: Int -> FieldSortOptions -> ShowS
Prelude.Show, forall x. Rep FieldSortOptions x -> FieldSortOptions
forall x. FieldSortOptions -> Rep FieldSortOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FieldSortOptions x -> FieldSortOptions
$cfrom :: forall x. FieldSortOptions -> Rep FieldSortOptions x
Prelude.Generic)

-- |
-- Create a value of 'FieldSortOptions' 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:
--
-- 'columnSort', 'fieldSortOptions_columnSort' - The sort configuration for a column that is not used in a field well.
--
-- 'fieldSort', 'fieldSortOptions_fieldSort' - The sort configuration for a field in a field well.
newFieldSortOptions ::
  FieldSortOptions
newFieldSortOptions :: FieldSortOptions
newFieldSortOptions =
  FieldSortOptions'
    { $sel:columnSort:FieldSortOptions' :: Maybe ColumnSort
columnSort = forall a. Maybe a
Prelude.Nothing,
      $sel:fieldSort:FieldSortOptions' :: Maybe FieldSort
fieldSort = forall a. Maybe a
Prelude.Nothing
    }

-- | The sort configuration for a column that is not used in a field well.
fieldSortOptions_columnSort :: Lens.Lens' FieldSortOptions (Prelude.Maybe ColumnSort)
fieldSortOptions_columnSort :: Lens' FieldSortOptions (Maybe ColumnSort)
fieldSortOptions_columnSort = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FieldSortOptions' {Maybe ColumnSort
columnSort :: Maybe ColumnSort
$sel:columnSort:FieldSortOptions' :: FieldSortOptions -> Maybe ColumnSort
columnSort} -> Maybe ColumnSort
columnSort) (\s :: FieldSortOptions
s@FieldSortOptions' {} Maybe ColumnSort
a -> FieldSortOptions
s {$sel:columnSort:FieldSortOptions' :: Maybe ColumnSort
columnSort = Maybe ColumnSort
a} :: FieldSortOptions)

-- | The sort configuration for a field in a field well.
fieldSortOptions_fieldSort :: Lens.Lens' FieldSortOptions (Prelude.Maybe FieldSort)
fieldSortOptions_fieldSort :: Lens' FieldSortOptions (Maybe FieldSort)
fieldSortOptions_fieldSort = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FieldSortOptions' {Maybe FieldSort
fieldSort :: Maybe FieldSort
$sel:fieldSort:FieldSortOptions' :: FieldSortOptions -> Maybe FieldSort
fieldSort} -> Maybe FieldSort
fieldSort) (\s :: FieldSortOptions
s@FieldSortOptions' {} Maybe FieldSort
a -> FieldSortOptions
s {$sel:fieldSort:FieldSortOptions' :: Maybe FieldSort
fieldSort = Maybe FieldSort
a} :: FieldSortOptions)

instance Data.FromJSON FieldSortOptions where
  parseJSON :: Value -> Parser FieldSortOptions
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"FieldSortOptions"
      ( \Object
x ->
          Maybe ColumnSort -> Maybe FieldSort -> FieldSortOptions
FieldSortOptions'
            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
"ColumnSort")
            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
"FieldSort")
      )

instance Prelude.Hashable FieldSortOptions where
  hashWithSalt :: Int -> FieldSortOptions -> Int
hashWithSalt Int
_salt FieldSortOptions' {Maybe FieldSort
Maybe ColumnSort
fieldSort :: Maybe FieldSort
columnSort :: Maybe ColumnSort
$sel:fieldSort:FieldSortOptions' :: FieldSortOptions -> Maybe FieldSort
$sel:columnSort:FieldSortOptions' :: FieldSortOptions -> Maybe ColumnSort
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ColumnSort
columnSort
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe FieldSort
fieldSort

instance Prelude.NFData FieldSortOptions where
  rnf :: FieldSortOptions -> ()
rnf FieldSortOptions' {Maybe FieldSort
Maybe ColumnSort
fieldSort :: Maybe FieldSort
columnSort :: Maybe ColumnSort
$sel:fieldSort:FieldSortOptions' :: FieldSortOptions -> Maybe FieldSort
$sel:columnSort:FieldSortOptions' :: FieldSortOptions -> Maybe ColumnSort
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ColumnSort
columnSort
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe FieldSort
fieldSort

instance Data.ToJSON FieldSortOptions where
  toJSON :: FieldSortOptions -> Value
toJSON FieldSortOptions' {Maybe FieldSort
Maybe ColumnSort
fieldSort :: Maybe FieldSort
columnSort :: Maybe ColumnSort
$sel:fieldSort:FieldSortOptions' :: FieldSortOptions -> Maybe FieldSort
$sel:columnSort:FieldSortOptions' :: FieldSortOptions -> Maybe ColumnSort
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ColumnSort" 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
columnSort,
            (Key
"FieldSort" 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
fieldSort
          ]
      )