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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SSMIncidents.Types.AttributeValueList

-- | A conditional statement with which to compare a value, after a
-- timestamp, before a timestamp, or equal to a string or integer. If
-- multiple conditions are specified, the conditionals become an @AND@ed
-- statement. If multiple values are specified for a conditional, the
-- values are @OR@d.
--
-- /See:/ 'newCondition' smart constructor.
data Condition = Condition'
  { -- | After the specified timestamp.
    Condition -> Maybe POSIX
after :: Prelude.Maybe Core.POSIX,
    -- | The value is equal to the provided string or integer.
    Condition -> Maybe AttributeValueList
equals :: Prelude.Maybe AttributeValueList,
    -- | Before the specified timestamp
    Condition -> Maybe POSIX
before :: Prelude.Maybe Core.POSIX
  }
  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:
--
-- 'after', 'condition_after' - After the specified timestamp.
--
-- 'equals', 'condition_equals' - The value is equal to the provided string or integer.
--
-- 'before', 'condition_before' - Before the specified timestamp
newCondition ::
  Condition
newCondition :: Condition
newCondition =
  Condition' :: Maybe POSIX -> Maybe AttributeValueList -> Maybe POSIX -> Condition
Condition'
    { $sel:after:Condition' :: Maybe POSIX
after = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:equals:Condition' :: Maybe AttributeValueList
equals = Maybe AttributeValueList
forall a. Maybe a
Prelude.Nothing,
      $sel:before:Condition' :: Maybe POSIX
before = Maybe POSIX
forall a. Maybe a
Prelude.Nothing
    }

-- | After the specified timestamp.
condition_after :: Lens.Lens' Condition (Prelude.Maybe Prelude.UTCTime)
condition_after :: (Maybe UTCTime -> f (Maybe UTCTime)) -> Condition -> f Condition
condition_after = (Condition -> Maybe POSIX)
-> (Condition -> Maybe POSIX -> Condition)
-> Lens Condition Condition (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Condition' {Maybe POSIX
after :: Maybe POSIX
$sel:after:Condition' :: Condition -> Maybe POSIX
after} -> Maybe POSIX
after) (\s :: Condition
s@Condition' {} Maybe POSIX
a -> Condition
s {$sel:after:Condition' :: Maybe POSIX
after = Maybe POSIX
a} :: Condition) ((Maybe POSIX -> f (Maybe POSIX)) -> Condition -> f Condition)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> Condition
-> f Condition
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The value is equal to the provided string or integer.
condition_equals :: Lens.Lens' Condition (Prelude.Maybe AttributeValueList)
condition_equals :: (Maybe AttributeValueList -> f (Maybe AttributeValueList))
-> Condition -> f Condition
condition_equals = (Condition -> Maybe AttributeValueList)
-> (Condition -> Maybe AttributeValueList -> Condition)
-> Lens
     Condition
     Condition
     (Maybe AttributeValueList)
     (Maybe AttributeValueList)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Condition' {Maybe AttributeValueList
equals :: Maybe AttributeValueList
$sel:equals:Condition' :: Condition -> Maybe AttributeValueList
equals} -> Maybe AttributeValueList
equals) (\s :: Condition
s@Condition' {} Maybe AttributeValueList
a -> Condition
s {$sel:equals:Condition' :: Maybe AttributeValueList
equals = Maybe AttributeValueList
a} :: Condition)

-- | Before the specified timestamp
condition_before :: Lens.Lens' Condition (Prelude.Maybe Prelude.UTCTime)
condition_before :: (Maybe UTCTime -> f (Maybe UTCTime)) -> Condition -> f Condition
condition_before = (Condition -> Maybe POSIX)
-> (Condition -> Maybe POSIX -> Condition)
-> Lens Condition Condition (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Condition' {Maybe POSIX
before :: Maybe POSIX
$sel:before:Condition' :: Condition -> Maybe POSIX
before} -> Maybe POSIX
before) (\s :: Condition
s@Condition' {} Maybe POSIX
a -> Condition
s {$sel:before:Condition' :: Maybe POSIX
before = Maybe POSIX
a} :: Condition) ((Maybe POSIX -> f (Maybe POSIX)) -> Condition -> f Condition)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> Condition
-> f Condition
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

instance Prelude.Hashable Condition

instance Prelude.NFData Condition

instance Core.ToJSON Condition where
  toJSON :: Condition -> Value
toJSON Condition' {Maybe POSIX
Maybe AttributeValueList
before :: Maybe POSIX
equals :: Maybe AttributeValueList
after :: Maybe POSIX
$sel:before:Condition' :: Condition -> Maybe POSIX
$sel:equals:Condition' :: Condition -> Maybe AttributeValueList
$sel:after:Condition' :: Condition -> Maybe POSIX
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"after" Text -> POSIX -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (POSIX -> Pair) -> Maybe POSIX -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe POSIX
after,
            (Text
"equals" Text -> AttributeValueList -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (AttributeValueList -> Pair)
-> Maybe AttributeValueList -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe AttributeValueList
equals,
            (Text
"before" Text -> POSIX -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (POSIX -> Pair) -> Maybe POSIX -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe POSIX
before
          ]
      )