{-# 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.Scheduler.Types.FlexibleTimeWindow
-- 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.Scheduler.Types.FlexibleTimeWindow where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import Amazonka.Scheduler.Types.FlexibleTimeWindowMode

-- | Allows you to configure a time window during which EventBridge Scheduler
-- invokes the schedule.
--
-- /See:/ 'newFlexibleTimeWindow' smart constructor.
data FlexibleTimeWindow = FlexibleTimeWindow'
  { -- | The maximum time window during which a schedule can be invoked.
    FlexibleTimeWindow -> Maybe Natural
maximumWindowInMinutes :: Prelude.Maybe Prelude.Natural,
    -- | Determines whether the schedule is invoked within a flexible time
    -- window.
    FlexibleTimeWindow -> FlexibleTimeWindowMode
mode :: FlexibleTimeWindowMode
  }
  deriving (FlexibleTimeWindow -> FlexibleTimeWindow -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FlexibleTimeWindow -> FlexibleTimeWindow -> Bool
$c/= :: FlexibleTimeWindow -> FlexibleTimeWindow -> Bool
== :: FlexibleTimeWindow -> FlexibleTimeWindow -> Bool
$c== :: FlexibleTimeWindow -> FlexibleTimeWindow -> Bool
Prelude.Eq, ReadPrec [FlexibleTimeWindow]
ReadPrec FlexibleTimeWindow
Int -> ReadS FlexibleTimeWindow
ReadS [FlexibleTimeWindow]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FlexibleTimeWindow]
$creadListPrec :: ReadPrec [FlexibleTimeWindow]
readPrec :: ReadPrec FlexibleTimeWindow
$creadPrec :: ReadPrec FlexibleTimeWindow
readList :: ReadS [FlexibleTimeWindow]
$creadList :: ReadS [FlexibleTimeWindow]
readsPrec :: Int -> ReadS FlexibleTimeWindow
$creadsPrec :: Int -> ReadS FlexibleTimeWindow
Prelude.Read, Int -> FlexibleTimeWindow -> ShowS
[FlexibleTimeWindow] -> ShowS
FlexibleTimeWindow -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FlexibleTimeWindow] -> ShowS
$cshowList :: [FlexibleTimeWindow] -> ShowS
show :: FlexibleTimeWindow -> String
$cshow :: FlexibleTimeWindow -> String
showsPrec :: Int -> FlexibleTimeWindow -> ShowS
$cshowsPrec :: Int -> FlexibleTimeWindow -> ShowS
Prelude.Show, forall x. Rep FlexibleTimeWindow x -> FlexibleTimeWindow
forall x. FlexibleTimeWindow -> Rep FlexibleTimeWindow x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FlexibleTimeWindow x -> FlexibleTimeWindow
$cfrom :: forall x. FlexibleTimeWindow -> Rep FlexibleTimeWindow x
Prelude.Generic)

-- |
-- Create a value of 'FlexibleTimeWindow' 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:
--
-- 'maximumWindowInMinutes', 'flexibleTimeWindow_maximumWindowInMinutes' - The maximum time window during which a schedule can be invoked.
--
-- 'mode', 'flexibleTimeWindow_mode' - Determines whether the schedule is invoked within a flexible time
-- window.
newFlexibleTimeWindow ::
  -- | 'mode'
  FlexibleTimeWindowMode ->
  FlexibleTimeWindow
newFlexibleTimeWindow :: FlexibleTimeWindowMode -> FlexibleTimeWindow
newFlexibleTimeWindow FlexibleTimeWindowMode
pMode_ =
  FlexibleTimeWindow'
    { $sel:maximumWindowInMinutes:FlexibleTimeWindow' :: Maybe Natural
maximumWindowInMinutes =
        forall a. Maybe a
Prelude.Nothing,
      $sel:mode:FlexibleTimeWindow' :: FlexibleTimeWindowMode
mode = FlexibleTimeWindowMode
pMode_
    }

