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

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

-- | The schedule for when to trigger an update.
--
-- /See:/ 'newSchedule' smart constructor.
data Schedule = Schedule'
  { -- | The expression that defines when to trigger an update. For more
    -- information, see
    -- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html Schedule Expressions for Rules>
    -- in the /Amazon CloudWatch Events User Guide/.
    Schedule -> Maybe Text
expression :: 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:
--
-- 'expression', 'schedule_expression' - The expression that defines when to trigger an update. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html Schedule Expressions for Rules>
-- in the /Amazon CloudWatch Events User Guide/.
newSchedule ::
  Schedule
newSchedule :: Schedule
newSchedule = Schedule' :: Maybe Text -> Schedule
Schedule' {$sel:expression:Schedule' :: Maybe Text
expression = Maybe Text
forall a. Maybe a
Prelude.Nothing}

-- | The expression that defines when to trigger an update. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html Schedule Expressions for Rules>
-- in the /Amazon CloudWatch Events User Guide/.
schedule_expression :: Lens.Lens' Schedule (Prelude.Maybe Prelude.Text)
schedule_expression :: (Maybe Text -> f (Maybe Text)) -> Schedule -> f Schedule
schedule_expression = (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
expression :: Maybe Text
$sel:expression:Schedule' :: Schedule -> Maybe Text
expression} -> Maybe Text
expression) (\s :: Schedule
s@Schedule' {} Maybe Text
a -> Schedule
s {$sel:expression:Schedule' :: Maybe Text
expression = 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 -> Schedule
Schedule' (Maybe Text -> Schedule) -> Parser (Maybe Text) -> Parser 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
"expression")
      )

instance Prelude.Hashable Schedule

instance Prelude.NFData Schedule

instance Core.ToJSON Schedule where
  toJSON :: Schedule -> Value
toJSON Schedule' {Maybe Text
expression :: Maybe Text
$sel:expression:Schedule' :: Schedule -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"expression" 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
expression]
      )