{-# 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.Glue.Types.Condition
-- 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.Glue.Types.Condition where

import qualified Amazonka.Core as Core
import Amazonka.Glue.Types.CrawlState
import Amazonka.Glue.Types.JobRunState
import Amazonka.Glue.Types.LogicalOperator
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Defines a condition under which a trigger fires.
--
-- /See:/ 'newCondition' smart constructor.
data Condition = Condition'
  { -- | The state of the crawler to which this condition applies.
    Condition -> Maybe CrawlState
crawlState :: Prelude.Maybe CrawlState,
    -- | The condition state. Currently, the only job states that a trigger can
    -- listen for are @SUCCEEDED@, @STOPPED@, @FAILED@, and @TIMEOUT@. The only
    -- crawler states that a trigger can listen for are @SUCCEEDED@, @FAILED@,
    -- and @CANCELLED@.
    Condition -> Maybe JobRunState
state :: Prelude.Maybe JobRunState,
    -- | The name of the job whose @JobRuns@ this condition applies to, and on
    -- which this trigger waits.
    Condition -> Maybe Text
jobName :: Prelude.Maybe Prelude.Text,
    -- | A logical operator.
    Condition -> Maybe LogicalOperator
logicalOperator :: Prelude.Maybe LogicalOperator,
    -- | The name of the crawler to which this condition applies.
    Condition -> Maybe Text
crawlerName :: Prelude.Maybe Prelude.Text
  }
  deriving (Condition -> Condition -> Bool
(Condition -> Condition -> Bool)
-> (Condition -> Condition -> Bool) -> Eq Condition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Condition -> Condition -> Bool
$c/= :: Condition -> Condition -> Bool
== :: Condition -> Condition -> Bool
$c== :: Condition -> Condition -> Bool
Prelude.Eq, ReadPrec [Condition]
ReadPrec Condition
Int -> ReadS Condition
ReadS [Condition]
(Int -> ReadS Condition)
-> ReadS [Condition]
-> ReadPrec Condition
-> ReadPrec [Condition]
-> Read Condition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Condition]
$creadListPrec :: ReadPrec [Condition]
readPrec :: ReadPrec Condition
$creadPrec :: ReadPrec Condition
readList :: ReadS [Condition]
$creadList :: ReadS [Condition]
readsPrec :: Int -> ReadS Condition
$creadsPrec :: Int -> ReadS Condition
Prelude.Read, Int -> Condition -> ShowS
[Condition] -> ShowS
Condition -> String
(Int -> Condition -> ShowS)
-> (Condition -> String)
-> ([Condition] -> ShowS)
-> Show Condition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Condition] -> ShowS
$cshowList :: [Condition] -> ShowS
show :: Condition -> String
$cshow :: Condition -> String
showsPrec :: Int -> Condition -> ShowS
$cshowsPrec :: Int -> Condition -> ShowS
Prelude.Show, (forall x. Condition -> Rep Condition x)
-> (forall x. Rep Condition x -> Condition) -> Generic Condition
forall x. Rep Condition x -> Condition
forall x. Condition -> Rep Condition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Condition x -> Condition
$cfrom :: forall x. Condition -> Rep Condition x
Prelude.Generic)

-- |
-- Create a value of 'Condition' 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:
--
-- 'crawlState', 'condition_crawlState' - The state of the crawler to which this condition applies.
--
-- 'state', 'condition_state' - The condition state. Currently, the only job states that a trigger can
-- listen for are @SUCCEEDED@, @STOPPED@, @FAILED@, and @TIMEOUT@. The only
-- crawler states that a trigger can listen for are @SUCCEEDED@, @FAILED@,
-- and @CANCELLED@.
--
-- 'jobName', 'condition_jobName' - The name of the job whose @JobRuns@ this condition applies to, and on
-- which this trigger waits.
--
-- 'logicalOperator', 'condition_logicalOperator' - A logical operator.
--
-- 'crawlerName', 'condition_crawlerName' - The name of the crawler to which this condition applies.
newCondition ::
  Condition
newCondition :: Condition
newCondition =
  Condition' :: Maybe CrawlState
