{-# 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.SecurityHub.Types.LoadBalancerState
-- 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.SecurityHub.Types.LoadBalancerState where

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

-- | Information about the state of the load balancer.
--
-- /See:/ 'newLoadBalancerState' smart constructor.
data LoadBalancerState = LoadBalancerState'
  { -- | A description of the state.
    LoadBalancerState -> Maybe Text
reason :: Prelude.Maybe Prelude.Text,
    -- | The state code. The initial state of the load balancer is provisioning.
    --
    -- After the load balancer is fully set up and ready to route traffic, its
    -- state is active.
    --
    -- If the load balancer could not be set up, its state is failed.
    LoadBalancerState -> Maybe Text
code :: Prelude.Maybe Prelude.Text
  }
  deriving (LoadBalancerState -> LoadBalancerState -> Bool
(LoadBalancerState -> LoadBalancerState -> Bool)
-> (LoadBalancerState -> LoadBalancerState -> Bool)
-> Eq LoadBalancerState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LoadBalancerState -> LoadBalancerState -> Bool
$c/= :: LoadBalancerState -> LoadBalancerState -> Bool
== :: LoadBalancerState -> LoadBalancerState -> Bool
$c== :: LoadBalancerState -> LoadBalancerState -> Bool
Prelude.Eq, ReadPrec [LoadBalancerState]
ReadPrec LoadBalancerState
Int -> ReadS LoadBalancerState
ReadS [LoadBalancerState]
(Int -> ReadS LoadBalancerState)
-> ReadS [LoadBalancerState]
-> ReadPrec LoadBalancerState
-> ReadPrec [LoadBalancerState]
-> Read LoadBalancerState
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LoadBalancerState]
$creadListPrec :: ReadPrec [LoadBalancerState]
readPrec :: ReadPrec LoadBalancerState
$creadPrec :: ReadPrec LoadBalancerState
readList :: ReadS [LoadBalancerState]
$creadList :: ReadS [LoadBalancerState]
readsPrec :: Int -> ReadS LoadBalancerState
$creadsPrec :: Int -> ReadS LoadBalancerState
Prelude.Read, Int -> LoadBalancerState -> ShowS
[LoadBalancerState] -> ShowS
LoadBalancerState -> String
(Int -> LoadBalancerState -> ShowS)
-> (LoadBalancerState -> String)
-> ([LoadBalancerState] -> ShowS)
-> Show LoadBalancerState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LoadBalancerState] -> ShowS
$cshowList :: [LoadBalancerState] -> ShowS
show :: LoadBalancerState -> String
$cshow :: LoadBalancerState -> String
showsPrec :: Int -> LoadBalancerState -> ShowS
$cshowsPrec :: Int -> LoadBalancerState -> ShowS
Prelude.Show, (forall x. LoadBalancerState -> Rep LoadBalancerState x)
-> (forall x. Rep LoadBalancerState x -> LoadBalancerState)
-> Generic LoadBalancerState
forall x. Rep LoadBalancerState x -> LoadBalancerState
forall x. LoadBalancerState -> Rep LoadBalancerState x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LoadBalancerState x -> LoadBalancerState
$cfrom :: forall x. LoadBalancerState -> Rep LoadBalancerState x
Prelude.Generic)

-- |
-- Create a value of 'LoadBalancerState' 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:
--
-- 'reason', 'loadBalancerState_reason' - A description of the state.
--
-- 'code', 'loadBalancerState_code' - The state code. The initial state of the load balancer is provisioning.
--
-- After the load balancer is fully set up and ready to route traffic, its
-- state is active.
--
-- If the load balancer could not be set up, its state is failed.
newLoadBalancerState ::
  LoadBalancerState
newLoadBalancerState :: LoadBalancerState
newLoadBalancerState =
  LoadBalancerState' :: Maybe Text -> Maybe Text -> LoadBalancerState
LoadBalancerState'
    { $sel:reason:LoadBalancerState' :: Maybe Text
reason = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:code:LoadBalancerState' :: Maybe Text
code = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | A description of the state.
loadBalancerState_reason :: Lens.Lens' LoadBalancerState (Prelude.Maybe Prelude.Text)
loadBalancerState_reason :: (Maybe Text -> f (Maybe Text))
-> LoadBalancerState -> f LoadBalancerState
loadBalancerState_reason = (LoadBalancerState -> Maybe Text)
-> (LoadBalancerState -> Maybe Text -> LoadBalancerState)
-> Lens
     LoadBalancerState LoadBalancerState (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LoadBalancerState' {Maybe Text
reason :: Maybe Text
$sel:reason:LoadBalancerState' :: LoadBalancerState -> Maybe Text
reason} -> Maybe Text
reason) (\s :: LoadBalancerState
s@LoadBalancerState' {} Maybe Text
a -> LoadBalancerState
s {$sel:reason:LoadBalancerState' :: Maybe Text
reason = Maybe Text
a} :: LoadBalancerState)

-- | The state code. The initial state of the load balancer is provisioning.
--
-- After the load balancer is fully set up and ready to route traffic, its
-- state is active.
--
-- If the load balancer could not be set up, its state is failed.
loadBalancerState_code :: Lens.Lens' LoadBalancerState (Prelude.Maybe Prelude.Text)
loadBalancerState_code :: (Maybe Text -> f (Maybe Text))
-> LoadBalancerState -> f LoadBalancerState
loadBalancerState_code = (LoadBalancerState -> Maybe Text)
-> (LoadBalancerState -> Maybe Text -> LoadBalancerState)
-> Lens
     LoadBalancerState LoadBalancerState (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LoadBalancerState' {Maybe Text
code :: Maybe Text
$sel:code:LoadBalancerState' :: LoadBalancerState -> Maybe Text
code} -> Maybe Text
code) (\s :: LoadBalancerState
s@LoadBalancerState' {} Maybe Text
a -> LoadBalancerState
s {$sel:code:LoadBalancerState' :: Maybe Text
code = Maybe Text
a} :: LoadBalancerState)

instance Core.FromJSON LoadBalancerState where
  parseJSON :: Value -> Parser LoadBalancerState
parseJSON =
    String
-> (Object -> Parser LoadBalancerState)
-> Value
-> Parser LoadBalancerState
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"LoadBalancerState"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> LoadBalancerState
LoadBalancerState'
            (Maybe Text -> Maybe Text -> LoadBalancerState)
-> Parser (Maybe Text) -> Parser (Maybe Text -> LoadBalancerState)
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
"Reason")
            Parser (Maybe Text -> LoadBalancerState)
-> Parser (Maybe Text) -> Parser LoadBalancerState
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
"Code")
      )

instance Prelude.Hashable LoadBalancerState

instance Prelude.NFData LoadBalancerState

instance Core.ToJSON LoadBalancerState where
  toJSON :: LoadBalancerState -> Value
toJSON LoadBalancerState' {Maybe Text
code :: Maybe Text
reason :: Maybe Text
$sel:code:LoadBalancerState' :: LoadBalancerState -> Maybe Text
$sel:reason:LoadBalancerState' :: LoadBalancerState -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Reason" 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
reason,
            (Text
"Code" 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
code
          ]
      )