{-# 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.CloudWatchEvents.Types.RoutingConfig
-- 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.CloudWatchEvents.Types.RoutingConfig where

import Amazonka.CloudWatchEvents.Types.FailoverConfig
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | The routing configuration of the endpoint.
--
-- /See:/ 'newRoutingConfig' smart constructor.
data RoutingConfig = RoutingConfig'
  { -- | The failover configuration for an endpoint. This includes what triggers
    -- failover and what happens when it\'s triggered.
    RoutingConfig -> FailoverConfig
failoverConfig :: FailoverConfig
  }
  deriving (RoutingConfig -> RoutingConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RoutingConfig -> RoutingConfig -> Bool
$c/= :: RoutingConfig -> RoutingConfig -> Bool
== :: RoutingConfig -> RoutingConfig -> Bool
$c== :: RoutingConfig -> RoutingConfig -> Bool
Prelude.Eq, ReadPrec [RoutingConfig]
ReadPrec RoutingConfig
Int -> ReadS RoutingConfig
ReadS [RoutingConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RoutingConfig]
$creadListPrec :: ReadPrec [RoutingConfig]
readPrec :: ReadPrec RoutingConfig
$creadPrec :: ReadPrec RoutingConfig
readList :: ReadS [RoutingConfig]
$creadList :: ReadS [RoutingConfig]
readsPrec :: Int -> ReadS RoutingConfig
$creadsPrec :: Int -> ReadS RoutingConfig
Prelude.Read, Int -> RoutingConfig -> ShowS
[RoutingConfig] -> ShowS
RoutingConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RoutingConfig] -> ShowS
$cshowList :: [RoutingConfig] -> ShowS
show :: RoutingConfig -> String
$cshow :: RoutingConfig -> String
showsPrec :: Int -> RoutingConfig -> ShowS
$cshowsPrec :: Int -> RoutingConfig -> ShowS
Prelude.Show, forall x. Rep RoutingConfig x -> RoutingConfig
forall x. RoutingConfig -> Rep RoutingConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RoutingConfig x -> RoutingConfig
$cfrom :: forall x. RoutingConfig -> Rep RoutingConfig x
Prelude.Generic)

-- |
-- Create a value of 'RoutingConfig' 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:
--
-- 'failoverConfig', 'routingConfig_failoverConfig' - The failover configuration for an endpoint. This includes what triggers
-- failover and what happens when it\'s triggered.
newRoutingConfig ::
  -- | 'failoverConfig'
  FailoverConfig ->
  RoutingConfig
newRoutingConfig :: FailoverConfig -> RoutingConfig
newRoutingConfig FailoverConfig
pFailoverConfig_ =
  RoutingConfig' {$sel:failoverConfig:RoutingConfig' :: FailoverConfig
failoverConfig = FailoverConfig
pFailoverConfig_}

-- | The failover configuration for an endpoint. This includes what triggers
-- failover and what happens when it\'s triggered.
routingConfig_failoverConfig :: Lens.Lens' RoutingConfig FailoverConfig
routingConfig_failoverConfig :: Lens' RoutingConfig FailoverConfig
routingConfig_failoverConfig = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RoutingConfig' {FailoverConfig
failoverConfig :: FailoverConfig
$sel:failoverConfig:RoutingConfig' :: RoutingConfig -> FailoverConfig
failoverConfig} -> FailoverConfig
failoverConfig) (\s :: RoutingConfig
s@RoutingConfig' {} FailoverConfig
a -> RoutingConfig
s {$sel:failoverConfig:RoutingConfig' :: FailoverConfig
failoverConfig = FailoverConfig
a} :: RoutingConfig)

instance Data.FromJSON RoutingConfig where
  parseJSON :: Value -> Parser RoutingConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RoutingConfig"
      ( \Object
x ->
          FailoverConfig -> RoutingConfig
RoutingConfig'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"FailoverConfig")
      )

instance Prelude.Hashable RoutingConfig where
  hashWithSalt :: Int -> RoutingConfig -> Int
hashWithSalt Int
_salt RoutingConfig' {FailoverConfig
failoverConfig :: FailoverConfig
$sel:failoverConfig:RoutingConfig' :: RoutingConfig -> FailoverConfig
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` FailoverConfig
failoverConfig

instance Prelude.NFData RoutingConfig where
  rnf :: RoutingConfig -> ()
rnf RoutingConfig' {FailoverConfig
failoverConfig :: FailoverConfig
$sel:failoverConfig:RoutingConfig' :: RoutingConfig -> FailoverConfig
..} = forall a. NFData a => a -> ()
Prelude.rnf FailoverConfig
failoverConfig

instance Data.ToJSON RoutingConfig where
  toJSON :: RoutingConfig -> Value
toJSON RoutingConfig' {FailoverConfig
failoverConfig :: FailoverConfig
$sel:failoverConfig:RoutingConfig' :: RoutingConfig -> FailoverConfig
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"FailoverConfig" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= FailoverConfig
failoverConfig)
          ]
      )