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

import qualified Amazonka.Core as Core
import Amazonka.Glue.Types.Condition
import Amazonka.Glue.Types.Logical
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Defines the predicate of the trigger, which determines when it fires.
--
-- /See:/ 'newPredicate' smart constructor.
data Predicate = Predicate'
  { -- | An optional field if only one condition is listed. If multiple
    -- conditions are listed, then this field is required.
    Predicate -> Maybe Logical
logical :: Prelude.Maybe Logical,
    -- | A list of the conditions that determine when the trigger will fire.
    Predicate -> Maybe [Condition]
conditions :: Prelude.Maybe [Condition]
  }
  deriving (Predicate -> Predicate -> Bool
(Predicate -> Predicate -> Bool)
-> (Predicate -> Predicate -> Bool) -> Eq Predicate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Predicate -> Predicate -> Bool
$c/= :: Predicate -> Predicate -> Bool
== :: Predicate -> Predicate -> Bool
$c== :: Predicate -> Predicate -> Bool
Prelude.Eq, ReadPrec [Predicate]
ReadPrec Predicate
Int -> ReadS Predicate
ReadS [Predicate]
(Int -> ReadS Predicate)
-> ReadS [Predicate]
-> ReadPrec Predicate
-> ReadPrec [Predicate]
-> Read Predicate
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Predicate]
$creadListPrec :: ReadPrec [Predicate]
readPrec :: ReadPrec Predicate
$creadPrec :: ReadPrec Predicate
readList :: ReadS [Predicate]
$creadList :: ReadS [Predicate]
readsPrec :: Int -> ReadS Predicate
$creadsPrec :: Int -> ReadS Predicate
Prelude.Read, Int -> Predicate -> ShowS
[Predicate] -> ShowS
Predicate -> String
(Int -> Predicate -> ShowS)
-> (Predicate -> String)
-> ([Predicate] -> ShowS)
-> Show Predicate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Predicate] -> ShowS
$cshowList :: [Predicate] -> ShowS
show :: Predicate -> String
$cshow :: Predicate -> String
showsPrec :: Int -> Predicate -> ShowS
$cshowsPrec :: Int -> Predicate -> ShowS
Prelude.Show, (forall x. Predicate -> Rep Predicate x)
-> (forall x. Rep Predicate x -> Predicate) -> Generic Predicate
forall x. Rep Predicate x -> Predicate
forall x. Predicate -> Rep Predicate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Predicate x -> Predicate
$cfrom :: forall x. Predicate -> Rep Predicate x
Prelude.Generic)

-- |
-- Create a value of 'Predicate' 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:
--
-- 'logical', 'predicate_logical' - An optional field if only one condition is listed. If multiple
-- conditions are listed, then this field is required.
--
-- 'conditions', 'predicate_conditions' - A list of the conditions that determine when the trigger will fire.
newPredicate ::
  Predicate
newPredicate :: Predicate
newPredicate =
  Predicate' :: Maybe Logical -> Maybe [Condition] -> Predicate
Predicate'
    { $sel:logical:Predicate' :: Maybe Logical
logical = Maybe Logical
forall a. Maybe a
Prelude.Nothing,
      $sel:conditions:Predicate' :: Maybe [Condition]
conditions = Maybe [Condition]
forall a. Maybe a
Prelude.Nothing
    }

-- | An optional field if only one condition is listed. If multiple
-- conditions are listed, then this field is required.
predicate_logical :: Lens.Lens' Predicate (Prelude.Maybe Logical)
predicate_logical :: (Maybe Logical -> f (Maybe Logical)) -> Predicate -> f Predicate
predicate_logical = (Predicate -> Maybe Logical)
-> (Predicate -> Maybe Logical -> Predicate)
-> Lens Predicate Predicate (Maybe Logical) (Maybe Logical)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Predicate' {Maybe Logical
logical :: Maybe Logical
$sel:logical:Predicate' :: Predicate -> Maybe Logical
logical} -> Maybe Logical
logical) (\s :: Predicate
s@Predicate' {} Maybe Logical
a -> Predicate
s {$sel:logical:Predicate' :: Maybe Logical
logical = Maybe Logical
a} :: Predicate)

-- | A list of the conditions that determine when the trigger will fire.
predicate_conditions :: Lens.Lens' Predicate (Prelude.Maybe [Condition])
predicate_conditions :: (Maybe [Condition] -> f (Maybe [Condition]))
-> Predicate -> f Predicate
predicate_conditions = (Predicate -> Maybe [Condition])
-> (Predicate -> Maybe [Condition] -> Predicate)
-> Lens Predicate Predicate (Maybe [Condition]) (Maybe [Condition])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Predicate' {Maybe [Condition]
conditions :: Maybe [Condition]
$sel:conditions:Predicate' :: Predicate -> Maybe [Condition]
conditions} -> Maybe [Condition]
conditions) (\s :: Predicate
s@Predicate' {} Maybe [Condition]
a -> Predicate
s {$sel:conditions:Predicate' :: Maybe [Condition]
conditions = Maybe [Condition]
a} :: Predicate) ((Maybe [Condition] -> f (Maybe [Condition]))
 -> Predicate -> f Predicate)
-> ((Maybe [Condition] -> f (Maybe [Condition]))
    -> Maybe [Condition] -> f (Maybe [Condition]))
-> (Maybe [Condition] -> f (Maybe [Condition]))
-> Predicate
-> f Predicate
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Condition] [Condition] [Condition] [Condition]
-> Iso
     (Maybe [Condition])
     (Maybe [Condition])
     (Maybe [Condition])
     (Maybe [Condition])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Condition] [Condition] [Condition] [Condition]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON Predicate where
  parseJSON :: Value -> Parser Predicate
parseJSON =
    String -> (Object -> Parser Predicate) -> Value -> Parser Predicate
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Predicate"
      ( \Object
x ->
          Maybe Logical -> Maybe [Condition] -> Predicate
Predicate'
            (Maybe Logical -> Maybe [Condition] -> Predicate)
-> Parser (Maybe Logical)
-> Parser (Maybe [Condition] -> Predicate)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Logical)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Logical")
            Parser (Maybe [Condition] -> Predicate)
-> Parser (Maybe [Condition]) -> Parser Predicate
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [Condition]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Conditions" Parser (Maybe (Maybe [Condition]))
-> Maybe [Condition] -> Parser (Maybe [Condition])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Condition]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable Predicate

instance Prelude.NFData Predicate

instance Core.ToJSON Predicate where
  toJSON :: Predicate -> Value
toJSON Predicate' {Maybe [Condition]
Maybe Logical
conditions :: Maybe [Condition]
logical :: Maybe Logical
$sel:conditions:Predicate' :: Predicate -> Maybe [Condition]
$sel:logical:Predicate' :: Predicate -> Maybe Logical
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Logical" Text -> Logical -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Logical -> Pair) -> Maybe Logical -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Logical
logical,
            (Text
"Conditions" Text -> [Condition] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Condition] -> Pair) -> Maybe [Condition] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Condition]
conditions
          ]
      )