{-# 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.Glue.Types.PartitionIndex
-- 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.Glue.Types.PartitionIndex 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

-- | A structure for a partition index.
--
-- /See:/ 'newPartitionIndex' smart constructor.
data PartitionIndex = PartitionIndex'
  { -- | The keys for the partition index.
    PartitionIndex -> NonEmpty Text
keys :: Prelude.NonEmpty Prelude.Text,
    -- | The name of the partition index.
    PartitionIndex -> Text
indexName :: Prelude.Text
  }
  deriving (PartitionIndex -> PartitionIndex -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PartitionIndex -> PartitionIndex -> Bool
$c/= :: PartitionIndex -> PartitionIndex -> Bool
== :: PartitionIndex -> PartitionIndex -> Bool
$c== :: PartitionIndex -> PartitionIndex -> Bool
Prelude.Eq, ReadPrec [PartitionIndex]
ReadPrec PartitionIndex
Int -> ReadS PartitionIndex
ReadS [PartitionIndex]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PartitionIndex]
$creadListPrec :: ReadPrec [PartitionIndex]
readPrec :: ReadPrec PartitionIndex
$creadPrec :: ReadPrec PartitionIndex
readList :: ReadS [PartitionIndex]
$creadList :: ReadS [PartitionIndex]
readsPrec :: Int -> ReadS PartitionIndex
$creadsPrec :: Int -> ReadS PartitionIndex
Prelude.Read, Int -> PartitionIndex -> ShowS
[PartitionIndex] -> ShowS
PartitionIndex -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PartitionIndex] -> ShowS
$cshowList :: [PartitionIndex] -> ShowS
show :: PartitionIndex -> String
$cshow :: PartitionIndex -> String
showsPrec :: Int -> PartitionIndex -> ShowS
$cshowsPrec :: Int -> PartitionIndex -> ShowS
Prelude.Show, forall x. Rep PartitionIndex x -> PartitionIndex
forall x. PartitionIndex -> Rep PartitionIndex x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PartitionIndex x -> PartitionIndex
$cfrom :: forall x. PartitionIndex -> Rep PartitionIndex x
Prelude.Generic)

-- |
-- Create a value of 'PartitionIndex' 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:
--
-- 'keys', 'partitionIndex_keys' - The keys for the partition index.
--
-- 'indexName', 'partitionIndex_indexName' - The name of the partition index.
newPartitionIndex ::
  -- | 'keys'
  Prelude.NonEmpty Prelude.Text ->
  -- | 'indexName'
  Prelude.Text ->
  PartitionIndex
newPartitionIndex :: NonEmpty Text -> Text -> PartitionIndex
newPartitionIndex NonEmpty Text
pKeys_ Text
pIndexName_ =
  PartitionIndex'
    { $sel:keys:PartitionIndex' :: NonEmpty Text
keys = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pKeys_,
      $sel:indexName:PartitionIndex' :: Text
indexName = Text
pIndexName_
    }

-- | The keys for the partition index.
partitionIndex_keys :: Lens.Lens' PartitionIndex (Prelude.NonEmpty Prelude.Text)
partitionIndex_keys :: Lens' PartitionIndex (NonEmpty Text)
partitionIndex_keys = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PartitionIndex' {NonEmpty Text
keys :: NonEmpty Text
$sel:keys:PartitionIndex' :: PartitionIndex -> NonEmpty Text
keys} -> NonEmpty Text
keys) (\s :: PartitionIndex
s@PartitionIndex' {} NonEmpty Text
a -> PartitionIndex
s {$sel:keys:PartitionIndex' :: NonEmpty Text
keys = NonEmpty Text
a} :: PartitionIndex) 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

-- | The name of the partition index.
partitionIndex_indexName :: Lens.Lens' PartitionIndex Prelude.Text
partitionIndex_indexName :: Lens' PartitionIndex Text
partitionIndex_indexName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PartitionIndex' {Text
indexName :: Text
$sel:indexName:PartitionIndex' :: PartitionIndex -> Text
indexName} -> Text
indexName) (\s :: PartitionIndex
s@PartitionIndex' {} Text
a -> PartitionIndex
s {$sel:indexName:PartitionIndex' :: Text
indexName = Text
a} :: PartitionIndex)

instance Prelude.Hashable PartitionIndex where
  hashWithSalt :: Int -> PartitionIndex -> Int
hashWithSalt Int
_salt PartitionIndex' {NonEmpty Text
Text
indexName :: Text
keys :: NonEmpty Text
$sel:indexName:PartitionIndex' :: PartitionIndex -> Text
$sel:keys:PartitionIndex' :: PartitionIndex -> NonEmpty Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
keys
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
indexName

instance Prelude.NFData PartitionIndex where
  rnf :: PartitionIndex -> ()
rnf PartitionIndex' {NonEmpty Text
Text
indexName :: Text
keys :: NonEmpty Text
$sel:indexName:PartitionIndex' :: PartitionIndex -> Text
$sel:keys:PartitionIndex' :: PartitionIndex -> NonEmpty Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Text
keys
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
indexName

instance Data.ToJSON PartitionIndex where
  toJSON :: PartitionIndex -> Value
toJSON PartitionIndex' {NonEmpty Text
Text
indexName :: Text
keys :: NonEmpty Text
$sel:indexName:PartitionIndex' :: PartitionIndex -> Text
$sel:keys:PartitionIndex' :: PartitionIndex -> NonEmpty Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Keys" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
keys),
            forall a. a -> Maybe a
Prelude.Just (Key
"IndexName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
indexName)
          ]
      )