{-# 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.Synthetics.Types.CanaryScheduleInput
-- 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.Synthetics.Types.CanaryScheduleInput where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | This structure specifies how often a canary is to make runs and the date
-- and time when it should stop making runs.
--
-- /See:/ 'newCanaryScheduleInput' smart constructor.
data CanaryScheduleInput = CanaryScheduleInput'
  { -- | How long, in seconds, for the canary to continue making regular runs
    -- according to the schedule in the @Expression@ value. If you specify 0,
    -- the canary continues making runs until you stop it. If you omit this
    -- field, the default of 0 is used.
    CanaryScheduleInput -> Maybe Natural
durationInSeconds :: Prelude.Maybe Prelude.Natural,
    -- | A @rate@ expression or a @cron@ expression that defines how often the
    -- canary is to run.
    --
    -- For a rate expression, The syntax is @rate(number unit)@. /unit/ can be
    -- @minute@, @minutes@, or @hour@.
    --
    -- For example, @rate(1 minute)@ runs the canary once a minute,
    -- @rate(10 minutes)@ runs it once every 10 minutes, and @rate(1 hour)@
    -- runs it once every hour. You can specify a frequency between
    -- @rate(1 minute)@ and @rate(1 hour)@.
    --
    -- Specifying @rate(0 minute)@ or @rate(0 hour)@ is a special value that
    -- causes the canary to run only once when it is started.
    --
    -- Use @cron(expression)@ to specify a cron expression. You can\'t schedule
    -- a canary to wait for more than a year before running. For information
    -- about the syntax for cron expressions, see
    -- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_cron.html Scheduling canary runs using cron>.
    CanaryScheduleInput -> Text
expression :: Prelude.Text
  }
  deriving (CanaryScheduleInput -> CanaryScheduleInput -> Bool
(CanaryScheduleInput -> CanaryScheduleInput -> Bool)
-> (CanaryScheduleInput -> CanaryScheduleInput -> Bool)
-> Eq CanaryScheduleInput
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CanaryScheduleInput -> CanaryScheduleInput -> Bool
$c/= :: CanaryScheduleInput -> CanaryScheduleInput -> Bool
== :: CanaryScheduleInput -> CanaryScheduleInput -> Bool
$c== :: CanaryScheduleInput -> CanaryScheduleInput -> Bool
Prelude.Eq, ReadPrec [CanaryScheduleInput]
ReadPrec CanaryScheduleInput
Int -> ReadS CanaryScheduleInput
ReadS [CanaryScheduleInput]
(Int -> ReadS CanaryScheduleInput)
-> ReadS [CanaryScheduleInput]
-> ReadPrec CanaryScheduleInput
-> ReadPrec [CanaryScheduleInput]
-> Read CanaryScheduleInput
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CanaryScheduleInput]
$creadListPrec :: ReadPrec [CanaryScheduleInput]
readPrec :: ReadPrec CanaryScheduleInput
$creadPrec :: ReadPrec CanaryScheduleInput
readList :: ReadS [CanaryScheduleInput]
$creadList :: ReadS [CanaryScheduleInput]
readsPrec :: Int -> ReadS CanaryScheduleInput
$creadsPrec :: Int -> ReadS CanaryScheduleInput
Prelude.Read, Int -> CanaryScheduleInput -> ShowS
[CanaryScheduleInput] -> ShowS
CanaryScheduleInput -> String
(Int -> CanaryScheduleInput -> ShowS)
-> (CanaryScheduleInput -> String)
-> ([CanaryScheduleInput] -> ShowS)
-> Show CanaryScheduleInput
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CanaryScheduleInput] -> ShowS
$cshowList :: [CanaryScheduleInput] -> ShowS
show :: CanaryScheduleInput -> String
$cshow :: CanaryScheduleInput -> String
showsPrec :: Int -> CanaryScheduleInput -> ShowS
$cshowsPrec :: Int -> CanaryScheduleInput -> ShowS
Prelude.Show, (forall x. CanaryScheduleInput -> Rep CanaryScheduleInput x)
-> (forall x. Rep CanaryScheduleInput x -> CanaryScheduleInput)
-> Generic CanaryScheduleInput
forall x. Rep CanaryScheduleInput x -> CanaryScheduleInput
forall x. CanaryScheduleInput -> Rep CanaryScheduleInput x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CanaryScheduleInput x -> CanaryScheduleInput
$cfrom :: forall x. CanaryScheduleInput -> Rep CanaryScheduleInput x
Prelude.Generic)

