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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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 current state of this replication group - creating, available,
    -- modifying, deleting.
    Shard -> Maybe Text
status :: Prelude.Maybe Prelude.Text,
    -- | The keyspace for this shard.
    Shard -> Maybe Text
slots :: Prelude.Maybe Prelude.Text,
    -- | The number of nodes in the shard
    Shard -> Maybe Int
numberOfNodes :: Prelude.Maybe Prelude.Int,
    -- | 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]
  }
  deriving (Shard -> Shard -> Bool
(Shard -> Shard -> Bool) -> (Shard -> Shard -> Bool) -> Eq Shard
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]
(Int -> ReadS Shard)
-> ReadS [Shard]
-> ReadPrec Shard
-> ReadPrec [Shard]
-> Read 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
(Int -> Shard -> ShowS)
-> (Shard -> String) -> ([Shard] -> ShowS) -> Show Shard
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. Shard -> Rep Shard x)
-> (forall x. Rep Shard x -> Shard) -> Generic Shard
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:
--
-- 'status', 'shard_status' - The current state of this replication group - creating, available,
-- modifying, deleting.
--
-- 'slots', 'shard_slots' - The keyspace for this shard.
--
-- 'numberOfNodes', 'shard_numberOfNodes' - The number of nodes in the shard
--
-- 'name', 'shard_name' - The name of the shard
--
-- 'nodes', 'shard_nodes' - A list containing information about individual nodes within the shard
newShard ::
  Shard
newShard :: Shard
newShard =
  Shard' :: Maybe Text
-> Maybe Text -> Maybe Int -> Maybe Text -> Maybe [Node] -> Shard
Shard'
    { $sel:status:Shard' :: Maybe Text
status = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:slots:Shard' :: Maybe Text
slots = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:numberOfNodes:Shard' :: Maybe Int
numberOfNodes = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:name:Shard' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:nodes:Shard' :: Maybe [Node]
nodes = Maybe [Node]
forall a. Maybe a
Prelude.Nothing
    }

-- | The current state of this replication group - creating, available,
-- modifying, deleting.
shard_status :: Lens.Lens' Shard (Prelude.Maybe Prelude.Text)
shard_status :: (Maybe Text -> f (Maybe Text)) -> Shard -> f Shard
shard_status = (Shard -> Maybe Text)
-> (Shard -> Maybe Text -> Shard)
-> Lens Shard Shard (Maybe Text) (Maybe Text)
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)

-- | The keyspace for this shard.
shard_slots :: Lens.Lens' Shard (Prelude.Maybe Prelude.Text)
shard_slots :: (Maybe Text -> f (Maybe Text)) -> Shard -> f Shard
shard_slots = (Shard -> Maybe Text)
-> (Shard -> Maybe Text -> Shard)
-> Lens Shard Shard (Maybe Text) (Maybe Text)
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 number of nodes in the shard
shard_numberOfNodes :: Lens.Lens' Shard (Prelude.Maybe Prelude.Int)
shard_numberOfNodes :: (Maybe Int -> f (Maybe Int)) -> Shard -> f Shard
shard_numberOfNodes = (Shard -> Maybe Int)
-> (Shard -> Maybe Int -> Shard)
-> Lens Shard Shard (Maybe Int) (Maybe Int)
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 name of the shard
shard_name :: Lens.Lens' Shard (Prelude.Maybe Prelude.Text)
shard_name :: (Maybe Text -> f (Maybe Text)) -> Shard -> f Shard
shard_name = (Shard -> Maybe Text)
-> (Shard -> Maybe Text -> Shard)
-> Lens Shard Shard (Maybe Text) (Maybe Text)
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 :: (Maybe [Node] -> f (Maybe [Node])) -> Shard -> f Shard
shard_nodes = (Shard -> Maybe [Node])
-> (Shard -> Maybe [Node] -> Shard)
-> Lens Shard Shard (Maybe [Node]) (Maybe [Node])
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) ((Maybe [Node] -> f (Maybe [Node])) -> Shard -> f Shard)
-> ((Maybe [Node] -> f (Maybe [Node]))
    -> Maybe [Node] -> f (Maybe [Node]))
-> (Maybe [Node] -> f (Maybe [Node]))
-> Shard
-> f Shard
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Node] [Node] [Node] [Node]
-> Iso (Maybe [Node]) (Maybe [Node]) (Maybe [Node]) (Maybe [Node])
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 AnIso [Node] [Node] [Node] [Node]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable Shard

instance Prelude.NFData Shard