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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.MemoryDb.Types.Node
import qualified Amazonka.Prelude as Prelude

-- | Represents a collection of nodes in a cluster. One node in the node
-- group is the read\/write primary node. All the other nodes are read-only
-- Replica nodes.
--
-- /See:/ 'newShard' smart constructor.
data Shard = Shard'
  { -- | The name of the shard
    Shard -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | A list containing information about individual nodes within the shard
    Shard -> Maybe [Node]
nodes :: Prelude.Maybe [Node],
    -- | The number of nodes in the shard
    Shard -> Maybe Int
numberOfNodes :: Prelude.Maybe Prelude.Int,
    -- | The keyspace for this shard.
    Shard -> Maybe Text
slots :: Prelude.Maybe Prelude.Text,
    -- | The current state of this replication group - creating, available,
    -- modifying, deleting.
    Shard -> Maybe Text
status :: Prelude.Maybe Prelude.Text
  }
  deriving (Shard -> Shard -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Shard -> Shard -> Bool
$c/= :: Shard -> Shard -> Bool
== :: Shard -> Shard -> Bool
$c== :: Shard -> Shard -> Bool
Prelude.Eq, ReadPrec [Shard]
ReadPrec Shard
Int -> ReadS Shard
ReadS [Shard]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Shard]
$creadListPrec :: ReadPrec [Shard]
readPrec :: ReadPrec Shard
$creadPrec :: ReadPrec Shard
readList :: ReadS [Shard]
$creadList :: ReadS [Shard]
readsPrec :: Int -> ReadS Shard
$creadsPrec :: Int -> ReadS Shard
Prelude.Read, Int -> Shard -> ShowS
[Shard] -> ShowS
Shard -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Shard] -> ShowS
$cshowList :: [Shard] -> ShowS
show :: Shard -> String
$cshow :: Shard -> String
showsPrec :: Int -> Shard -> ShowS
$cshowsPrec :: Int -> Shard -> ShowS
Prelude.Show, forall x. Rep Shard x -> Shard
forall x. Shard -> Rep Shard x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Shard x -> Shard
$cfrom :: forall x. Shard -> Rep Shard x
Prelude.Generic)

-- |
-- Create a value of 'Shard' 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', 'shard_name' - The name of the shard
--
-- 'nodes', 'shard_nodes' - A list containing information about individual nodes within the shard
--
-- 'numberOfNodes', 'shard_numberOfNodes' - The number of nodes in the shard
--
-- 'slots', 'shard_slots' - The keyspace for this shard.
--
-- 'status', 'shard_status' - The current state of this replication group - creating, available,
-- modifying, deleting.
newShard ::
  Shard
newShard :: Shard
newShard =
  Shard'
    { $sel:name:Shard' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:nodes:Shard' :: Maybe [Node]
nodes = forall a. Maybe a
Prelude.Nothing,
      $sel:numberOfNodes:Shard' :: Maybe Int
numberOfNodes = forall a. Maybe a
Prelude.Nothing,
      $sel:slots:Shard' :: Maybe Text
slots = forall a. Maybe a
Prelude.Nothing,
      $sel:status:Shard' :: Maybe Text
status = forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the shard
shard_name :: Lens.Lens' Shard (Prelude.Maybe Prelude.Text)
shard_name :: Lens' Shard (Maybe Text)
shard_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Shard' {Maybe Text
name :: Maybe Text
$sel:name:Shard' :: Shard -> Maybe Text
name} -> Maybe Text
name) (\s :: Shard
s@Shard' {} Maybe Text
a -> Shard
s {$sel:name:Shard' :: Maybe Text
name = Maybe Text
a} :: Shard)

