{-# 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.MediaLive.Types.AutomaticInputFailoverSettings
-- 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.MediaLive.Types.AutomaticInputFailoverSettings where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.MediaLive.Types.FailoverCondition
import Amazonka.MediaLive.Types.InputPreference
import qualified Amazonka.Prelude as Prelude

-- | The settings for Automatic Input Failover.
--
-- /See:/ 'newAutomaticInputFailoverSettings' smart constructor.
data AutomaticInputFailoverSettings = AutomaticInputFailoverSettings'
  { -- | A list of failover conditions. If any of these conditions occur,
    -- MediaLive will perform a failover to the other input.
    AutomaticInputFailoverSettings -> Maybe [FailoverCondition]
failoverConditions :: Prelude.Maybe [FailoverCondition],
    -- | This clear time defines the requirement a recovered input must meet to
    -- be considered healthy. The input must have no failover conditions for
    -- this length of time. Enter a time in milliseconds. This value is
    -- particularly important if the input_preference for the failover pair is
    -- set to PRIMARY_INPUT_PREFERRED, because after this time, MediaLive will
    -- switch back to the primary input.
    AutomaticInputFailoverSettings -> Maybe Natural
errorClearTimeMsec :: Prelude.Maybe Prelude.Natural,
    -- | Input preference when deciding which input to make active when a
    -- previously failed input has recovered.
    AutomaticInputFailoverSettings -> Maybe InputPreference
inputPreference :: Prelude.Maybe InputPreference,
    -- | The input ID of the secondary input in the automatic input failover
    -- pair.
    AutomaticInputFailoverSettings -> Text
secondaryInputId :: Prelude.Text
  }
  deriving (AutomaticInputFailoverSettings
-> AutomaticInputFailoverSettings -> Bool
(AutomaticInputFailoverSettings
 -> AutomaticInputFailoverSettings -> Bool)
-> (AutomaticInputFailoverSettings
    -> AutomaticInputFailoverSettings -> Bool)
-> Eq AutomaticInputFailoverSettings
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AutomaticInputFailoverSettings
-> AutomaticInputFailoverSettings -> Bool
$c/= :: AutomaticInputFailoverSettings
-> AutomaticInputFailoverSettings -> Bool
== :: AutomaticInputFailoverSettings
-> AutomaticInputFailoverSettings -> Bool
$c== :: AutomaticInputFailoverSettings
-> AutomaticInputFailoverSettings -> Bool
Prelude.Eq, ReadPrec [AutomaticInputFailoverSettings]
ReadPrec AutomaticInputFailoverSettings
Int -> ReadS AutomaticInputFailoverSettings
ReadS [AutomaticInputFailoverSettings]
(Int -> ReadS AutomaticInputFailoverSettings)
-> ReadS [AutomaticInputFailoverSettings]
-> ReadPrec AutomaticInputFailoverSettings
-> ReadPrec [AutomaticInputFailoverSettings]
-> Read AutomaticInputFailoverSettings
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AutomaticInputFailoverSettings]
$creadListPrec :: ReadPrec [AutomaticInputFailoverSettings]
readPrec :: ReadPrec AutomaticInputFailoverSettings
$creadPrec :: ReadPrec AutomaticInputFailoverSettings
readList :: ReadS [AutomaticInputFailoverSettings]
$creadList :: ReadS [AutomaticInputFailoverSettings]
readsPrec :: Int -> ReadS AutomaticInputFailoverSettings
$creadsPrec :: Int -> ReadS AutomaticInputFailoverSettings
Prelude.Read, Int -> AutomaticInputFailoverSettings -> ShowS
[AutomaticInputFailoverSettings] -> ShowS
AutomaticInputFailoverSettings -> String
(Int -> AutomaticInputFailoverSettings -> ShowS)
-> (AutomaticInputFailoverSettings -> String)
-> ([AutomaticInputFailoverSettings] -> ShowS)
-> Show AutomaticInputFailoverSettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AutomaticInputFailoverSettings] -> ShowS
$cshowList :: [AutomaticInputFailoverSettings] -> ShowS
show :: AutomaticInputFailoverSettings -> String
$cshow :: AutomaticInputFailoverSettings -> String
showsPrec :: Int -> AutomaticInputFailoverSettings -> ShowS
$cshowsPrec :: Int -> AutomaticInputFailoverSettings -> ShowS
Prelude.Show, (forall x.
 AutomaticInputFailoverSettings
 -> Rep AutomaticInputFailoverSettings x)
