{-# 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.Pinpoint.Types.SimpleCondition
-- 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.Pinpoint.Types.SimpleCondition where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Pinpoint.Types.EventCondition
import Amazonka.Pinpoint.Types.SegmentCondition
import Amazonka.Pinpoint.Types.SegmentDimensions
import qualified Amazonka.Prelude as Prelude

-- | Specifies a condition to evaluate for an activity in a journey.
--
-- /See:/ 'newSimpleCondition' smart constructor.
data SimpleCondition = SimpleCondition'
  { -- | The dimension settings for the segment that\'s associated with the
    -- activity.
    SimpleCondition -> Maybe SegmentDimensions
segmentDimensions :: Prelude.Maybe SegmentDimensions,
    -- | The dimension settings for the event that\'s associated with the
    -- activity.
    SimpleCondition -> Maybe EventCondition
eventCondition :: Prelude.Maybe EventCondition,
    -- | The segment that\'s associated with the activity.
    SimpleCondition -> Maybe SegmentCondition
segmentCondition :: Prelude.Maybe SegmentCondition
  }
  deriving (SimpleCondition -> SimpleCondition -> Bool
(SimpleCondition -> SimpleCondition -> Bool)
-> (SimpleCondition -> SimpleCondition -> Bool)
-> Eq SimpleCondition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SimpleCondition -> SimpleCondition -> Bool
$c/= :: SimpleCondition -> SimpleCondition -> Bool
== :: SimpleCondition -> SimpleCondition -> Bool
$c== :: SimpleCondition -> SimpleCondition -> Bool
Prelude.Eq, ReadPrec [SimpleCondition]
ReadPrec SimpleCondition
Int -> ReadS SimpleCondition
ReadS [SimpleCondition]
(Int -> ReadS SimpleCondition)
-> ReadS [SimpleCondition]
-> ReadPrec SimpleCondition
-> ReadPrec [SimpleCondition]
-> Read SimpleCondition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SimpleCondition]
$creadListPrec :: ReadPrec [SimpleCondition]
readPrec :: ReadPrec SimpleCondition
$creadPrec :: ReadPrec SimpleCondition
readList :: ReadS [SimpleCondition]
$creadList :: ReadS [SimpleCondition]
readsPrec :: Int -> ReadS SimpleCondition
$creadsPrec :: Int -> ReadS SimpleCondition
Prelude.Read, Int -> SimpleCondition -> ShowS
[SimpleCondition] -> ShowS
SimpleCondition -> String
(Int -> SimpleCondition -> ShowS)
-> (SimpleCondition -> String)
-> ([SimpleCondition] -> ShowS)
-> Show SimpleCondition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SimpleCondition] -> ShowS
$cshowList :: [SimpleCondition] -> ShowS
show :: SimpleCondition -> String
$cshow :: SimpleCondition -> String
showsPrec :: Int -> SimpleCondition -> ShowS
$cshowsPrec :: Int -> SimpleCondition -> ShowS
Prelude.Show, (forall x. SimpleCondition -> Rep SimpleCondition x)
-> (forall x. Rep SimpleCondition x -> SimpleCondition)
-> Generic SimpleCondition
forall x. Rep SimpleCondition x -> SimpleCondition
forall x. SimpleCondition -> Rep SimpleCondition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SimpleCondition x -> SimpleCondition
$cfrom :: forall x. SimpleCondition -> Rep SimpleCondition x
Prelude.Generic)

-- |
-- Create a value of 'SimpleCondition' 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:
--
-- 'segmentDimensions', 'simpleCondition_segmentDimensions' - The dimension settings for the segment that\'s associated with the
-- activity.
--
-- 'eventCondition', 'simpleCondition_eventCondition' - The dimension settings for the event that\'s associated with the
-- activity.
--
-- 'segmentCondition', 'simpleCondition_segmentCondition' - The segment that\'s associated with the activity.
newSimpleCondition ::
  SimpleCondition
newSimpleCondition :: SimpleCondition
newSimpleCondition =
  SimpleCondition' :: Maybe SegmentDimensions
-> Maybe EventCondition
-> Maybe SegmentCondition
-> SimpleCondition
SimpleCondition'
    { $sel:segmentDimensions:SimpleCondition' :: Maybe SegmentDimensions
segmentDimensions =
        Maybe SegmentDimensions
forall a. Maybe a
Prelude.Nothing,
      $sel:eventCondition:SimpleCondition' :: Maybe EventCondition
eventCondition = Maybe EventCondition
forall a. Maybe a
Prelude.Nothing,
      $sel:segmentCondition:SimpleCondition' :: Maybe SegmentCondition
segmentCondition = Maybe SegmentCondition
forall a. Maybe a
Prelude.Nothing
    }

-- | The dimension settings for the segment that\'s associated with the
-- activity.
simpleCondition_segmentDimensions :: Lens.Lens' SimpleCondition (Prelude.Maybe SegmentDimensions)
simpleCondition_segmentDimensions :: (Maybe SegmentDimensions -> f (Maybe SegmentDimensions))
-> SimpleCondition -> f SimpleCondition
simpleCondition_segmentDimensions = (SimpleCondition -> Maybe SegmentDimensions)
-> (SimpleCondition -> Maybe SegmentDimensions -> SimpleCondition)
-> Lens
     SimpleCondition
     SimpleCondition
     (Maybe SegmentDimensions)
     (Maybe SegmentDimensions)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SimpleCondition' {Maybe SegmentDimensions