-> Maybe JobRunState
-> Maybe Text
-> Maybe LogicalOperator
-> Maybe Text
-> Condition
Condition'
    { $sel:crawlState:Condition' :: Maybe CrawlState
crawlState = Maybe CrawlState
forall a. Maybe a
Prelude.Nothing,
      $sel:state:Condition' :: Maybe JobRunState
state = Maybe JobRunState
forall a. Maybe a
Prelude.Nothing,
      $sel:jobName:Condition' :: Maybe Text
jobName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:logicalOperator:Condition' :: Maybe LogicalOperator
logicalOperator = Maybe LogicalOperator
forall a. Maybe a
Prelude.Nothing,
      $sel:crawlerName:Condition' :: Maybe Text
crawlerName = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The state of the crawler to which this condition applies.
condition_crawlState :: Lens.Lens' Condition (Prelude.Maybe CrawlState)
condition_crawlState :: (Maybe CrawlState -> f (Maybe CrawlState))
-> Condition -> f Condition
condition_crawlState = (Condition -> Maybe CrawlState)
-> (Condition -> Maybe CrawlState -> Condition)
-> Lens Condition Condition (Maybe CrawlState) (Maybe CrawlState)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Condition' {Maybe CrawlState
crawlState :: Maybe CrawlState
$sel:crawlState:Condition' :: Condition -> Maybe CrawlState
crawlState} -> Maybe CrawlState
crawlState) (\s :: Condition
s@Condition' {} Maybe CrawlState
a -> Condition
s {$sel:crawlState:Condition' :: Maybe CrawlState
crawlState = Maybe CrawlState
a} :: Condition)

-- | The condition state. Currently, the only job states that a trigger can
-- listen for are @SUCCEEDED@, @STOPPED@, @FAILED@, and @TIMEOUT@. The only
-- crawler states that a trigger can listen for are @SUCCEEDED@, @FAILED@,
-- and @CANCELLED@.
condition_state :: Lens.Lens' Condition (Prelude.Maybe JobRunState)
condition_state :: (Maybe JobRunState -> f (Maybe JobRunState))
-> Condition -> f Condition
condition_state = (Condition -> Maybe JobRunState)
-> (Condition -> Maybe JobRunState -> Condition)
-> Lens Condition Condition (Maybe JobRunState) (Maybe JobRunState)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Condition' {Maybe JobRunState
state :: Maybe JobRunState
$sel:state:Condition' :: Condition -> Maybe JobRunState
state} -> Maybe JobRunState
state) (\s :: Condition
s@Condition' {} Maybe JobRunState
a -> Condition
s {$sel:state:Condition' :: Maybe JobRunState
state = Maybe JobRunState
a} :: Condition)

-- | The name of the job whose @JobRuns@ this condition applies to, and on
-- which this trigger waits.
condition_jobName :: Lens.Lens' Condition (Prelude.Maybe Prelude.Text)
condition_jobName :: (Maybe Text -> f (Maybe Text)) -> Condition -> f Condition
condition_jobName = (Condition -> Maybe Text)
-> (Condition -> Maybe Text -> Condition)
-> Lens Condition Condition (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Condition' {Maybe Text
jobName :: Maybe Text
$sel:jobName:Condition' :: Condition -> Maybe Text
jobName} -> Maybe Text
jobName) (\s :: Condition
s@Condition' {} Maybe Text
a -> Condition
s {$sel:jobName:Condition' :: Maybe Text
jobName = Maybe Text
a} :: Condition)

-- | A logical operator.
condition_logicalOperator :: Lens.Lens' Condition (Prelude.Maybe LogicalOperator)
condition_logicalOperator :: (Maybe LogicalOperator -> f (Maybe LogicalOperator))
-> Condition -> f Condition
condition_logicalOperator = (Condition -> Maybe LogicalOperator)
-> (Condition -> Maybe LogicalOperator -> Condition)
-> Lens
     Condition Condition (Maybe LogicalOperator) (Maybe LogicalOperator)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Condition' {Maybe LogicalOperator