-> (forall x.
    Rep AutomaticInputFailoverSettings x
    -> AutomaticInputFailoverSettings)
-> Generic AutomaticInputFailoverSettings
forall x.
Rep AutomaticInputFailoverSettings x
-> AutomaticInputFailoverSettings
forall x.
AutomaticInputFailoverSettings
-> Rep AutomaticInputFailoverSettings x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AutomaticInputFailoverSettings x
-> AutomaticInputFailoverSettings
$cfrom :: forall x.
AutomaticInputFailoverSettings
-> Rep AutomaticInputFailoverSettings x
Prelude.Generic)

-- |
-- Create a value of 'AutomaticInputFailoverSettings' 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:
--
-- 'failoverConditions', 'automaticInputFailoverSettings_failoverConditions' - A list of failover conditions. If any of these conditions occur,
-- MediaLive will perform a failover to the other input.
--
-- 'errorClearTimeMsec', 'automaticInputFailoverSettings_errorClearTimeMsec' - This clear time defines the requirement a recovered input must meet to
-- be considered healthy. The input must have no failover conditions for
-- this length of time. Enter a time in milliseconds. This value is
-- particularly important if the input_preference for the failover pair is
-- set to PRIMARY_INPUT_PREFERRED, because after this time, MediaLive will
-- switch back to the primary input.
--
-- 'inputPreference', 'automaticInputFailoverSettings_inputPreference' - Input preference when deciding which input to make active when a
-- previously failed input has recovered.
--
-- 'secondaryInputId', 'automaticInputFailoverSettings_secondaryInputId' - The input ID of the secondary input in the automatic input failover
-- pair.
newAutomaticInputFailoverSettings ::
  -- | 'secondaryInputId'
  Prelude.Text ->
  AutomaticInputFailoverSettings
newAutomaticInputFailoverSettings :: Text -> AutomaticInputFailoverSettings
newAutomaticInputFailoverSettings Text
pSecondaryInputId_ =
  AutomaticInputFailoverSettings' :: Maybe [FailoverCondition]
-> Maybe Natural
-> Maybe InputPreference
-> Text
-> AutomaticInputFailoverSettings
AutomaticInputFailoverSettings'
    { $sel:failoverConditions:AutomaticInputFailoverSettings' :: Maybe [FailoverCondition]
failoverConditions =
        Maybe [FailoverCondition]
forall a. Maybe a
Prelude.Nothing,
      $sel:errorClearTimeMsec:AutomaticInputFailoverSettings' :: Maybe Natural
errorClearTimeMsec = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:inputPreference:AutomaticInputFailoverSettings' :: Maybe InputPreference
inputPreference = Maybe InputPreference
forall a. Maybe a
Prelude.Nothing,
      $sel:secondaryInputId:AutomaticInputFailoverSettings' :: Text
secondaryInputId = Text
pSecondaryInputId_
    }

-- | A list of failover conditions. If any of these conditions occur,
-- MediaLive will perform a failover to the other input.
automaticInputFailoverSettings_failoverConditions :: Lens.Lens' AutomaticInputFailoverSettings (Prelude.Maybe [FailoverCondition])
automaticInputFailoverSettings_failoverConditions :: (Maybe [FailoverCondition] -> f (Maybe [FailoverCondition]))
-> AutomaticInputFailoverSettings
-> f AutomaticInputFailoverSettings
automaticInputFailoverSettings_failoverConditions = (AutomaticInputFailoverSettings -> Maybe [FailoverCondition])
-> (AutomaticInputFailoverSettings
    -> Maybe [FailoverCondition] -> AutomaticInputFailoverSettings)
-> Lens
     AutomaticInputFailoverSettings
     AutomaticInputFailoverSettings
     (Maybe [FailoverCondition])
     (Maybe [FailoverCondition])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AutomaticInputFailoverSettings' {Maybe [FailoverCondition]
failoverConditions :: Maybe [FailoverCondition]
$sel:failoverConditions:AutomaticInputFailoverSettings' :: AutomaticInputFailoverSettings -> Maybe [FailoverCondition]
failoverConditions} -> Maybe [FailoverCondition]
failoverConditions) (\s :: AutomaticInputFailoverSettings
s@AutomaticInputFailoverSettings' {} Maybe [FailoverCondition]
a -> AutomaticInputFailoverSettings
s {$sel:failoverConditions:AutomaticInputFailoverSettings' :: Maybe [FailoverCondition]
failoverConditions = Maybe [FailoverCondition]
a} :: AutomaticInputFailoverSettings) ((Maybe [FailoverCondition] -> f (Maybe [FailoverCondition]))
 -> AutomaticInputFailoverSettings
 -> f AutomaticInputFailoverSettings)
