{-# 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-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Glue.Types.PartitionIndex where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(PartitionIndex -> PartitionIndex -> Bool)
-> (PartitionIndex -> PartitionIndex -> Bool) -> Eq PartitionIndex
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]
(Int -> ReadS PartitionIndex)
-> ReadS [PartitionIndex]
-> ReadPrec PartitionIndex
-> ReadPrec [PartitionIndex]
-> Read 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
(Int -> PartitionIndex -> ShowS)
-> (PartitionIndex -> String)
-> ([PartitionIndex] -> ShowS)
-> Show PartitionIndex
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. PartitionIndex -> Rep PartitionIndex x)
-> (forall x. Rep PartitionIndex x -> PartitionIndex)
-> Generic PartitionIndex
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' :: NonEmpty Text -> Text -> PartitionIndex
PartitionIndex'
    { $sel:keys:PartitionIndex' :: NonEmpty Text
keys = Tagged (NonEmpty Text) (Identity (NonEmpty Text))
-> Tagged (NonEmpty Text) (Identity (NonEmpty Text))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Text) (Identity (NonEmpty Text))
 -> Tagged (NonEmpty Text) (Identity (NonEmpty Text)))
-> NonEmpty Text -> NonEmpty Text
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 :: (NonEmpty Text -> f (NonEmpty Text))
-> PartitionIndex -> f PartitionIndex
partitionIndex_keys = (PartitionIndex -> NonEmpty Text)
-> (PartitionIndex -> NonEmpty Text -> PartitionIndex)
-> Lens
     PartitionIndex PartitionIndex (NonEmpty Text) (NonEmpty Text)
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) ((NonEmpty Text -> f (NonEmpty Text))
 -> PartitionIndex -> f PartitionIndex)
-> ((NonEmpty Text -> f (NonEmpty Text))
    -> NonEmpty Text -> f (NonEmpty Text))
-> (NonEmpty Text -> f (NonEmpty Text))
-> PartitionIndex
-> f PartitionIndex
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Text -> f (NonEmpty Text))
-> NonEmpty Text -> f (NonEmpty Text)
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 :: (Text -> f Text) -> PartitionIndex -> f PartitionIndex
partitionIndex_indexName = (PartitionIndex -> Text)
-> (PartitionIndex -> Text -> PartitionIndex)
-> Lens PartitionIndex PartitionIndex Text Text
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

instance Prelude.NFData PartitionIndex

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Keys" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Text
keys),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"IndexName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
indexName)
          ]
      )