{-# 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.DataPathSort
-- 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.DataPathSort 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.DataPathValue
import Amazonka.QuickSight.Types.SortDirection

-- | Allows data paths to be sorted by a specific data value.
--
-- /See:/ 'newDataPathSort' smart constructor.
data DataPathSort = DataPathSort'
  { -- | Determines the sort direction.
    DataPathSort -> SortDirection
direction :: SortDirection,
    -- | The list of data paths that need to be sorted.
    DataPathSort -> [DataPathValue]
sortPaths :: [DataPathValue]
  }
  deriving (DataPathSort -> DataPathSort -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DataPathSort -> DataPathSort -> Bool
$c/= :: DataPathSort -> DataPathSort -> Bool
== :: DataPathSort -> DataPathSort -> Bool
$c== :: DataPathSort -> DataPathSort -> Bool
Prelude.Eq, Int -> DataPathSort -> ShowS
[DataPathSort] -> ShowS
DataPathSort -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DataPathSort] -> ShowS
$cshowList :: [DataPathSort] -> ShowS
show :: DataPathSort -> String
$cshow :: DataPathSort -> String
showsPrec :: Int -> DataPathSort -> ShowS
$cshowsPrec :: Int -> DataPathSort -> ShowS
Prelude.Show, forall x. Rep DataPathSort x -> DataPathSort
forall x. DataPathSort -> Rep DataPathSort x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DataPathSort x -> DataPathSort
$cfrom :: forall x. DataPathSort -> Rep DataPathSort x
Prelude.Generic)

-- |
-- Create a value of 'DataPathSort' 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:
--
-- 'direction', 'dataPathSort_direction' - Determines the sort direction.
--
-- 'sortPaths', 'dataPathSort_sortPaths' - The list of data paths that need to be sorted.
newDataPathSort ::
  -- | 'direction'
  SortDirection ->
  DataPathSort
newDataPathSort :: SortDirection -> DataPathSort
newDataPathSort SortDirection
pDirection_ =
  DataPathSort'
    { $sel:direction:DataPathSort' :: SortDirection
direction = SortDirection
pDirection_,
      $sel:sortPaths:DataPathSort' :: [DataPathValue]
sortPaths = forall a. Monoid a => a
Prelude.mempty
    }

-- | Determines the sort direction.
dataPathSort_direction :: Lens.Lens' DataPathSort SortDirection
dataPathSort_direction :: Lens' DataPathSort SortDirection
dataPathSort_direction = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DataPathSort' {SortDirection
direction :: SortDirection
$sel:direction:DataPathSort' :: DataPathSort -> SortDirection
direction} -> SortDirection
direction) (\s :: DataPathSort
s@DataPathSort' {} SortDirection
a -> DataPathSort
s {$sel:direction:DataPathSort' :: SortDirection
direction = SortDirection
a} :: DataPathSort)

-- | The list of data paths that need to be sorted.
dataPathSort_sortPaths :: Lens.Lens' DataPathSort [DataPathValue]
dataPathSort_sortPaths :: Lens' DataPathSort [DataPathValue]
dataPathSort_sortPaths = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DataPathSort' {[DataPathValue]
sortPaths :: [DataPathValue]
$sel:sortPaths:DataPathSort' :: DataPathSort -> [DataPathValue]
sortPaths} -> [DataPathValue]
sortPaths) (\s :: DataPathSort
s@DataPathSort' {} [DataPathValue]
a -> DataPathSort
s {$sel:sortPaths:DataPathSort' :: [DataPathValue]
sortPaths = [DataPathValue]
a} :: DataPathSort) 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 DataPathSort where
  parseJSON :: Value -> Parser DataPathSort
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"DataPathSort"
      ( \Object
x ->
          SortDirection -> [DataPathValue] -> DataPathSort
DataPathSort'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Direction")
            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
"SortPaths" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable DataPathSort where
  hashWithSalt :: Int -> DataPathSort -> Int
hashWithSalt Int
_salt DataPathSort' {[DataPathValue]
SortDirection
sortPaths :: [DataPathValue]
direction :: SortDirection
$sel:sortPaths:DataPathSort' :: DataPathSort -> [DataPathValue]
$sel:direction:DataPathSort' :: DataPathSort -> SortDirection
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` SortDirection
direction
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [DataPathValue]
sortPaths

instance Prelude.NFData DataPathSort where
  rnf :: DataPathSort -> ()
rnf DataPathSort' {[DataPathValue]
SortDirection
sortPaths :: [DataPathValue]
direction :: SortDirection
$sel:sortPaths:DataPathSort' :: DataPathSort -> [DataPathValue]
$sel:direction:DataPathSort' :: DataPathSort -> SortDirection
..} =
    forall a. NFData a => a -> ()
Prelude.rnf SortDirection
direction
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [DataPathValue]
sortPaths

instance Data.ToJSON DataPathSort where
  toJSON :: DataPathSort -> Value
toJSON DataPathSort' {[DataPathValue]
SortDirection
sortPaths :: [DataPathValue]
direction :: SortDirection
$sel:sortPaths:DataPathSort' :: DataPathSort -> [DataPathValue]
$sel:direction:DataPathSort' :: DataPathSort -> SortDirection
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Direction" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= SortDirection
direction),
            forall a. a -> Maybe a
Prelude.Just (Key
"SortPaths" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [DataPathValue]
sortPaths)
          ]
      )