-> ((Maybe [FailoverCondition] -> f (Maybe [FailoverCondition]))
    -> Maybe [FailoverCondition] -> f (Maybe [FailoverCondition]))
-> (Maybe [FailoverCondition] -> f (Maybe [FailoverCondition]))
-> AutomaticInputFailoverSettings
-> f AutomaticInputFailoverSettings
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [FailoverCondition]
  [FailoverCondition]
  [FailoverCondition]
  [FailoverCondition]
-> Iso
     (Maybe [FailoverCondition])
     (Maybe [FailoverCondition])
     (Maybe [FailoverCondition])
     (Maybe [FailoverCondition])
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
  [FailoverCondition]
  [FailoverCondition]
  [FailoverCondition]
  [FailoverCondition]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | This clear time defines the requirement a recovered input must meet to
-- be considered healthy. The input must have no failover conditions for
-- this length of time. Enter a time in milliseconds. This value is
-- particularly important if the input_preference for the failover pair is
-- set to PRIMARY_INPUT_PREFERRED, because after this time, MediaLive will
-- switch back to the primary input.
automaticInputFailoverSettings_errorClearTimeMsec :: Lens.Lens' AutomaticInputFailoverSettings (Prelude.Maybe Prelude.Natural)
automaticInputFailoverSettings_errorClearTimeMsec :: (Maybe Natural -> f (Maybe Natural))
-> AutomaticInputFailoverSettings
-> f AutomaticInputFailoverSettings
automaticInputFailoverSettings_errorClearTimeMsec = (AutomaticInputFailoverSettings -> Maybe Natural)
-> (AutomaticInputFailoverSettings
    -> Maybe Natural -> AutomaticInputFailoverSettings)
-> Lens
     AutomaticInputFailoverSettings
     AutomaticInputFailoverSettings
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AutomaticInputFailoverSettings' {Maybe Natural
errorClearTimeMsec :: Maybe Natural
$sel:errorClearTimeMsec:AutomaticInputFailoverSettings' :: AutomaticInputFailoverSettings -> Maybe Natural
errorClearTimeMsec} -> Maybe Natural
errorClearTimeMsec) (\s :: AutomaticInputFailoverSettings
s@AutomaticInputFailoverSettings' {} Maybe Natural
a -> AutomaticInputFailoverSettings
s {$sel:errorClearTimeMsec:AutomaticInputFailoverSettings' :: Maybe Natural
errorClearTimeMsec = Maybe Natural
a} :: AutomaticInputFailoverSettings)

-- | Input preference when deciding which input to make active when a
-- previously failed input has recovered.
automaticInputFailoverSettings_inputPreference :: Lens.Lens' AutomaticInputFailoverSettings (Prelude.Maybe InputPreference)
automaticInputFailoverSettings_inputPreference :: (Maybe InputPreference -> f (Maybe InputPreference))
-> AutomaticInputFailoverSettings
-> f AutomaticInputFailoverSettings
automaticInputFailoverSettings_inputPreference = (AutomaticInputFailoverSettings -> Maybe InputPreference)
-> (AutomaticInputFailoverSettings
    -> Maybe InputPreference -> AutomaticInputFailoverSettings)
-> Lens
     AutomaticInputFailoverSettings
     AutomaticInputFailoverSettings
     (Maybe InputPreference)
     (Maybe InputPreference)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AutomaticInputFailoverSettings' {Maybe InputPreference
inputPreference :: Maybe InputPreference
$sel:inputPreference:AutomaticInputFailoverSettings' :: AutomaticInputFailoverSettings -> Maybe InputPreference
inputPreference} -> Maybe InputPreference
inputPreference) (\s :: AutomaticInputFailoverSettings
s@AutomaticInputFailoverSettings' {} Maybe InputPreference
a -> AutomaticInputFailoverSettings
s {$sel:inputPreference:AutomaticInputFailoverSettings' :: Maybe InputPreference
inputPreference = Maybe InputPreference
a} :: AutomaticInputFailoverSettings)

