{-# 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.ImageBuilder.Types.Schedule
-- 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.ImageBuilder.Types.Schedule where

import qualified Amazonka.Core as Core
import Amazonka.ImageBuilder.Types.PipelineExecutionStartCondition
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A schedule configures how often and when a pipeline will automatically
-- create a new image.
--
-- /See:/ 'newSchedule' smart constructor.
data Schedule = Schedule'
  { -- | The cron expression determines how often EC2 Image Builder evaluates
    -- your @pipelineExecutionStartCondition@.
    --
    -- For information on how to format a cron expression in Image Builder, see
    -- <https://docs.aws.amazon.com/imagebuilder/latest/userguide/image-builder-cron.html Use cron expressions in EC2 Image Builder>.
    Schedule -> Maybe Text
scheduleExpression :: Prelude.Maybe Prelude.Text,
    -- | The condition configures when the pipeline should trigger a new image
    -- build. When the @pipelineExecutionStartCondition@ is set to
    -- @EXPRESSION_MATCH_AND_DEPENDENCY_UPDATES_AVAILABLE@, and you use
    -- semantic version filters on the base image or components in your image
    -- recipe, EC2 Image Builder will build a new image only when there are new
    -- versions of the image or components in your recipe that match the
    -- semantic version filter. When it is set to @EXPRESSION_MATCH_ONLY@, it
    -- will build a new image every time the CRON expression matches the
    -- current time. For semantic version syntax, see
    -- <https://docs.aws.amazon.com/imagebuilder/latest/APIReference/API_CreateComponent.html CreateComponent>
    -- in the /EC2 Image Builder API Reference/.
    Schedule -> Maybe PipelineExecutionStartCondition
pipelineExecutionStartCondition :: Prelude.Maybe PipelineExecutionStartCondition,
    -- | The timezone that applies to the scheduling expression. For example,
    -- \"Etc\/UTC\", \"America\/Los_Angeles\" in the
    -- <https://www.joda.org/joda-time/timezones.html IANA timezone format>. If
    -- not specified this defaults to UTC.
    Schedule -> Maybe Text
timezone :: Prelude.Maybe Prelude.Text
  }
  deriving (Schedule -> Schedule -> Bool
(Schedule -> Schedule -> Bool)
-> (Schedule -> Schedule -> Bool) -> Eq Schedule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Schedule -> Schedule -> Bool
$c/= :: Schedule -> Schedule -> Bool
== :: Schedule -> Schedule -> Bool
$c== :: Schedule -> Schedule -> Bool
Prelude.Eq, ReadPrec [Schedule]
ReadPrec Schedule
Int -> ReadS Schedule
ReadS [Schedule]
(Int -> ReadS Schedule)
-> ReadS [Schedule]
-> ReadPrec Schedule
-> ReadPrec [Schedule]
-> Read Schedule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Schedule]
$creadListPrec :: ReadPrec [Schedule]
readPrec :: ReadPrec Schedule
$creadPrec :: ReadPrec Schedule
readList :: ReadS [Schedule]
$creadList :: ReadS [Schedule]
readsPrec :: Int -> ReadS Schedule
$creadsPrec :: Int -> ReadS Schedule
Prelude.Read, Int -> Schedule -> ShowS
[Schedule] -> ShowS
Schedule -> String
(Int -> Schedule -> ShowS)
-> (Schedule -> String) -> ([Schedule] -> ShowS) -> Show Schedule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Schedule] -> ShowS
$cshowList :: [Schedule] -> ShowS
show :: Schedule -> String
$cshow :: Schedule -> String
showsPrec :: Int -> Schedule -> ShowS
$cshowsPrec :: Int -> Schedule -> ShowS
Prelude.Show, (forall x. Schedule -> Rep Schedule x)
-> (forall x. Rep Schedule x -> Schedule) -> Generic Schedule
forall x. Rep Schedule x -> Schedule
forall x. Schedule -> Rep Schedule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Schedule x -> Schedule
$cfrom :: forall x. Schedule -> Rep Schedule x
Prelude.Generic)

