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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.MediaConnect.Types.FailoverMode
import Amazonka.MediaConnect.Types.SourcePriority
import Amazonka.MediaConnect.Types.State
import qualified Amazonka.Prelude as Prelude

-- | The settings for source failover
--
-- /See:/ 'newFailoverConfig' smart constructor.
data FailoverConfig = FailoverConfig'
  { FailoverConfig -> Maybe State
state :: Prelude.Maybe State,
    -- | Search window time to look for dash-7 packets
    FailoverConfig -> Maybe Int
recoveryWindow :: Prelude.Maybe Prelude.Int,
    -- | The priority you want to assign to a source. You can have a primary
    -- stream and a backup stream or two equally prioritized streams.
    FailoverConfig -> Maybe SourcePriority
sourcePriority :: Prelude.Maybe SourcePriority,
    -- | The type of failover you choose for this flow. MERGE combines the source
    -- streams into a single stream, allowing graceful recovery from any
    -- single-source loss. FAILOVER allows switching between different streams.
    FailoverConfig -> Maybe FailoverMode
failoverMode :: Prelude.Maybe FailoverMode
  }
  deriving (FailoverConfig -> FailoverConfig -> Bool
(FailoverConfig -> FailoverConfig -> Bool)
-> (FailoverConfig -> FailoverConfig -> Bool) -> Eq FailoverConfig
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]
(Int -> ReadS FailoverConfig)
-> ReadS [FailoverConfig]
-> ReadPrec FailoverConfig
-> ReadPrec [FailoverConfig]
-> Read 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
(Int -> FailoverConfig -> ShowS)
-> (FailoverConfig -> String)
-> ([FailoverConfig] -> ShowS)
-> Show FailoverConfig
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. FailoverConfig -> Rep FailoverConfig x)
-> (forall x. Rep FailoverConfig x -> FailoverConfig)
-> Generic FailoverConfig
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:
--
-- 'state', 'failoverConfig_state' - Undocumented member.
--
-- 'recoveryWindow', 'failoverConfig_recoveryWindow' - Search window time to look for dash-7 packets
--
-- 'sourcePriority', 'failoverConfig_sourcePriority' - The priority you want to assign to a source. You can have a primary
-- stream and a backup stream or two equally prioritized streams.
--
-- 'failoverMode', 'failoverConfig_failoverMode' - The type of failover you choose for this flow. MERGE combines the source
-- streams into a single stream, allowing graceful recovery from any
-- single-source loss. FAILOVER allows switching between different streams.
newFailoverConfig ::
  FailoverConfig
newFailoverConfig :: FailoverConfig
newFailoverConfig =
  FailoverConfig' :: Maybe State
-> Maybe Int
-> Maybe SourcePriority
-> Maybe FailoverMode
-> FailoverConfig
FailoverConfig'
    { $sel:state:FailoverConfig' :: Maybe State
state = Maybe State
forall a. Maybe a
Prelude.Nothing,
      $sel:recoveryWindow:FailoverConfig' :: Maybe Int
recoveryWindow = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:sourcePriority:FailoverConfig' :: Maybe SourcePriority
sourcePriority = Maybe SourcePriority
forall a. Maybe a
Prelude.Nothing,
      $sel:failoverMode:FailoverConfig' :: Maybe FailoverMode
failoverMode = Maybe FailoverMode
forall a. Maybe a
Prelude.Nothing
    }

-- | Undocumented member.
failoverConfig_state :: Lens.Lens' FailoverConfig (Prelude.Maybe State)
failoverConfig_state :: (Maybe State -> f (Maybe State))
-> FailoverConfig -> f FailoverConfig
failoverConfig_state = (FailoverConfig -> Maybe State)
-> (FailoverConfig -> Maybe State -> FailoverConfig)
-> Lens FailoverConfig FailoverConfig (Maybe State) (Maybe State)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FailoverConfig' {Maybe State
state :: Maybe State
$sel:state:FailoverConfig' :: FailoverConfig -> Maybe State
state} -> Maybe State
state) (\s :: FailoverConfig
s@FailoverConfig' {} Maybe State
a -> FailoverConfig
s {$sel:state:FailoverConfig' :: Maybe State
state = Maybe State
a} :: FailoverConfig)

-- | Search window time to look for dash-7 packets
failoverConfig_recoveryWindow :: Lens.Lens' FailoverConfig (Prelude.Maybe Prelude.Int)
failoverConfig_recoveryWindow :: (Maybe Int -> f (Maybe Int)) -> FailoverConfig -> f FailoverConfig
failoverConfig_recoveryWindow = (FailoverConfig -> Maybe Int)
-> (FailoverConfig -> Maybe Int -> FailoverConfig)
-> Lens FailoverConfig FailoverConfig (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FailoverConfig' {Maybe Int
recoveryWindow :: Maybe Int
$sel:recoveryWindow:FailoverConfig' :: FailoverConfig -> Maybe Int
recoveryWindow} -> Maybe Int
recoveryWindow) (\s :: FailoverConfig
s@FailoverConfig' {} Maybe Int
a -> FailoverConfig
s {$sel:recoveryWindow:FailoverConfig' :: Maybe Int
recoveryWindow = Maybe Int
a} :: FailoverConfig)

