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

import qualified Amazonka.Core as Core
import Amazonka.IoTAnalytics.Types.Schedule
import Amazonka.IoTAnalytics.Types.TriggeringDataset
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The @DatasetTrigger@ that specifies when the dataset is automatically
-- updated.
--
-- /See:/ 'newDatasetTrigger' smart constructor.
data DatasetTrigger = DatasetTrigger'
  { -- | The dataset whose content creation triggers the creation of this
    -- dataset\'s contents.
    DatasetTrigger -> Maybe TriggeringDataset
dataset :: Prelude.Maybe TriggeringDataset,
    -- | The Schedule when the trigger is initiated.
    DatasetTrigger -> Maybe Schedule
schedule :: Prelude.Maybe Schedule
  }
  deriving (DatasetTrigger -> DatasetTrigger -> Bool
(DatasetTrigger -> DatasetTrigger -> Bool)
-> (DatasetTrigger -> DatasetTrigger -> Bool) -> Eq DatasetTrigger
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DatasetTrigger -> DatasetTrigger -> Bool
$c/= :: DatasetTrigger -> DatasetTrigger -> Bool
== :: DatasetTrigger -> DatasetTrigger -> Bool
$c== :: DatasetTrigger -> DatasetTrigger -> Bool
Prelude.Eq, ReadPrec [DatasetTrigger]
ReadPrec DatasetTrigger
Int -> ReadS DatasetTrigger
ReadS [DatasetTrigger]
(Int -> ReadS DatasetTrigger)
-> ReadS [DatasetTrigger]
-> ReadPrec DatasetTrigger
-> ReadPrec [DatasetTrigger]
-> Read DatasetTrigger
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DatasetTrigger]
$creadListPrec :: ReadPrec [DatasetTrigger]
readPrec :: ReadPrec DatasetTrigger
$creadPrec :: ReadPrec DatasetTrigger
readList :: ReadS [DatasetTrigger]
$creadList :: ReadS [DatasetTrigger]
readsPrec :: Int -> ReadS DatasetTrigger
$creadsPrec :: Int -> ReadS DatasetTrigger
Prelude.Read, Int -> DatasetTrigger -> ShowS
[DatasetTrigger] -> ShowS
DatasetTrigger -> String
(Int -> DatasetTrigger -> ShowS)
-> (DatasetTrigger -> String)
-> ([DatasetTrigger] -> ShowS)
-> Show DatasetTrigger
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DatasetTrigger] -> ShowS
$cshowList :: [DatasetTrigger] -> ShowS
show :: DatasetTrigger -> String
$cshow :: DatasetTrigger -> String
showsPrec :: Int -> DatasetTrigger -> ShowS
$cshowsPrec :: Int -> DatasetTrigger -> ShowS
Prelude.Show, (forall x. DatasetTrigger -> Rep DatasetTrigger x)
-> (forall x. Rep DatasetTrigger x -> DatasetTrigger)
-> Generic DatasetTrigger
forall x. Rep DatasetTrigger x -> DatasetTrigger
forall x. DatasetTrigger -> Rep DatasetTrigger x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DatasetTrigger x -> DatasetTrigger
$cfrom :: forall x. DatasetTrigger -> Rep DatasetTrigger x
Prelude.Generic)

-- |
-- Create a value of 'DatasetTrigger' 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:
--
-- 'dataset', 'datasetTrigger_dataset' - The dataset whose content creation triggers the creation of this
-- dataset\'s contents.
--
-- 'schedule', 'datasetTrigger_schedule' - The Schedule when the trigger is initiated.
newDatasetTrigger ::
  DatasetTrigger
newDatasetTrigger :: DatasetTrigger
newDatasetTrigger =
  DatasetTrigger' :: Maybe TriggeringDataset -> Maybe Schedule -> DatasetTrigger
DatasetTrigger'
    { $sel:dataset:DatasetTrigger' :: Maybe TriggeringDataset
dataset = Maybe TriggeringDataset
forall a. Maybe a
Prelude.Nothing,
      $sel:schedule:DatasetTrigger' :: Maybe Schedule
schedule = Maybe Schedule
forall a. Maybe a
Prelude.Nothing
    }

-- | The dataset whose content creation triggers the creation of this
-- dataset\'s contents.
datasetTrigger_dataset :: Lens.Lens' DatasetTrigger (Prelude.Maybe TriggeringDataset)
datasetTrigger_dataset :: (Maybe TriggeringDataset -> f (Maybe TriggeringDataset))
-> DatasetTrigger -> f DatasetTrigger
datasetTrigger_dataset = (DatasetTrigger -> Maybe TriggeringDataset)
-> (DatasetTrigger -> Maybe TriggeringDataset -> DatasetTrigger)
-> Lens
     DatasetTrigger
     DatasetTrigger
     (Maybe TriggeringDataset)
     (Maybe TriggeringDataset)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DatasetTrigger' {Maybe TriggeringDataset
dataset :: Maybe TriggeringDataset
$sel:dataset:DatasetTrigger' :: DatasetTrigger -> Maybe TriggeringDataset
dataset} -> Maybe TriggeringDataset
dataset) (\s :: DatasetTrigger
s@DatasetTrigger' {} Maybe TriggeringDataset
a -> DatasetTrigger
s {$sel:dataset:DatasetTrigger' :: Maybe TriggeringDataset
dataset = Maybe TriggeringDataset
a} :: DatasetTrigger)

-- | The Schedule when the trigger is initiated.
datasetTrigger_schedule :: Lens.Lens' DatasetTrigger (Prelude.Maybe Schedule)
datasetTrigger_schedule :: (Maybe Schedule -> f (Maybe Schedule))
-> DatasetTrigger -> f DatasetTrigger
datasetTrigger_schedule = (DatasetTrigger -> Maybe Schedule)
-> (DatasetTrigger -> Maybe Schedule -> DatasetTrigger)
-> Lens
     DatasetTrigger DatasetTrigger (Maybe Schedule) (Maybe Schedule)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DatasetTrigger' {Maybe Schedule
schedule :: Maybe Schedule
$sel:schedule:DatasetTrigger' :: DatasetTrigger -> Maybe Schedule
schedule} -> Maybe Schedule
schedule) (\s :: DatasetTrigger
s@DatasetTrigger' {} Maybe Schedule
a -> DatasetTrigger
s {$sel:schedule:DatasetTrigger' :: Maybe Schedule
schedule = Maybe Schedule
a} :: DatasetTrigger)

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

instance Prelude.Hashable DatasetTrigger

instance Prelude.NFData DatasetTrigger

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