-- |
-- Create a value of 'Schedule' 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:
--
-- 'scheduleExpression', 'schedule_scheduleExpression' - The cron expression determines how often EC2 Image Builder evaluates
-- your @pipelineExecutionStartCondition@.
--
-- For information on how to format a cron expression in Image Builder, see
-- <https://docs.aws.amazon.com/imagebuilder/latest/userguide/image-builder-cron.html Use cron expressions in EC2 Image Builder>.
--
-- 'pipelineExecutionStartCondition', 'schedule_pipelineExecutionStartCondition' - The condition configures when the pipeline should trigger a new image
-- build. When the @pipelineExecutionStartCondition@ is set to
-- @EXPRESSION_MATCH_AND_DEPENDENCY_UPDATES_AVAILABLE@, and you use
-- semantic version filters on the base image or components in your image
-- recipe, EC2 Image Builder will build a new image only when there are new
-- versions of the image or components in your recipe that match the
-- semantic version filter. When it is set to @EXPRESSION_MATCH_ONLY@, it
-- will build a new image every time the CRON expression matches the
-- current time. For semantic version syntax, see
-- <https://docs.aws.amazon.com/imagebuilder/latest/APIReference/API_CreateComponent.html CreateComponent>
-- in the /EC2 Image Builder API Reference/.
--
-- 'timezone', 'schedule_timezone' - The timezone that applies to the scheduling expression. For example,
-- \"Etc\/UTC\", \"America\/Los_Angeles\" in the
-- <https://www.joda.org/joda-time/timezones.html IANA timezone format>. If
-- not specified this defaults to UTC.
newSchedule ::
  Schedule
newSchedule :: Schedule
newSchedule =
  Schedule' :: Maybe Text
-> Maybe PipelineExecutionStartCondition -> Maybe Text -> Schedule
Schedule'
    { $sel:scheduleExpression:Schedule' :: Maybe Text
scheduleExpression = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:pipelineExecutionStartCondition:Schedule' :: Maybe PipelineExecutionStartCondition
pipelineExecutionStartCondition = Maybe PipelineExecutionStartCondition
forall a. Maybe a
Prelude.Nothing,
      $sel:timezone:Schedule' :: Maybe Text
timezone = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The cron expression determines how often EC2 Image Builder evaluates
-- your @pipelineExecutionStartCondition@.
--
-- For information on how to format a cron expression in Image Builder, see
-- <https://docs.aws.amazon.com/imagebuilder/latest/userguide/image-builder-cron.html Use cron expressions in EC2 Image Builder>.
schedule_scheduleExpression :: Lens.Lens' Schedule (Prelude.Maybe Prelude.Text)
schedule_scheduleExpression :: (Maybe Text -> f (Maybe Text)) -> Schedule -> f Schedule
schedule_scheduleExpression = (Schedule -> Maybe Text)
-> (Schedule -> Maybe Text -> Schedule)
-> Lens Schedule Schedule (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Schedule' {Maybe Text
scheduleExpression :: Maybe Text
$sel:scheduleExpression:Schedule' :: Schedule -> Maybe Text
scheduleExpression} -> Maybe Text
scheduleExpression) (\s :: Schedule
s@Schedule' {} Maybe Text
a -> Schedule
s {$sel:scheduleExpression:Schedule' :: Maybe Text
scheduleExpression = Maybe Text
a} :: Schedule)

-- | The condition configures when the pipeline should trigger a new image
-- build. When the @pipelineExecutionStartCondition@ is set to
-- @EXPRESSION_MATCH_AND_DEPENDENCY_UPDATES_AVAILABLE@, and you use
-- semantic version filters on the base image or components in your image
-- recipe, EC2 Image Builder will build a new image only when there are new
-- versions of the image or components in your recipe that match the
-- semantic version filter. When it is set to @EXPRESSION_MATCH_ONLY@, it
-- will build a new image every time the CRON expression matches the
-- current time. For semantic version syntax, see
-- <https://docs.aws.amazon.com/imagebuilder/latest/APIReference/API_CreateComponent.html CreateComponent>
-- in the /EC2 Image Builder API Reference/.
schedule_pipelineExecutionStartCondition :: Lens.Lens' Schedule (Prelude.Maybe PipelineExecutionStartCondition)
schedule_pipelineExecutionStartCondition :: (Maybe PipelineExecutionStartCondition
 -> f (Maybe PipelineExecutionStartCondition))