-- | The priority you want to assign to a source. You can have a primary
-- stream and a backup stream or two equally prioritized streams.
failoverConfig_sourcePriority :: Lens.Lens' FailoverConfig (Prelude.Maybe SourcePriority)
failoverConfig_sourcePriority :: (Maybe SourcePriority -> f (Maybe SourcePriority))
-> FailoverConfig -> f FailoverConfig
failoverConfig_sourcePriority = (FailoverConfig -> Maybe SourcePriority)
-> (FailoverConfig -> Maybe SourcePriority -> FailoverConfig)
-> Lens
     FailoverConfig
     FailoverConfig
     (Maybe SourcePriority)
     (Maybe SourcePriority)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FailoverConfig' {Maybe SourcePriority
sourcePriority :: Maybe SourcePriority
$sel:sourcePriority:FailoverConfig' :: FailoverConfig -> Maybe SourcePriority
sourcePriority} -> Maybe SourcePriority
sourcePriority) (\s :: FailoverConfig
s@FailoverConfig' {} Maybe SourcePriority
a -> FailoverConfig
s {$sel:sourcePriority:FailoverConfig' :: Maybe SourcePriority
sourcePriority = Maybe SourcePriority
a} :: FailoverConfig)

-- | The type of failover you choose for this flow. MERGE combines the source
-- streams into a single stream, allowing graceful recovery from any
-- single-source loss. FAILOVER allows switching between different streams.
failoverConfig_failoverMode :: Lens.Lens' FailoverConfig (Prelude.Maybe FailoverMode)
failoverConfig_failoverMode :: (Maybe FailoverMode -> f (Maybe FailoverMode))
-> FailoverConfig -> f FailoverConfig
failoverConfig_failoverMode = (FailoverConfig -> Maybe FailoverMode)
-> (FailoverConfig -> Maybe FailoverMode -> FailoverConfig)
-> Lens
     FailoverConfig
     FailoverConfig
     (Maybe FailoverMode)
     (Maybe FailoverMode)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FailoverConfig' {Maybe FailoverMode
failoverMode :: Maybe FailoverMode
$sel:failoverMode:FailoverConfig' :: FailoverConfig -> Maybe FailoverMode
failoverMode} -> Maybe FailoverMode
failoverMode) (\s :: FailoverConfig
s@FailoverConfig' {} Maybe FailoverMode
a -> FailoverConfig
s {$sel:failoverMode:FailoverConfig' :: Maybe FailoverMode
failoverMode = Maybe FailoverMode
a} :: FailoverConfig)

instance Core.FromJSON FailoverConfig where
  parseJSON :: Value -> Parser FailoverConfig
parseJSON =
    String
-> (Object -> Parser FailoverConfig)
-> Value
-> Parser FailoverConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"FailoverConfig"
      ( \Object
x ->
          Maybe State
-> Maybe Int
-> Maybe SourcePriority
-> Maybe FailoverMode
-> FailoverConfig
FailoverConfig'
            (Maybe State
 -> Maybe Int
 -> Maybe SourcePriority
 -> Maybe FailoverMode
 -> FailoverConfig)
-> Parser (Maybe State)
-> Parser
     (Maybe Int
      -> Maybe SourcePriority -> Maybe FailoverMode -> FailoverConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe State)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"state")
            Parser
  (Maybe Int
   -> Maybe SourcePriority -> Maybe FailoverMode -> FailoverConfig)
-> Parser (Maybe Int)
-> Parser
     (Maybe SourcePriority -> Maybe FailoverMode -> FailoverConfig)
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
"recoveryWindow")
            Parser
  (Maybe SourcePriority -> Maybe FailoverMode -> FailoverConfig)
-> Parser (Maybe SourcePriority)
-> Parser (Maybe FailoverMode -> FailoverConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe SourcePriority)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"sourcePriority")
            Parser (Maybe FailoverMode -> FailoverConfig)
-> Parser (Maybe FailoverMode) -> Parser FailoverConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe FailoverMode)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"failoverMode")
      )

instance Prelude.Hashable FailoverConfig

instance Prelude.NFData FailoverConfig

instance Core.ToJSON FailoverConfig where
  toJSON :: FailoverConfig -> Value
toJSON FailoverConfig' {Maybe Int
Maybe FailoverMode
Maybe SourcePriority
Maybe State
failoverMode :: Maybe FailoverMode
sourcePriority :: Maybe SourcePriority
recoveryWindow :: Maybe Int
state :: Maybe State
$sel:failoverMode:FailoverConfig' :: FailoverConfig -> Maybe FailoverMode
$sel:sourcePriority:FailoverConfig' :: FailoverConfig -> Maybe SourcePriority
$sel:recoveryWindow:FailoverConfig' :: FailoverConfig -> Maybe Int
$sel:state:FailoverConfig' :: FailoverConfig -> Maybe State
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"state" Text -> State -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (State -> Pair) -> Maybe State -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe State
state,
            (Text
"recoveryWindow" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
recoveryWindow,
            (Text
"sourcePriority" Text -> SourcePriority -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (SourcePriority -> Pair) -> Maybe SourcePriority -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SourcePriority
sourcePriority,
            (Text
"failoverMode" Text -> FailoverMode -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (FailoverMode -> Pair) -> Maybe FailoverMode -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe FailoverMode
failoverMode
          ]
      )