-- |
-- Create a value of 'CanaryScheduleInput' 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:
--
-- 'durationInSeconds', 'canaryScheduleInput_durationInSeconds' - How long, in seconds, for the canary to continue making regular runs
-- according to the schedule in the @Expression@ value. If you specify 0,
-- the canary continues making runs until you stop it. If you omit this
-- field, the default of 0 is used.
--
-- 'expression', 'canaryScheduleInput_expression' - A @rate@ expression or a @cron@ expression that defines how often the
-- canary is to run.
--
-- For a rate expression, The syntax is @rate(number unit)@. /unit/ can be
-- @minute@, @minutes@, or @hour@.
--
-- For example, @rate(1 minute)@ runs the canary once a minute,
-- @rate(10 minutes)@ runs it once every 10 minutes, and @rate(1 hour)@
-- runs it once every hour. You can specify a frequency between
-- @rate(1 minute)@ and @rate(1 hour)@.
--
-- Specifying @rate(0 minute)@ or @rate(0 hour)@ is a special value that
-- causes the canary to run only once when it is started.
--
-- Use @cron(expression)@ to specify a cron expression. You can\'t schedule
-- a canary to wait for more than a year before running. For information
-- about the syntax for cron expressions, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_cron.html Scheduling canary runs using cron>.
newCanaryScheduleInput ::
  -- | 'expression'
  Prelude.Text ->
  CanaryScheduleInput
newCanaryScheduleInput :: Text -> CanaryScheduleInput
newCanaryScheduleInput Text
pExpression_ =
  CanaryScheduleInput' :: Maybe Natural -> Text -> CanaryScheduleInput
CanaryScheduleInput'
    { $sel:durationInSeconds:CanaryScheduleInput' :: Maybe Natural
durationInSeconds =
        Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:expression:CanaryScheduleInput' :: Text
expression = Text
pExpression_
    }

-- | How long, in seconds, for the canary to continue making regular runs
-- according to the schedule in the @Expression@ value. If you specify 0,
-- the canary continues making runs until you stop it. If you omit this
-- field, the default of 0 is used.
canaryScheduleInput_durationInSeconds :: Lens.Lens' CanaryScheduleInput (Prelude.Maybe Prelude.Natural)
canaryScheduleInput_durationInSeconds :: (Maybe Natural -> f (Maybe Natural))
-> CanaryScheduleInput -> f CanaryScheduleInput
canaryScheduleInput_durationInSeconds = (CanaryScheduleInput -> Maybe Natural)
-> (CanaryScheduleInput -> Maybe Natural -> CanaryScheduleInput)
-> Lens
     CanaryScheduleInput
     CanaryScheduleInput
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CanaryScheduleInput' {Maybe Natural
durationInSeconds :: Maybe Natural
$sel:durationInSeconds:CanaryScheduleInput' :: CanaryScheduleInput -> Maybe Natural
durationInSeconds} -> Maybe Natural
durationInSeconds) (\s :: CanaryScheduleInput
s@CanaryScheduleInput' {} Maybe Natural
a -> CanaryScheduleInput
s {$sel:durationInSeconds:CanaryScheduleInput' :: Maybe Natural
durationInSeconds = Maybe Natural
a} :: CanaryScheduleInput)

-- | A @rate@ expression or a @cron@ expression that defines how often the
-- canary is to run.
--
-- For a rate expression, The syntax is @rate(number unit)@. /unit/ can be
-- @minute@, @minutes@, or @hour@.
--
-- For example, @rate(1 minute)@ runs the canary once a minute,
-- @rate(10 minutes)@ runs it once every 10 minutes, and @rate(1 hour)@
-- runs it once every hour. You can specify a frequency between
-- @rate(1 minute)@ and @rate(1 hour)@.
--
-- Specifying @rate(0 minute)@ or @rate(0 hour)@ is a special value that
-- causes the canary to run only once when it is started.
--
-- Use @cron(expression)@ to specify a cron expression. You can\'t schedule
-- a canary to wait for more than a year before running. For information
-- about the syntax for cron expressions, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_cron.html Scheduling canary runs using cron>.
canaryScheduleInput_expression :: Lens.Lens' CanaryScheduleInput Prelude.Text
canaryScheduleInput_expression :: (Text -> f Text) -> CanaryScheduleInput -> f CanaryScheduleInput
canaryScheduleInput_expression = (CanaryScheduleInput -> Text)
-> (CanaryScheduleInput -> Text -> CanaryScheduleInput)
-> Lens CanaryScheduleInput CanaryScheduleInput Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CanaryScheduleInput' {Text
expression :: Text
$sel:expression:CanaryScheduleInput' :: CanaryScheduleInput -> Text
expression} -> Text
expression) (\s :: CanaryScheduleInput
s@CanaryScheduleInput' {} Text
a -> CanaryScheduleInput
s {$sel:expression:CanaryScheduleInput' :: Text
expression = Text
a} :: CanaryScheduleInput)

instance Prelude.Hashable CanaryScheduleInput

instance Prelude.NFData CanaryScheduleInput

instance Core.ToJSON CanaryScheduleInput where
  toJSON :: CanaryScheduleInput -> Value
toJSON CanaryScheduleInput' {Maybe Natural
Text
expression :: Text
durationInSeconds :: Maybe Natural
$sel:expression:CanaryScheduleInput' :: CanaryScheduleInput -> Text
$sel:durationInSeconds:CanaryScheduleInput' :: CanaryScheduleInput -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"DurationInSeconds" 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
durationInSeconds,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Expression" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
expression)
          ]
      )