-> Schedule -> f Schedule
schedule_pipelineExecutionStartCondition = (Schedule -> Maybe PipelineExecutionStartCondition)
-> (Schedule -> Maybe PipelineExecutionStartCondition -> Schedule)
-> Lens
     Schedule
     Schedule
     (Maybe PipelineExecutionStartCondition)
     (Maybe PipelineExecutionStartCondition)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Schedule' {Maybe PipelineExecutionStartCondition
pipelineExecutionStartCondition :: Maybe PipelineExecutionStartCondition
$sel:pipelineExecutionStartCondition:Schedule' :: Schedule -> Maybe PipelineExecutionStartCondition
pipelineExecutionStartCondition} -> Maybe PipelineExecutionStartCondition
pipelineExecutionStartCondition) (\s :: Schedule
s@Schedule' {} Maybe PipelineExecutionStartCondition
a -> Schedule
s {$sel:pipelineExecutionStartCondition:Schedule' :: Maybe PipelineExecutionStartCondition
pipelineExecutionStartCondition = Maybe PipelineExecutionStartCondition
a} :: Schedule)

-- | The timezone that applies to the scheduling expression. For example,
-- \"Etc\/UTC\", \"America\/Los_Angeles\" in the
-- <https://www.joda.org/joda-time/timezones.html IANA timezone format>. If
-- not specified this defaults to UTC.
schedule_timezone :: Lens.Lens' Schedule (Prelude.Maybe Prelude.Text)
schedule_timezone :: (Maybe Text -> f (Maybe Text)) -> Schedule -> f Schedule
schedule_timezone = (Schedule -> Maybe Text)
-> (Schedule -> Maybe Text -> Schedule)
-> Lens Schedule Schedule (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Schedule' {Maybe Text
timezone :: Maybe Text
$sel:timezone:Schedule' :: Schedule -> Maybe Text
timezone} -> Maybe Text
timezone) (\s :: Schedule
s@Schedule' {} Maybe Text
a -> Schedule
s {$sel:timezone:Schedule' :: Maybe Text
timezone = Maybe Text
a} :: Schedule)

instance Core.FromJSON Schedule where
  parseJSON :: Value -> Parser Schedule
parseJSON =
    String -> (Object -> Parser Schedule) -> Value -> Parser Schedule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Schedule"
      ( \Object
x ->
          Maybe Text
-> Maybe PipelineExecutionStartCondition -> Maybe Text -> Schedule
Schedule'
            (Maybe Text
 -> Maybe PipelineExecutionStartCondition -> Maybe Text -> Schedule)
-> Parser (Maybe Text)
-> Parser
     (Maybe PipelineExecutionStartCondition -> Maybe Text -> Schedule)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"scheduleExpression")
            Parser
  (Maybe PipelineExecutionStartCondition -> Maybe Text -> Schedule)
-> Parser (Maybe PipelineExecutionStartCondition)
-> Parser (Maybe Text -> Schedule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe PipelineExecutionStartCondition)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"pipelineExecutionStartCondition")
            Parser (Maybe Text -> Schedule)
-> Parser (Maybe Text) -> Parser Schedule
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"timezone")
      )

instance Prelude.Hashable Schedule

instance Prelude.NFData Schedule

instance Core.ToJSON Schedule where
  toJSON :: Schedule -> Value
toJSON Schedule' {Maybe Text
Maybe PipelineExecutionStartCondition
timezone :: Maybe Text
pipelineExecutionStartCondition :: Maybe PipelineExecutionStartCondition
scheduleExpression :: Maybe Text
$sel:timezone:Schedule' :: Schedule -> Maybe Text
$sel:pipelineExecutionStartCondition:Schedule' :: Schedule -> Maybe PipelineExecutionStartCondition
$sel:scheduleExpression:Schedule' :: Schedule -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"scheduleExpression" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
scheduleExpression,
            (Text
"pipelineExecutionStartCondition" Text -> PipelineExecutionStartCondition -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (PipelineExecutionStartCondition -> Pair)
-> Maybe PipelineExecutionStartCondition -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe PipelineExecutionStartCondition
pipelineExecutionStartCondition,
            (Text
"timezone" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
timezone
          ]
      )