logicalOperator :: Maybe LogicalOperator
$sel:logicalOperator:Condition' :: Condition -> Maybe LogicalOperator
logicalOperator} -> Maybe LogicalOperator
logicalOperator) (\s :: Condition
s@Condition' {} Maybe LogicalOperator
a -> Condition
s {$sel:logicalOperator:Condition' :: Maybe LogicalOperator
logicalOperator = Maybe LogicalOperator
a} :: Condition)

-- | The name of the crawler to which this condition applies.
condition_crawlerName :: Lens.Lens' Condition (Prelude.Maybe Prelude.Text)
condition_crawlerName :: (Maybe Text -> f (Maybe Text)) -> Condition -> f Condition
condition_crawlerName = (Condition -> Maybe Text)
-> (Condition -> Maybe Text -> Condition)
-> Lens Condition Condition (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Condition' {Maybe Text
crawlerName :: Maybe Text
$sel:crawlerName:Condition' :: Condition -> Maybe Text
crawlerName} -> Maybe Text
crawlerName) (\s :: Condition
s@Condition' {} Maybe Text
a -> Condition
s {$sel:crawlerName:Condition' :: Maybe Text
crawlerName = Maybe Text
a} :: Condition)

instance Core.FromJSON Condition where
  parseJSON :: Value -> Parser Condition
parseJSON =
    String -> (Object -> Parser Condition) -> Value -> Parser Condition
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Condition"
      ( \Object
x ->
          Maybe CrawlState
-> Maybe JobRunState
-> Maybe Text
-> Maybe LogicalOperator
-> Maybe Text
-> Condition
Condition'
            (Maybe CrawlState
 -> Maybe JobRunState
 -> Maybe Text
 -> Maybe LogicalOperator
 -> Maybe Text
 -> Condition)
-> Parser (Maybe CrawlState)
-> Parser
     (Maybe JobRunState
      -> Maybe Text -> Maybe LogicalOperator -> Maybe Text -> Condition)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe CrawlState)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"CrawlState")
            Parser
  (Maybe JobRunState
   -> Maybe Text -> Maybe LogicalOperator -> Maybe Text -> Condition)
-> Parser (Maybe JobRunState)
-> Parser
     (Maybe Text -> Maybe LogicalOperator -> Maybe Text -> Condition)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe JobRunState)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"State")
            Parser
  (Maybe Text -> Maybe LogicalOperator -> Maybe Text -> Condition)
-> Parser (Maybe Text)
-> Parser (Maybe LogicalOperator -> Maybe Text -> Condition)
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
"JobName")
            Parser (Maybe LogicalOperator -> Maybe Text -> Condition)
-> Parser (Maybe LogicalOperator)
-> Parser (Maybe Text -> Condition)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe LogicalOperator)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"LogicalOperator")
            Parser (Maybe Text -> Condition)
-> Parser (Maybe Text) -> Parser Condition
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
"CrawlerName")
      )

instance Prelude.Hashable Condition

instance Prelude.NFData Condition

instance Core.ToJSON Condition where
  toJSON :: Condition -> Value
toJSON Condition' {Maybe Text
Maybe CrawlState
Maybe JobRunState
Maybe LogicalOperator
crawlerName :: Maybe Text
logicalOperator :: Maybe LogicalOperator
jobName :: Maybe Text
state :: Maybe JobRunState
crawlState :: Maybe CrawlState
$sel:crawlerName:Condition' :: Condition -> Maybe Text
$sel:logicalOperator:Condition' :: Condition -> Maybe LogicalOperator
$sel:jobName:Condition' :: Condition -> Maybe Text
$sel:state:Condition' :: Condition -> Maybe JobRunState
$sel:crawlState:Condition' :: Condition -> Maybe CrawlState
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"CrawlState" Text -> CrawlState -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (CrawlState -> Pair) -> Maybe CrawlState -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe CrawlState
crawlState,
            (Text
"State" Text -> JobRunState -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (JobRunState -> Pair) -> Maybe JobRunState -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe JobRunState
state,
            (Text
"JobName" 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
jobName,
            (Text
"LogicalOperator" Text -> LogicalOperator -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (LogicalOperator -> Pair) -> Maybe LogicalOperator -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe LogicalOperator
logicalOperator,
            (Text
"CrawlerName" 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
crawlerName
          ]
      )