-- | The input ID of the secondary input in the automatic input failover
-- pair.
automaticInputFailoverSettings_secondaryInputId :: Lens.Lens' AutomaticInputFailoverSettings Prelude.Text
automaticInputFailoverSettings_secondaryInputId :: (Text -> f Text)
-> AutomaticInputFailoverSettings
-> f AutomaticInputFailoverSettings
automaticInputFailoverSettings_secondaryInputId = (AutomaticInputFailoverSettings -> Text)
-> (AutomaticInputFailoverSettings
    -> Text -> AutomaticInputFailoverSettings)
-> Lens
     AutomaticInputFailoverSettings
     AutomaticInputFailoverSettings
     Text
     Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AutomaticInputFailoverSettings' {Text
secondaryInputId :: Text
$sel:secondaryInputId:AutomaticInputFailoverSettings' :: AutomaticInputFailoverSettings -> Text
secondaryInputId} -> Text
secondaryInputId) (\s :: AutomaticInputFailoverSettings
s@AutomaticInputFailoverSettings' {} Text
a -> AutomaticInputFailoverSettings
s {$sel:secondaryInputId:AutomaticInputFailoverSettings' :: Text
secondaryInputId = Text
a} :: AutomaticInputFailoverSettings)

instance Core.FromJSON AutomaticInputFailoverSettings where
  parseJSON :: Value -> Parser AutomaticInputFailoverSettings
parseJSON =
    String
-> (Object -> Parser AutomaticInputFailoverSettings)
-> Value
-> Parser AutomaticInputFailoverSettings
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AutomaticInputFailoverSettings"
      ( \Object
x ->
          Maybe [FailoverCondition]
-> Maybe Natural
-> Maybe InputPreference
-> Text
-> AutomaticInputFailoverSettings
AutomaticInputFailoverSettings'
            (Maybe [FailoverCondition]
 -> Maybe Natural
 -> Maybe InputPreference
 -> Text
 -> AutomaticInputFailoverSettings)
-> Parser (Maybe [FailoverCondition])
-> Parser
     (Maybe Natural
      -> Maybe InputPreference -> Text -> AutomaticInputFailoverSettings)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x Object -> Text -> Parser (Maybe (Maybe [FailoverCondition]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"failoverConditions"
                            Parser (Maybe (Maybe [FailoverCondition]))
-> Maybe [FailoverCondition] -> Parser (Maybe [FailoverCondition])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [FailoverCondition]
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser
  (Maybe Natural
   -> Maybe InputPreference -> Text -> AutomaticInputFailoverSettings)
-> Parser (Maybe Natural)
-> Parser
     (Maybe InputPreference -> Text -> AutomaticInputFailoverSettings)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"errorClearTimeMsec")
            Parser
  (Maybe InputPreference -> Text -> AutomaticInputFailoverSettings)
-> Parser (Maybe InputPreference)
-> Parser (Text -> AutomaticInputFailoverSettings)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe InputPreference)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"inputPreference")
            Parser (Text -> AutomaticInputFailoverSettings)
-> Parser Text -> Parser AutomaticInputFailoverSettings
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"secondaryInputId")
      )

instance
  Prelude.Hashable
    AutomaticInputFailoverSettings

instance
  Prelude.NFData
    AutomaticInputFailoverSettings

instance Core.ToJSON AutomaticInputFailoverSettings where
  toJSON :: AutomaticInputFailoverSettings -> Value
toJSON AutomaticInputFailoverSettings' {Maybe Natural
Maybe [FailoverCondition]
Maybe InputPreference
Text
secondaryInputId :: Text
inputPreference :: Maybe InputPreference
errorClearTimeMsec :: Maybe Natural
failoverConditions :: Maybe [FailoverCondition]
$sel:secondaryInputId:AutomaticInputFailoverSettings' :: AutomaticInputFailoverSettings -> Text
$sel:inputPreference:AutomaticInputFailoverSettings' :: AutomaticInputFailoverSettings -> Maybe InputPreference
$sel:errorClearTimeMsec:AutomaticInputFailoverSettings' :: AutomaticInputFailoverSettings -> Maybe Natural
$sel:failoverConditions:AutomaticInputFailoverSettings' :: AutomaticInputFailoverSettings -> Maybe [FailoverCondition]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"failoverConditions" Text -> [FailoverCondition] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([FailoverCondition] -> Pair)
-> Maybe [FailoverCondition] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [FailoverCondition]
failoverConditions,
            (Text
"errorClearTimeMsec" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
errorClearTimeMsec,
            (Text
"inputPreference" Text -> InputPreference -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (InputPreference -> Pair) -> Maybe InputPreference -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe InputPreference
inputPreference,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"secondaryInputId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
secondaryInputId)
          ]
      )