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

import Amazonka.CloudWatchEvents.Types.Primary
import Amazonka.CloudWatchEvents.Types.Secondary
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 failover configuration for an endpoint. This includes what triggers
-- failover and what happens when it\'s triggered.
--
-- /See:/ 'newFailoverConfig' smart constructor.
data FailoverConfig = FailoverConfig'
  { -- | The main Region of the endpoint.
    FailoverConfig -> Primary
primary :: Primary,
    -- | The Region that events are routed to when failover is triggered or event
    -- replication is enabled.
    FailoverConfig -> Secondary
secondary :: Secondary
  }
  deriving (FailoverConfig -> FailoverConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FailoverConfig -> FailoverConfig -> Bool
$c/= :: FailoverConfig -> FailoverConfig -> Bool
== :: FailoverConfig -> FailoverConfig -> Bool
$c== :: FailoverConfig -> FailoverConfig -> Bool
Prelude.Eq, ReadPrec [FailoverConfig]
ReadPrec FailoverConfig
Int -> ReadS FailoverConfig
ReadS [FailoverConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FailoverConfig]
$creadListPrec :: ReadPrec [FailoverConfig]
readPrec :: ReadPrec FailoverConfig
$creadPrec :: ReadPrec FailoverConfig
readList :: ReadS [FailoverConfig]
$creadList :: ReadS [FailoverConfig]
readsPrec :: Int -> ReadS FailoverConfig
$creadsPrec :: Int -> ReadS FailoverConfig
Prelude.Read, Int -> FailoverConfig -> ShowS
[FailoverConfig] -> ShowS
FailoverConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FailoverConfig] -> ShowS
$cshowList :: [FailoverConfig] -> ShowS
show :: FailoverConfig -> String
$cshow :: FailoverConfig -> String
showsPrec :: Int -> FailoverConfig -> ShowS
$cshowsPrec :: Int -> FailoverConfig -> ShowS
Prelude.Show, forall x. Rep FailoverConfig x -> FailoverConfig
forall x. FailoverConfig -> Rep FailoverConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FailoverConfig x -> FailoverConfig
$cfrom :: forall x. FailoverConfig -> Rep FailoverConfig x
Prelude.Generic)

-- |
-- Create a value of 'FailoverConfig' 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:
--
-- 'primary', 'failoverConfig_primary' - The main Region of the endpoint.
--
-- 'secondary', 'failoverConfig_secondary' - The Region that events are routed to when failover is triggered or event
-- replication is enabled.
newFailoverConfig ::
  -- | 'primary'
  Primary ->
  -- | 'secondary'
  Secondary ->
  FailoverConfig
newFailoverConfig :: Primary -> Secondary -> FailoverConfig
newFailoverConfig Primary
pPrimary_ Secondary
pSecondary_ =
  FailoverConfig'
    { $sel:primary:FailoverConfig' :: Primary
primary = Primary
pPrimary_,
      $sel:secondary:FailoverConfig' :: Secondary
secondary = Secondary
pSecondary_
    }

-- | The main Region of the endpoint.
failoverConfig_primary :: Lens.Lens' FailoverConfig Primary
failoverConfig_primary :: Lens' FailoverConfig Primary
failoverConfig_primary = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FailoverConfig' {Primary
primary :: Primary
$sel:primary:FailoverConfig' :: FailoverConfig -> Primary
primary} -> Primary
primary) (\s :: FailoverConfig
s@FailoverConfig' {} Primary
a -> FailoverConfig
s {$sel:primary:FailoverConfig' :: Primary
primary = Primary
a} :: FailoverConfig)

-- | The Region that events are routed to when failover is triggered or event
-- replication is enabled.
failoverConfig_secondary :: Lens.Lens' FailoverConfig Secondary
failoverConfig_secondary :: Lens' FailoverConfig Secondary
failoverConfig_secondary = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FailoverConfig' {Secondary
secondary :: Secondary
$sel:secondary:FailoverConfig' :: FailoverConfig -> Secondary
secondary} -> Secondary
secondary) (\s :: FailoverConfig
s@FailoverConfig' {} Secondary
a -> FailoverConfig
s {$sel:secondary:FailoverConfig' :: Secondary
secondary = Secondary
a} :: FailoverConfig)

instance Data.FromJSON FailoverConfig where
  parseJSON :: Value -> Parser FailoverConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"FailoverConfig"
      ( \Object
x ->
          Primary -> Secondary -> FailoverConfig
FailoverConfig'
            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
"Primary")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Secondary")
      )

instance Prelude.Hashable FailoverConfig where
  hashWithSalt :: Int -> FailoverConfig -> Int
hashWithSalt Int
_salt FailoverConfig' {Primary
Secondary
secondary :: Secondary
primary :: Primary
$sel:secondary:FailoverConfig' :: FailoverConfig -> Secondary
$sel:primary:FailoverConfig' :: FailoverConfig -> Primary
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Primary
primary
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Secondary
secondary

instance Prelude.NFData FailoverConfig where
  rnf :: FailoverConfig -> ()
rnf FailoverConfig' {Primary
Secondary
secondary :: Secondary
primary :: Primary
$sel:secondary:FailoverConfig' :: FailoverConfig -> Secondary
$sel:primary:FailoverConfig' :: FailoverConfig -> Primary
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Primary
primary
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Secondary
secondary

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