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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.MediaLive.Types.ScheduleActionSettings
import Amazonka.MediaLive.Types.ScheduleActionStartSettings
import qualified Amazonka.Prelude as Prelude

-- | Contains information on a single schedule action.
--
-- /See:/ 'newScheduleAction' smart constructor.
data ScheduleAction = ScheduleAction'
  { -- | The name of the action, must be unique within the schedule. This name
    -- provides the main reference to an action once it is added to the
    -- schedule. A name is unique if it is no longer in the schedule. The
    -- schedule is automatically cleaned up to remove actions with a start time
    -- of more than 1 hour ago (approximately) so at that point a name can be
    -- reused.
    ScheduleAction -> Text
actionName :: Prelude.Text,
    -- | The time for the action to start in the channel.
    ScheduleAction -> ScheduleActionStartSettings
scheduleActionStartSettings :: ScheduleActionStartSettings,
    -- | Settings for this schedule action.
    ScheduleAction -> ScheduleActionSettings
scheduleActionSettings :: ScheduleActionSettings
  }
  deriving (ScheduleAction -> ScheduleAction -> Bool
(ScheduleAction -> ScheduleAction -> Bool)
-> (ScheduleAction -> ScheduleAction -> Bool) -> Eq ScheduleAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ScheduleAction -> ScheduleAction -> Bool
$c/= :: ScheduleAction -> ScheduleAction -> Bool
== :: ScheduleAction -> ScheduleAction -> Bool
$c== :: ScheduleAction -> ScheduleAction -> Bool
Prelude.Eq, ReadPrec [ScheduleAction]
ReadPrec ScheduleAction
Int -> ReadS ScheduleAction
ReadS [ScheduleAction]
(Int -> ReadS ScheduleAction)
-> ReadS [ScheduleAction]
-> ReadPrec ScheduleAction
-> ReadPrec [ScheduleAction]
-> Read ScheduleAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ScheduleAction]
$creadListPrec :: ReadPrec [ScheduleAction]
readPrec :: ReadPrec ScheduleAction
$creadPrec :: ReadPrec ScheduleAction
readList :: ReadS [ScheduleAction]
$creadList :: ReadS [ScheduleAction]
readsPrec :: Int -> ReadS ScheduleAction
$creadsPrec :: Int -> ReadS ScheduleAction
Prelude.Read, Int -> ScheduleAction -> ShowS
[ScheduleAction] -> ShowS
ScheduleAction -> String
(Int -> ScheduleAction -> ShowS)
-> (ScheduleAction -> String)
-> ([ScheduleAction] -> ShowS)
-> Show ScheduleAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ScheduleAction] -> ShowS
$cshowList :: [ScheduleAction] -> ShowS
show :: ScheduleAction -> String
$cshow :: ScheduleAction -> String
showsPrec :: Int -> ScheduleAction -> ShowS
$cshowsPrec :: Int -> ScheduleAction -> ShowS
Prelude.Show, (forall x. ScheduleAction -> Rep ScheduleAction x)
-> (forall x. Rep ScheduleAction x -> ScheduleAction)
-> Generic ScheduleAction
forall x. Rep ScheduleAction x -> ScheduleAction
forall x. ScheduleAction -> Rep ScheduleAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ScheduleAction x -> ScheduleAction
$cfrom :: forall x. ScheduleAction -> Rep ScheduleAction x
Prelude.Generic)

-- |
-- Create a value of 'ScheduleAction' 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:
--
-- 'actionName', 'scheduleAction_actionName' - The name of the action, must be unique within the schedule. This name
-- provides the main reference to an action once it is added to the
-- schedule. A name is unique if it is no longer in the schedule. The
-- schedule is automatically cleaned up to remove actions with a start time
-- of more than 1 hour ago (approximately) so at that point a name can be
-- reused.
--
-- 'scheduleActionStartSettings', 'scheduleAction_scheduleActionStartSettings' - The time for the action to start in the channel.
--
-- 'scheduleActionSettings', 'scheduleAction_scheduleActionSettings' - Settings for this schedule action.
newScheduleAction ::
  -- | 'actionName'
  Prelude.Text ->
  -- | 'scheduleActionStartSettings'
  ScheduleActionStartSettings ->
  -- | 'scheduleActionSettings'
  ScheduleActionSettings ->
  ScheduleAction
newScheduleAction :: Text
-> ScheduleActionStartSettings
-> ScheduleActionSettings
-> ScheduleAction
newScheduleAction
  Text
pActionName_
  ScheduleActionStartSettings
pScheduleActionStartSettings_
  ScheduleActionSettings
pScheduleActionSettings_ =
    ScheduleAction' :: Text
-> ScheduleActionStartSettings
-> ScheduleActionSettings
-> ScheduleAction
ScheduleAction'
      { $sel:actionName:ScheduleAction' :: Text
actionName = Text
pActionName_,
        $sel:scheduleActionStartSettings:ScheduleAction' :: ScheduleActionStartSettings
scheduleActionStartSettings =
          ScheduleActionStartSettings
pScheduleActionStartSettings_,
        $sel:scheduleActionSettings:ScheduleAction' :: ScheduleActionSettings
scheduleActionSettings = ScheduleActionSettings
pScheduleActionSettings_
      }

