{-# 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.SMS.Types.ServerGroup
-- 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.SMS.Types.ServerGroup where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SMS.Types.Server

-- | Logical grouping of servers.
--
-- /See:/ 'newServerGroup' smart constructor.
data ServerGroup = ServerGroup'
  { -- | The servers that belong to a server group.
    ServerGroup -> Maybe [Server]
serverList :: Prelude.Maybe [Server],
    -- | The name of a server group.
    ServerGroup -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The ID of a server group.
    ServerGroup -> Maybe Text
serverGroupId :: Prelude.Maybe Prelude.Text
  }
  deriving (ServerGroup -> ServerGroup -> Bool
(ServerGroup -> ServerGroup -> Bool)
-> (ServerGroup -> ServerGroup -> Bool) -> Eq ServerGroup
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ServerGroup -> ServerGroup -> Bool
$c/= :: ServerGroup -> ServerGroup -> Bool
== :: ServerGroup -> ServerGroup -> Bool
$c== :: ServerGroup -> ServerGroup -> Bool
Prelude.Eq, ReadPrec [ServerGroup]
ReadPrec ServerGroup
Int -> ReadS ServerGroup
ReadS [ServerGroup]
(Int -> ReadS ServerGroup)
-> ReadS [ServerGroup]
-> ReadPrec ServerGroup
-> ReadPrec [ServerGroup]
-> Read ServerGroup
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ServerGroup]
$creadListPrec :: ReadPrec [ServerGroup]
readPrec :: ReadPrec ServerGroup
$creadPrec :: ReadPrec ServerGroup
readList :: ReadS [ServerGroup]
$creadList :: ReadS [ServerGroup]
readsPrec :: Int -> ReadS ServerGroup
$creadsPrec :: Int -> ReadS ServerGroup
Prelude.Read, Int -> ServerGroup -> ShowS
[ServerGroup] -> ShowS
ServerGroup -> String
(Int -> ServerGroup -> ShowS)
-> (ServerGroup -> String)
-> ([ServerGroup] -> ShowS)
-> Show ServerGroup
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ServerGroup] -> ShowS
$cshowList :: [ServerGroup] -> ShowS
show :: ServerGroup -> String
$cshow :: ServerGroup -> String
showsPrec :: Int -> ServerGroup -> ShowS
$cshowsPrec :: Int -> ServerGroup -> ShowS
Prelude.Show, (forall x. ServerGroup -> Rep ServerGroup x)
-> (forall x. Rep ServerGroup x -> ServerGroup)
-> Generic ServerGroup
forall x. Rep ServerGroup x -> ServerGroup
forall x. ServerGroup -> Rep ServerGroup x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ServerGroup x -> ServerGroup
$cfrom :: forall x. ServerGroup -> Rep ServerGroup x
Prelude.Generic)

-- |
-- Create a value of 'ServerGroup' 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:
--
-- 'serverList', 'serverGroup_serverList' - The servers that belong to a server group.
--
-- 'name', 'serverGroup_name' - The name of a server group.
--
-- 'serverGroupId', 'serverGroup_serverGroupId' - The ID of a server group.
newServerGroup ::
  ServerGroup
newServerGroup :: ServerGroup
newServerGroup =
  ServerGroup' :: Maybe [Server] -> Maybe Text -> Maybe Text -> ServerGroup
ServerGroup'
    { $sel:serverList:ServerGroup' :: Maybe [Server]
serverList = Maybe [Server]
forall a. Maybe a
Prelude.Nothing,
      $sel:name:ServerGroup' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:serverGroupId:ServerGroup' :: Maybe Text
serverGroupId = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The servers that belong to a server group.
serverGroup_serverList :: Lens.Lens' ServerGroup (Prelude.Maybe [Server])
serverGroup_serverList :: (Maybe [Server] -> f (Maybe [Server]))
-> ServerGroup -> f ServerGroup
serverGroup_serverList = (ServerGroup -> Maybe [Server])
-> (ServerGroup -> Maybe [Server] -> ServerGroup)
-> Lens ServerGroup ServerGroup (Maybe [Server]) (Maybe [Server])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServerGroup' {Maybe [Server]
serverList :: Maybe [Server]
$sel:serverList:ServerGroup' :: ServerGroup -> Maybe [Server]
serverList} -> Maybe [Server]
serverList) (\s :: ServerGroup
s@ServerGroup' {} Maybe [Server]
a -> ServerGroup
s {$sel:serverList:ServerGroup' :: Maybe [Server]
serverList = Maybe [Server]
a} :: ServerGroup) ((Maybe [Server] -> f (Maybe [Server]))
 -> ServerGroup -> f ServerGroup)