-- | A list containing information about individual nodes within the shard
shard_nodes :: Lens.Lens' Shard (Prelude.Maybe [Node])
shard_nodes :: Lens' Shard (Maybe [Node])
shard_nodes = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Shard' {Maybe [Node]
nodes :: Maybe [Node]
$sel:nodes:Shard' :: Shard -> Maybe [Node]
nodes} -> Maybe [Node]
nodes) (\s :: Shard
s@Shard' {} Maybe [Node]
a -> Shard
s {$sel:nodes:Shard' :: Maybe [Node]
nodes = Maybe [Node]
a} :: Shard) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The number of nodes in the shard
shard_numberOfNodes :: Lens.Lens' Shard (Prelude.Maybe Prelude.Int)
shard_numberOfNodes :: Lens' Shard (Maybe Int)
shard_numberOfNodes = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Shard' {Maybe Int
numberOfNodes :: Maybe Int
$sel:numberOfNodes:Shard' :: Shard -> Maybe Int
numberOfNodes} -> Maybe Int
numberOfNodes) (\s :: Shard
s@Shard' {} Maybe Int
a -> Shard
s {$sel:numberOfNodes:Shard' :: Maybe Int
numberOfNodes = Maybe Int
a} :: Shard)

-- | The keyspace for this shard.
shard_slots :: Lens.Lens' Shard (Prelude.Maybe Prelude.Text)
shard_slots :: Lens' Shard (Maybe Text)
shard_slots = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Shard' {Maybe Text
slots :: Maybe Text
$sel:slots:Shard' :: Shard -> Maybe Text
slots} -> Maybe Text
slots) (\s :: Shard
s@Shard' {} Maybe Text
a -> Shard
s {$sel:slots:Shard' :: Maybe Text
slots = Maybe Text
a} :: Shard)

-- | The current state of this replication group - creating, available,
-- modifying, deleting.
shard_status :: Lens.Lens' Shard (Prelude.Maybe Prelude.Text)
shard_status :: Lens' Shard (Maybe Text)
shard_status = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Shard' {Maybe Text
status :: Maybe Text
$sel:status:Shard' :: Shard -> Maybe Text
status} -> Maybe Text
status) (\s :: Shard
s@Shard' {} Maybe Text
a -> Shard
s {$sel:status:Shard' :: Maybe Text
status = Maybe Text
a} :: Shard)

instance Data.FromJSON Shard where
  parseJSON :: Value -> Parser Shard
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Shard"
      ( \Object
x ->
          Maybe Text
-> Maybe [Node] -> Maybe Int -> Maybe Text -> Maybe Text -> Shard
Shard'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe 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 (Maybe a)
Data..:? Key
"Nodes" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"NumberOfNodes")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Slots")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Status")
      )

instance Prelude.Hashable Shard where
  hashWithSalt :: Int -> Shard -> Int
hashWithSalt Int
_salt Shard' {Maybe Int
Maybe [Node]
Maybe Text
status :: Maybe Text
slots :: Maybe Text
numberOfNodes :: Maybe Int
nodes :: Maybe [Node]
name :: Maybe Text
$sel:status:Shard' :: Shard -> Maybe Text
$sel:slots:Shard' :: Shard -> Maybe Text
$sel:numberOfNodes:Shard' :: Shard -> Maybe Int
$sel:nodes:Shard' :: Shard -> Maybe [Node]
$sel:name:Shard' :: Shard -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Node]
nodes
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
numberOfNodes
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
slots
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
status

instance Prelude.NFData Shard where
  rnf :: Shard -> ()
rnf Shard' {Maybe Int
Maybe [Node]
Maybe Text
status :: Maybe Text
slots :: Maybe Text
numberOfNodes :: Maybe Int
nodes :: Maybe [Node]
name :: Maybe Text
$sel:status:Shard' :: Shard -> Maybe Text
$sel:slots:Shard' :: Shard -> Maybe Text
$sel:numberOfNodes:Shard' :: Shard -> Maybe Int
$sel:nodes:Shard' :: Shard -> Maybe [Node]
$sel:name:Shard' :: Shard -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Node]
nodes
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
numberOfNodes
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
slots
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
status