segmentDimensions :: Maybe SegmentDimensions
$sel:segmentDimensions:SimpleCondition' :: SimpleCondition -> Maybe SegmentDimensions
segmentDimensions} -> Maybe SegmentDimensions
segmentDimensions) (\s :: SimpleCondition
s@SimpleCondition' {} Maybe SegmentDimensions
a -> SimpleCondition
s {$sel:segmentDimensions:SimpleCondition' :: Maybe SegmentDimensions
segmentDimensions = Maybe SegmentDimensions
a} :: SimpleCondition)

-- | The dimension settings for the event that\'s associated with the
-- activity.
simpleCondition_eventCondition :: Lens.Lens' SimpleCondition (Prelude.Maybe EventCondition)
simpleCondition_eventCondition :: (Maybe EventCondition -> f (Maybe EventCondition))
-> SimpleCondition -> f SimpleCondition
simpleCondition_eventCondition = (SimpleCondition -> Maybe EventCondition)
-> (SimpleCondition -> Maybe EventCondition -> SimpleCondition)
-> Lens
     SimpleCondition
     SimpleCondition
     (Maybe EventCondition)
     (Maybe EventCondition)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SimpleCondition' {Maybe EventCondition
eventCondition :: Maybe EventCondition
$sel:eventCondition:SimpleCondition' :: SimpleCondition -> Maybe EventCondition
eventCondition} -> Maybe EventCondition
eventCondition) (\s :: SimpleCondition
s@SimpleCondition' {} Maybe EventCondition
a -> SimpleCondition
s {$sel:eventCondition:SimpleCondition' :: Maybe EventCondition
eventCondition = Maybe EventCondition
a} :: SimpleCondition)

-- | The segment that\'s associated with the activity.
simpleCondition_segmentCondition :: Lens.Lens' SimpleCondition (Prelude.Maybe SegmentCondition)
simpleCondition_segmentCondition :: (Maybe SegmentCondition -> f (Maybe SegmentCondition))
-> SimpleCondition -> f SimpleCondition
simpleCondition_segmentCondition = (SimpleCondition -> Maybe SegmentCondition)
-> (SimpleCondition -> Maybe SegmentCondition -> SimpleCondition)
-> Lens
     SimpleCondition
     SimpleCondition
     (Maybe SegmentCondition)
     (Maybe SegmentCondition)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SimpleCondition' {Maybe SegmentCondition
segmentCondition :: Maybe SegmentCondition
$sel:segmentCondition:SimpleCondition' :: SimpleCondition -> Maybe SegmentCondition
segmentCondition} -> Maybe SegmentCondition
segmentCondition) (\s :: SimpleCondition
s@SimpleCondition' {} Maybe SegmentCondition
a -> SimpleCondition
s {$sel:segmentCondition:SimpleCondition' :: Maybe SegmentCondition
segmentCondition = Maybe SegmentCondition
a} :: SimpleCondition)

instance Core.FromJSON SimpleCondition where
  parseJSON :: Value -> Parser SimpleCondition
parseJSON =
    String
-> (Object -> Parser SimpleCondition)
-> Value
-> Parser SimpleCondition
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SimpleCondition"
      ( \Object
x ->
          Maybe SegmentDimensions
-> Maybe EventCondition
-> Maybe SegmentCondition
-> SimpleCondition
SimpleCondition'
            (Maybe SegmentDimensions
 -> Maybe EventCondition
 -> Maybe SegmentCondition
 -> SimpleCondition)
-> Parser (Maybe SegmentDimensions)
-> Parser
     (Maybe EventCondition -> Maybe SegmentCondition -> SimpleCondition)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe SegmentDimensions)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"segmentDimensions")
            Parser
  (Maybe EventCondition -> Maybe SegmentCondition -> SimpleCondition)
-> Parser (Maybe EventCondition)
-> Parser (Maybe SegmentCondition -> SimpleCondition)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe EventCondition)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"EventCondition")
            Parser (Maybe SegmentCondition -> SimpleCondition)
-> Parser (Maybe SegmentCondition) -> Parser SimpleCondition
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe SegmentCondition)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"SegmentCondition")
      )

instance Prelude.Hashable SimpleCondition

instance Prelude.NFData SimpleCondition

instance Core.ToJSON SimpleCondition where
  toJSON :: SimpleCondition -> Value
toJSON SimpleCondition' {Maybe SegmentCondition
Maybe SegmentDimensions
Maybe EventCondition
segmentCondition :: Maybe SegmentCondition
eventCondition :: Maybe EventCondition
segmentDimensions :: Maybe SegmentDimensions
$sel:segmentCondition:SimpleCondition' :: SimpleCondition -> Maybe SegmentCondition
$sel:eventCondition:SimpleCondition' :: SimpleCondition -> Maybe EventCondition
$sel:segmentDimensions:SimpleCondition' :: SimpleCondition -> Maybe SegmentDimensions
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"segmentDimensions" Text -> SegmentDimensions -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (SegmentDimensions -> Pair)
-> Maybe SegmentDimensions -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SegmentDimensions
segmentDimensions,
            (Text
"EventCondition" Text -> EventCondition -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (EventCondition -> Pair) -> Maybe EventCondition -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe EventCondition
eventCondition,
            (Text
"SegmentCondition" Text -> SegmentCondition -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (SegmentCondition -> Pair) -> Maybe SegmentCondition -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SegmentCondition
segmentCondition
          ]
      )