-> ((Maybe [Server] -> f (Maybe [Server]))
    -> Maybe [Server] -> f (Maybe [Server]))
-> (Maybe [Server] -> f (Maybe [Server]))
-> ServerGroup
-> f ServerGroup
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Server] [Server] [Server] [Server]
-> Iso
     (Maybe [Server]) (Maybe [Server]) (Maybe [Server]) (Maybe [Server])
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 [Server] [Server] [Server] [Server]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of a server group.
serverGroup_name :: Lens.Lens' ServerGroup (Prelude.Maybe Prelude.Text)
serverGroup_name :: (Maybe Text -> f (Maybe Text)) -> ServerGroup -> f ServerGroup
serverGroup_name = (ServerGroup -> Maybe Text)
-> (ServerGroup -> Maybe Text -> ServerGroup)
-> Lens ServerGroup ServerGroup (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServerGroup' {Maybe Text
name :: Maybe Text
$sel:name:ServerGroup' :: ServerGroup -> Maybe Text
name} -> Maybe Text
name) (\s :: ServerGroup
s@ServerGroup' {} Maybe Text
a -> ServerGroup
s {$sel:name:ServerGroup' :: Maybe Text
name = Maybe Text
a} :: ServerGroup)

-- | The ID of a server group.
serverGroup_serverGroupId :: Lens.Lens' ServerGroup (Prelude.Maybe Prelude.Text)
serverGroup_serverGroupId :: (Maybe Text -> f (Maybe Text)) -> ServerGroup -> f ServerGroup
serverGroup_serverGroupId = (ServerGroup -> Maybe Text)
-> (ServerGroup -> Maybe Text -> ServerGroup)
-> Lens ServerGroup ServerGroup (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServerGroup' {Maybe Text
serverGroupId :: Maybe Text
$sel:serverGroupId:ServerGroup' :: ServerGroup -> Maybe Text
serverGroupId} -> Maybe Text
serverGroupId) (\s :: ServerGroup
s@ServerGroup' {} Maybe Text
a -> ServerGroup
s {$sel:serverGroupId:ServerGroup' :: Maybe Text
serverGroupId = Maybe Text
a} :: ServerGroup)

instance Core.FromJSON ServerGroup where
  parseJSON :: Value -> Parser ServerGroup
parseJSON =
    String
-> (Object -> Parser ServerGroup) -> Value -> Parser ServerGroup
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ServerGroup"
      ( \Object
x ->
          Maybe [Server] -> Maybe Text -> Maybe Text -> ServerGroup
ServerGroup'
            (Maybe [Server] -> Maybe Text -> Maybe Text -> ServerGroup)
-> Parser (Maybe [Server])
-> Parser (Maybe Text -> Maybe Text -> ServerGroup)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [Server]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"serverList" Parser (Maybe (Maybe [Server]))
-> Maybe [Server] -> Parser (Maybe [Server])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Server]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe Text -> Maybe Text -> ServerGroup)
-> Parser (Maybe Text) -> Parser (Maybe Text -> ServerGroup)
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 Text -> ServerGroup)
-> Parser (Maybe Text) -> Parser ServerGroup
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
"serverGroupId")
      )

instance Prelude.Hashable ServerGroup

instance Prelude.NFData ServerGroup

instance Core.ToJSON ServerGroup where
  toJSON :: ServerGroup -> Value
toJSON ServerGroup' {Maybe [Server]
Maybe Text
serverGroupId :: Maybe Text
name :: Maybe Text
serverList :: Maybe [Server]
$sel:serverGroupId:ServerGroup' :: ServerGroup -> Maybe Text
$sel:name:ServerGroup' :: ServerGroup -> Maybe Text
$sel:serverList:ServerGroup' :: ServerGroup -> Maybe [Server]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"serverList" Text -> [Server] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Server] -> Pair) -> Maybe [Server] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Server]
serverList,
            (Text
"name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
name,
            (Text
"serverGroupId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
serverGroupId
          ]
      )