-- | The name of the action, must be unique within the schedule. This name
-- provides the main reference to an action once it is added to the
-- schedule. A name is unique if it is no longer in the schedule. The
-- schedule is automatically cleaned up to remove actions with a start time
-- of more than 1 hour ago (approximately) so at that point a name can be
-- reused.
scheduleAction_actionName :: Lens.Lens' ScheduleAction Prelude.Text
scheduleAction_actionName :: (Text -> f Text) -> ScheduleAction -> f ScheduleAction
scheduleAction_actionName = (ScheduleAction -> Text)
-> (ScheduleAction -> Text -> ScheduleAction)
-> Lens ScheduleAction ScheduleAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ScheduleAction' {Text
actionName :: Text
$sel:actionName:ScheduleAction' :: ScheduleAction -> Text
actionName} -> Text
actionName) (\s :: ScheduleAction
s@ScheduleAction' {} Text
a -> ScheduleAction
s {$sel:actionName:ScheduleAction' :: Text
actionName = Text
a} :: ScheduleAction)

-- | The time for the action to start in the channel.
scheduleAction_scheduleActionStartSettings :: Lens.Lens' ScheduleAction ScheduleActionStartSettings
scheduleAction_scheduleActionStartSettings :: (ScheduleActionStartSettings -> f ScheduleActionStartSettings)
-> ScheduleAction -> f ScheduleAction
scheduleAction_scheduleActionStartSettings = (ScheduleAction -> ScheduleActionStartSettings)
-> (ScheduleAction
    -> ScheduleActionStartSettings -> ScheduleAction)
-> Lens
     ScheduleAction
     ScheduleAction
     ScheduleActionStartSettings
     ScheduleActionStartSettings
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ScheduleAction' {ScheduleActionStartSettings
scheduleActionStartSettings :: ScheduleActionStartSettings
$sel:scheduleActionStartSettings:ScheduleAction' :: ScheduleAction -> ScheduleActionStartSettings
scheduleActionStartSettings} -> ScheduleActionStartSettings
scheduleActionStartSettings) (\s :: ScheduleAction
s@ScheduleAction' {} ScheduleActionStartSettings
a -> ScheduleAction
s {$sel:scheduleActionStartSettings:ScheduleAction' :: ScheduleActionStartSettings
scheduleActionStartSettings = ScheduleActionStartSettings
a} :: ScheduleAction)

-- | Settings for this schedule action.
scheduleAction_scheduleActionSettings :: Lens.Lens' ScheduleAction ScheduleActionSettings
scheduleAction_scheduleActionSettings :: (ScheduleActionSettings -> f ScheduleActionSettings)
-> ScheduleAction -> f ScheduleAction
scheduleAction_scheduleActionSettings = (ScheduleAction -> ScheduleActionSettings)
-> (ScheduleAction -> ScheduleActionSettings -> ScheduleAction)
-> Lens
     ScheduleAction
     ScheduleAction
     ScheduleActionSettings
     ScheduleActionSettings
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ScheduleAction' {ScheduleActionSettings
scheduleActionSettings :: ScheduleActionSettings
$sel:scheduleActionSettings:ScheduleAction' :: ScheduleAction -> ScheduleActionSettings
scheduleActionSettings} -> ScheduleActionSettings
scheduleActionSettings) (\s :: ScheduleAction
s@ScheduleAction' {} ScheduleActionSettings
a -> ScheduleAction
s {$sel:scheduleActionSettings:ScheduleAction' :: ScheduleActionSettings
scheduleActionSettings = ScheduleActionSettings
a} :: ScheduleAction)

instance Core.FromJSON ScheduleAction where
  parseJSON :: Value -> Parser ScheduleAction
parseJSON =
    String
-> (Object -> Parser ScheduleAction)
-> Value
-> Parser ScheduleAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ScheduleAction"
      ( \Object
x ->
          Text
-> ScheduleActionStartSettings
-> ScheduleActionSettings
-> ScheduleAction
ScheduleAction'
            (Text
 -> ScheduleActionStartSettings
 -> ScheduleActionSettings
 -> ScheduleAction)
-> Parser Text
-> Parser
     (ScheduleActionStartSettings
      -> ScheduleActionSettings -> ScheduleAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"actionName")
            Parser
  (ScheduleActionStartSettings
   -> ScheduleActionSettings -> ScheduleAction)
-> Parser ScheduleActionStartSettings
-> Parser (ScheduleActionSettings -> ScheduleAction)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ScheduleActionStartSettings
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"scheduleActionStartSettings")
            Parser (ScheduleActionSettings -> ScheduleAction)
-> Parser ScheduleActionSettings -> Parser ScheduleAction
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ScheduleActionSettings
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"scheduleActionSettings")
      )

instance Prelude.Hashable ScheduleAction

instance Prelude.NFData ScheduleAction

instance Core.ToJSON ScheduleAction where
  toJSON :: ScheduleAction -> Value
toJSON ScheduleAction' {Text
ScheduleActionStartSettings
ScheduleActionSettings
scheduleActionSettings :: ScheduleActionSettings
scheduleActionStartSettings :: ScheduleActionStartSettings
actionName :: Text
$sel:scheduleActionSettings:ScheduleAction' :: ScheduleAction -> ScheduleActionSettings
$sel:scheduleActionStartSettings:ScheduleAction' :: ScheduleAction -> ScheduleActionStartSettings
$sel:actionName:ScheduleAction' :: ScheduleAction -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"actionName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
actionName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"scheduleActionStartSettings"
                  Text -> ScheduleActionStartSettings -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ScheduleActionStartSettings
scheduleActionStartSettings
              ),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"scheduleActionSettings"
                  Text -> ScheduleActionSettings -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ScheduleActionSettings
scheduleActionSettings
              )
          ]
      )