{-# 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.KeySpaces.Types.ClusteringKey
-- 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.KeySpaces.Types.ClusteringKey where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.KeySpaces.Types.SortOrder
import qualified Amazonka.Prelude as Prelude

-- | The optional clustering column portion of your primary key determines
-- how the data is clustered and sorted within each partition.
--
-- /See:/ 'newClusteringKey' smart constructor.
data ClusteringKey = ClusteringKey'
  { -- | The name(s) of the clustering column(s).
    ClusteringKey -> Text
name :: Prelude.Text,
    -- | Sets the ascendant (@ASC@) or descendant (@DESC@) order modifier.
    ClusteringKey -> SortOrder
orderBy :: SortOrder
  }
  deriving (ClusteringKey -> ClusteringKey -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ClusteringKey -> ClusteringKey -> Bool
$c/= :: ClusteringKey -> ClusteringKey -> Bool
== :: ClusteringKey -> ClusteringKey -> Bool
$c== :: ClusteringKey -> ClusteringKey -> Bool
Prelude.Eq, ReadPrec [ClusteringKey]
ReadPrec ClusteringKey
Int -> ReadS ClusteringKey
ReadS [ClusteringKey]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ClusteringKey]
$creadListPrec :: ReadPrec [ClusteringKey]
readPrec :: ReadPrec ClusteringKey
$creadPrec :: ReadPrec ClusteringKey
readList :: ReadS [ClusteringKey]
$creadList :: ReadS [ClusteringKey]
readsPrec :: Int -> ReadS ClusteringKey
$creadsPrec :: Int -> ReadS ClusteringKey
Prelude.Read, Int -> ClusteringKey -> ShowS
[ClusteringKey] -> ShowS
ClusteringKey -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ClusteringKey] -> ShowS
$cshowList :: [ClusteringKey] -> ShowS
show :: ClusteringKey -> String
$cshow :: ClusteringKey -> String
showsPrec :: Int -> ClusteringKey -> ShowS
$cshowsPrec :: Int -> ClusteringKey -> ShowS
Prelude.Show, forall x. Rep ClusteringKey x -> ClusteringKey
forall x. ClusteringKey -> Rep ClusteringKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ClusteringKey x -> ClusteringKey
$cfrom :: forall x. ClusteringKey -> Rep ClusteringKey x
Prelude.Generic)

-- |
-- Create a value of 'ClusteringKey' 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:
--
-- 'name', 'clusteringKey_name' - The name(s) of the clustering column(s).
--
-- 'orderBy', 'clusteringKey_orderBy' - Sets the ascendant (@ASC@) or descendant (@DESC@) order modifier.
newClusteringKey ::
  -- | 'name'
  Prelude.Text ->
  -- | 'orderBy'
  SortOrder ->
  ClusteringKey
newClusteringKey :: Text -> SortOrder -> ClusteringKey
newClusteringKey Text
pName_ SortOrder
pOrderBy_ =
  ClusteringKey' {$sel:name:ClusteringKey' :: Text
name = Text
pName_, $sel:orderBy:ClusteringKey' :: SortOrder
orderBy = SortOrder
pOrderBy_}

-- | The name(s) of the clustering column(s).
clusteringKey_name :: Lens.Lens' ClusteringKey Prelude.Text
clusteringKey_name :: Lens' ClusteringKey Text
clusteringKey_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ClusteringKey' {Text
name :: Text
$sel:name:ClusteringKey' :: ClusteringKey -> Text
name} -> Text
name) (\s :: ClusteringKey
s@ClusteringKey' {} Text
a -> ClusteringKey
s {$sel:name:ClusteringKey' :: Text
name = Text
a} :: ClusteringKey)

-- | Sets the ascendant (@ASC@) or descendant (@DESC@) order modifier.
clusteringKey_orderBy :: Lens.Lens' ClusteringKey SortOrder
clusteringKey_orderBy :: Lens' ClusteringKey SortOrder
clusteringKey_orderBy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ClusteringKey' {SortOrder
orderBy :: SortOrder
$sel:orderBy:ClusteringKey' :: ClusteringKey -> SortOrder
orderBy} -> SortOrder
orderBy) (\s :: ClusteringKey
s@ClusteringKey' {} SortOrder
a -> ClusteringKey
s {$sel:orderBy:ClusteringKey' :: SortOrder
orderBy = SortOrder
a} :: ClusteringKey)

instance Data.FromJSON ClusteringKey where
  parseJSON :: Value -> Parser ClusteringKey
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ClusteringKey"
      ( \Object
x ->
          Text -> SortOrder -> ClusteringKey
ClusteringKey'
            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
"name")
            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
"orderBy")
      )

instance Prelude.Hashable ClusteringKey where
  hashWithSalt :: Int -> ClusteringKey -> Int
hashWithSalt Int
_salt ClusteringKey' {Text
SortOrder
orderBy :: SortOrder
name :: Text
$sel:orderBy:ClusteringKey' :: ClusteringKey -> SortOrder
$sel:name:ClusteringKey' :: ClusteringKey -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` SortOrder
orderBy

instance Prelude.NFData ClusteringKey where
  rnf :: ClusteringKey -> ()
rnf ClusteringKey' {Text
SortOrder
orderBy :: SortOrder
name :: Text
$sel:orderBy:ClusteringKey' :: ClusteringKey -> SortOrder
$sel:name:ClusteringKey' :: ClusteringKey -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
name seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf SortOrder
orderBy

instance Data.ToJSON ClusteringKey where
  toJSON :: ClusteringKey -> Value
toJSON ClusteringKey' {Text
SortOrder
orderBy :: SortOrder
name :: Text
$sel:orderBy:ClusteringKey' :: ClusteringKey -> SortOrder
$sel:name:ClusteringKey' :: ClusteringKey -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"orderBy" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= SortOrder
orderBy)
          ]
      )