{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.MediaLive.Types.AutomaticInputFailoverSettings where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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'
  { -- | 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,
    -- | 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],
    -- | 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
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]
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
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.
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:
--
-- '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.
--
-- 'failoverConditions', 'automaticInputFailoverSettings_failoverConditions' - A list of failover conditions. If any of these conditions occur,
-- MediaLive will perform a failover to the other 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'
    { $sel:errorClearTimeMsec:AutomaticInputFailoverSettings' :: Maybe Natural
errorClearTimeMsec =
        forall a. Maybe a
Prelude.Nothing,
      $sel:failoverConditions:AutomaticInputFailoverSettings' :: Maybe [FailoverCondition]
failoverConditions = forall a. Maybe a
Prelude.Nothing,
      $sel:inputPreference:AutomaticInputFailoverSettings' :: Maybe InputPreference
inputPreference = forall a. Maybe a
Prelude.Nothing,
      $sel:secondaryInputId:AutomaticInputFailoverSettings' :: Text
secondaryInputId = Text
pSecondaryInputId_
    }

-- | 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 :: Lens' AutomaticInputFailoverSettings (Maybe Natural)
automaticInputFailoverSettings_errorClearTimeMsec = 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)

-- | 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 :: Lens' AutomaticInputFailoverSettings (Maybe [FailoverCondition])
automaticInputFailoverSettings_failoverConditions = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | 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 :: Lens' AutomaticInputFailoverSettings (Maybe InputPreference)
automaticInputFailoverSettings_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 :: Lens' AutomaticInputFailoverSettings Text
automaticInputFailoverSettings_secondaryInputId = 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 Data.FromJSON AutomaticInputFailoverSettings where
  parseJSON :: Value -> Parser AutomaticInputFailoverSettings
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AutomaticInputFailoverSettings"
      ( \Object
x ->
          Maybe Natural
-> Maybe [FailoverCondition]
-> Maybe InputPreference
-> Text
-> AutomaticInputFailoverSettings
AutomaticInputFailoverSettings'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"errorClearTimeMsec")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"failoverConditions"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"inputPreference")
            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
"secondaryInputId")
      )

instance
  Prelude.Hashable
    AutomaticInputFailoverSettings
  where
  hashWithSalt :: Int -> AutomaticInputFailoverSettings -> Int
hashWithSalt
    Int
_salt
    AutomaticInputFailoverSettings' {Maybe Natural
Maybe [FailoverCondition]
Maybe InputPreference
Text
secondaryInputId :: Text
inputPreference :: Maybe InputPreference
failoverConditions :: Maybe [FailoverCondition]
errorClearTimeMsec :: Maybe Natural
$sel:secondaryInputId:AutomaticInputFailoverSettings' :: AutomaticInputFailoverSettings -> Text
$sel:inputPreference:AutomaticInputFailoverSettings' :: AutomaticInputFailoverSettings -> Maybe InputPreference
$sel:failoverConditions:AutomaticInputFailoverSettings' :: AutomaticInputFailoverSettings -> Maybe [FailoverCondition]
$sel:errorClearTimeMsec:AutomaticInputFailoverSettings' :: AutomaticInputFailoverSettings -> Maybe Natural
..} =
      Int
_salt
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
errorClearTimeMsec
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [FailoverCondition]
failoverConditions
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe InputPreference
inputPreference
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
secondaryInputId

instance
  Prelude.NFData
    AutomaticInputFailoverSettings
  where
  rnf :: AutomaticInputFailoverSettings -> ()
rnf AutomaticInputFailoverSettings' {Maybe Natural
Maybe [FailoverCondition]
Maybe InputPreference
Text
secondaryInputId :: Text
inputPreference :: Maybe InputPreference
failoverConditions :: Maybe [FailoverCondition]
errorClearTimeMsec :: Maybe Natural
$sel:secondaryInputId:AutomaticInputFailoverSettings' :: AutomaticInputFailoverSettings -> Text
$sel:inputPreference:AutomaticInputFailoverSettings' :: AutomaticInputFailoverSettings -> Maybe InputPreference
$sel:failoverConditions:AutomaticInputFailoverSettings' :: AutomaticInputFailoverSettings -> Maybe [FailoverCondition]
$sel:errorClearTimeMsec:AutomaticInputFailoverSettings' :: AutomaticInputFailoverSettings -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
errorClearTimeMsec
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [FailoverCondition]
failoverConditions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe InputPreference
inputPreference
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
secondaryInputId

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