{-# 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.PartitionKey
-- 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.PartitionKey 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

-- | The partition key portion of the primary key is required and determines
-- how Amazon Keyspaces stores the data. The partition key can be a single
-- column, or it can be a compound value composed of two or more columns.
--
-- /See:/ 'newPartitionKey' smart constructor.
data PartitionKey = PartitionKey'
  { -- | The name(s) of the partition key column(s).
    PartitionKey -> Text
name :: Prelude.Text
  }
  deriving (PartitionKey -> PartitionKey -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PartitionKey -> PartitionKey -> Bool
$c/= :: PartitionKey -> PartitionKey -> Bool
== :: PartitionKey -> PartitionKey -> Bool
$c== :: PartitionKey -> PartitionKey -> Bool
Prelude.Eq, ReadPrec [PartitionKey]
ReadPrec PartitionKey
Int -> ReadS PartitionKey
ReadS [PartitionKey]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PartitionKey]
$creadListPrec :: ReadPrec [PartitionKey]
readPrec :: ReadPrec PartitionKey
$creadPrec :: ReadPrec PartitionKey
readList :: ReadS [PartitionKey]
$creadList :: ReadS [PartitionKey]
readsPrec :: Int -> ReadS PartitionKey
$creadsPrec :: Int -> ReadS PartitionKey
Prelude.Read, Int -> PartitionKey -> ShowS
[PartitionKey] -> ShowS
PartitionKey -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PartitionKey] -> ShowS
$cshowList :: [PartitionKey] -> ShowS
show :: PartitionKey -> String
$cshow :: PartitionKey -> String
showsPrec :: Int -> PartitionKey -> ShowS
$cshowsPrec :: Int -> PartitionKey -> ShowS
Prelude.Show, forall x. Rep PartitionKey x -> PartitionKey
forall x. PartitionKey -> Rep PartitionKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PartitionKey x -> PartitionKey
$cfrom :: forall x. PartitionKey -> Rep PartitionKey x
Prelude.Generic)

-- |
-- Create a value of 'PartitionKey' 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', 'partitionKey_name' - The name(s) of the partition key column(s).
newPartitionKey ::
  -- | 'name'
  Prelude.Text ->
  PartitionKey
newPartitionKey :: Text -> PartitionKey
newPartitionKey Text
pName_ = PartitionKey' {$sel:name:PartitionKey' :: Text
name = Text
pName_}

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

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

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

instance Prelude.NFData PartitionKey where
  rnf :: PartitionKey -> ()
rnf PartitionKey' {Text
name :: Text
$sel:name:PartitionKey' :: PartitionKey -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
name

instance Data.ToJSON PartitionKey where
  toJSON :: PartitionKey -> Value
toJSON PartitionKey' {Text
name :: Text
$sel:name:PartitionKey' :: PartitionKey -> 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)]
      )