-- | The maximum time window during which a schedule can be invoked.
flexibleTimeWindow_maximumWindowInMinutes :: Lens.Lens' FlexibleTimeWindow (Prelude.Maybe Prelude.Natural)
flexibleTimeWindow_maximumWindowInMinutes :: Lens' FlexibleTimeWindow (Maybe Natural)
flexibleTimeWindow_maximumWindowInMinutes = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FlexibleTimeWindow' {Maybe Natural
maximumWindowInMinutes :: Maybe Natural
$sel:maximumWindowInMinutes:FlexibleTimeWindow' :: FlexibleTimeWindow -> Maybe Natural
maximumWindowInMinutes} -> Maybe Natural
maximumWindowInMinutes) (\s :: FlexibleTimeWindow
s@FlexibleTimeWindow' {} Maybe Natural
a -> FlexibleTimeWindow
s {$sel:maximumWindowInMinutes:FlexibleTimeWindow' :: Maybe Natural
maximumWindowInMinutes = Maybe Natural
a} :: FlexibleTimeWindow)

-- | Determines whether the schedule is invoked within a flexible time
-- window.
flexibleTimeWindow_mode :: Lens.Lens' FlexibleTimeWindow FlexibleTimeWindowMode
flexibleTimeWindow_mode :: Lens' FlexibleTimeWindow FlexibleTimeWindowMode
flexibleTimeWindow_mode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FlexibleTimeWindow' {FlexibleTimeWindowMode
mode :: FlexibleTimeWindowMode
$sel:mode:FlexibleTimeWindow' :: FlexibleTimeWindow -> FlexibleTimeWindowMode
mode} -> FlexibleTimeWindowMode
mode) (\s :: FlexibleTimeWindow
s@FlexibleTimeWindow' {} FlexibleTimeWindowMode
a -> FlexibleTimeWindow
s {$sel:mode:FlexibleTimeWindow' :: FlexibleTimeWindowMode
mode = FlexibleTimeWindowMode
a} :: FlexibleTimeWindow)

instance Data.FromJSON FlexibleTimeWindow where
  parseJSON :: Value -> Parser FlexibleTimeWindow
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"FlexibleTimeWindow"
      ( \Object
x ->
          Maybe Natural -> FlexibleTimeWindowMode -> FlexibleTimeWindow
FlexibleTimeWindow'
            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
"MaximumWindowInMinutes")
            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
"Mode")
      )

instance Prelude.Hashable FlexibleTimeWindow where
  hashWithSalt :: Int -> FlexibleTimeWindow -> Int
hashWithSalt Int
_salt FlexibleTimeWindow' {Maybe Natural
FlexibleTimeWindowMode
mode :: FlexibleTimeWindowMode
maximumWindowInMinutes :: Maybe Natural
$sel:mode:FlexibleTimeWindow' :: FlexibleTimeWindow -> FlexibleTimeWindowMode
$sel:maximumWindowInMinutes:FlexibleTimeWindow' :: FlexibleTimeWindow -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
maximumWindowInMinutes
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` FlexibleTimeWindowMode
mode

instance Prelude.NFData FlexibleTimeWindow where
  rnf :: FlexibleTimeWindow -> ()
rnf FlexibleTimeWindow' {Maybe Natural
FlexibleTimeWindowMode
mode :: FlexibleTimeWindowMode
maximumWindowInMinutes :: Maybe Natural
$sel:mode:FlexibleTimeWindow' :: FlexibleTimeWindow -> FlexibleTimeWindowMode
$sel:maximumWindowInMinutes:FlexibleTimeWindow' :: FlexibleTimeWindow -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
maximumWindowInMinutes
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf FlexibleTimeWindowMode
mode

instance Data.ToJSON FlexibleTimeWindow where
  toJSON :: FlexibleTimeWindow -> Value
toJSON FlexibleTimeWindow' {Maybe Natural
FlexibleTimeWindowMode
mode :: FlexibleTimeWindowMode
maximumWindowInMinutes :: Maybe Natural
$sel:mode:FlexibleTimeWindow' :: FlexibleTimeWindow -> FlexibleTimeWindowMode
$sel:maximumWindowInMinutes:FlexibleTimeWindow' :: FlexibleTimeWindow -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"MaximumWindowInMinutes" 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
maximumWindowInMinutes,
            forall a. a -> Maybe a
Prelude.Just (Key
"Mode" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= FlexibleTimeWindowMode
mode)
          ]
      )