{-# 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.MemoryDb.Types.ShardConfiguration
-- 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.MemoryDb.Types.ShardConfiguration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Shard configuration options. Each shard configuration has the following:
-- Slots and ReplicaCount.
--
-- /See:/ 'newShardConfiguration' smart constructor.
data ShardConfiguration = ShardConfiguration'
  { -- | A string that specifies the keyspace for a particular node group.
    -- Keyspaces range from 0 to 16,383. The string is in the format
    -- startkey-endkey.
    ShardConfiguration -> Maybe Text
slots :: Prelude.Maybe Prelude.Text,
    -- | The number of read replica nodes in this shard.
    ShardConfiguration -> Maybe Int
replicaCount :: Prelude.Maybe Prelude.Int
  }
  deriving (ShardConfiguration -> ShardConfiguration -> Bool
(ShardConfiguration -> ShardConfiguration -> Bool)
-> (ShardConfiguration -> ShardConfiguration -> Bool)
-> Eq ShardConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ShardConfiguration -> ShardConfiguration -> Bool
$c/= :: ShardConfiguration -> ShardConfiguration -> Bool
== :: ShardConfiguration -> ShardConfiguration -> Bool
$c== :: ShardConfiguration -> ShardConfiguration -> Bool
Prelude.Eq, ReadPrec [ShardConfiguration]
ReadPrec ShardConfiguration
Int -> ReadS ShardConfiguration
ReadS [ShardConfiguration]
(Int -> ReadS ShardConfiguration)
-> ReadS [ShardConfiguration]
-> ReadPrec ShardConfiguration
-> ReadPrec [ShardConfiguration]
-> Read ShardConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ShardConfiguration]
$creadListPrec :: ReadPrec [ShardConfiguration]
readPrec :: ReadPrec ShardConfiguration
$creadPrec :: ReadPrec ShardConfiguration
readList :: ReadS [ShardConfiguration]
$creadList :: ReadS [ShardConfiguration]
readsPrec :: Int -> ReadS ShardConfiguration
$creadsPrec :: Int -> ReadS ShardConfiguration
Prelude.Read, Int -> ShardConfiguration -> ShowS
[ShardConfiguration] -> ShowS
ShardConfiguration -> String
(Int -> ShardConfiguration -> ShowS)
-> (ShardConfiguration -> String)
-> ([ShardConfiguration] -> ShowS)
-> Show ShardConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ShardConfiguration] -> ShowS
$cshowList :: [ShardConfiguration] -> ShowS
show :: ShardConfiguration -> String
$cshow :: ShardConfiguration -> String
showsPrec :: Int -> ShardConfiguration -> ShowS
$cshowsPrec :: Int -> ShardConfiguration -> ShowS
Prelude.Show, (forall x. ShardConfiguration -> Rep ShardConfiguration x)
-> (forall x. Rep ShardConfiguration x -> ShardConfiguration)
-> Generic ShardConfiguration
forall x. Rep ShardConfiguration x -> ShardConfiguration
forall x. ShardConfiguration -> Rep ShardConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ShardConfiguration x -> ShardConfiguration
$cfrom :: forall x. ShardConfiguration -> Rep ShardConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'ShardConfiguration' 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:
--
-- 'slots', 'shardConfiguration_slots' - A string that specifies the keyspace for a particular node group.
-- Keyspaces range from 0 to 16,383. The string is in the format
-- startkey-endkey.
--
-- 'replicaCount', 'shardConfiguration_replicaCount' - The number of read replica nodes in this shard.
newShardConfiguration ::
  ShardConfiguration
newShardConfiguration :: ShardConfiguration
newShardConfiguration =
  ShardConfiguration' :: Maybe Text -> Maybe Int -> ShardConfiguration
ShardConfiguration'
    { $sel:slots:ShardConfiguration' :: Maybe Text
slots = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:replicaCount:ShardConfiguration' :: Maybe Int
replicaCount = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | A string that specifies the keyspace for a particular node group.
-- Keyspaces range from 0 to 16,383. The string is in the format
-- startkey-endkey.
shardConfiguration_slots :: Lens.Lens' ShardConfiguration (Prelude.Maybe Prelude.Text)
shardConfiguration_slots :: (Maybe Text -> f (Maybe Text))
-> ShardConfiguration -> f ShardConfiguration
shardConfiguration_slots = (ShardConfiguration -> Maybe Text)
-> (ShardConfiguration -> Maybe Text -> ShardConfiguration)
-> Lens
     ShardConfiguration ShardConfiguration (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ShardConfiguration' {Maybe Text
slots :: Maybe Text
$sel:slots:ShardConfiguration' :: ShardConfiguration -> Maybe Text
slots} -> Maybe Text
slots) (\s :: ShardConfiguration
s@ShardConfiguration' {} Maybe Text
a -> ShardConfiguration
s {$sel:slots:ShardConfiguration' :: Maybe Text
slots = Maybe Text
a} :: ShardConfiguration)

-- | The number of read replica nodes in this shard.
shardConfiguration_replicaCount :: Lens.Lens' ShardConfiguration (Prelude.Maybe Prelude.Int)
shardConfiguration_replicaCount :: (Maybe Int -> f (Maybe Int))
-> ShardConfiguration -> f ShardConfiguration
shardConfiguration_replicaCount = (ShardConfiguration -> Maybe Int)
-> (ShardConfiguration -> Maybe Int -> ShardConfiguration)
-> Lens
     ShardConfiguration ShardConfiguration (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ShardConfiguration' {Maybe Int
replicaCount :: Maybe Int
$sel:replicaCount:ShardConfiguration' :: ShardConfiguration -> Maybe Int
replicaCount} -> Maybe Int
replicaCount) (\s :: ShardConfiguration
s@ShardConfiguration' {} Maybe Int
a -> ShardConfiguration
s {$sel:replicaCount:ShardConfiguration' :: Maybe Int
replicaCount = Maybe Int
a} :: ShardConfiguration)

instance Core.FromJSON ShardConfiguration where
  parseJSON :: Value -> Parser ShardConfiguration
parseJSON =
    String
-> (Object -> Parser ShardConfiguration)
-> Value
-> Parser ShardConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ShardConfiguration"
      ( \Object
x ->
          Maybe Text -> Maybe Int -> ShardConfiguration
ShardConfiguration'
            (Maybe Text -> Maybe Int -> ShardConfiguration)
-> Parser (Maybe Text) -> Parser (Maybe Int -> ShardConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Slots")
            Parser (Maybe Int -> ShardConfiguration)
-> Parser (Maybe Int) -> Parser ShardConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ReplicaCount")
      )

instance Prelude.Hashable ShardConfiguration

instance Prelude.NFData ShardConfiguration