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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Pinpoint.Types.EventFilter
import qualified Amazonka.Prelude as Prelude

-- | Specifies the settings for an event that causes a journey activity to
-- start.
--
-- /See:/ 'newEventStartCondition' smart constructor.
data EventStartCondition = EventStartCondition'
  { EventStartCondition -> Maybe EventFilter
eventFilter :: Prelude.Maybe EventFilter,
    EventStartCondition -> Maybe Text
segmentId :: Prelude.Maybe Prelude.Text
  }
  deriving (EventStartCondition -> EventStartCondition -> Bool
(EventStartCondition -> EventStartCondition -> Bool)
-> (EventStartCondition -> EventStartCondition -> Bool)
-> Eq EventStartCondition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EventStartCondition -> EventStartCondition -> Bool
$c/= :: EventStartCondition -> EventStartCondition -> Bool
== :: EventStartCondition -> EventStartCondition -> Bool
$c== :: EventStartCondition -> EventStartCondition -> Bool
Prelude.Eq, ReadPrec [EventStartCondition]
ReadPrec EventStartCondition
Int -> ReadS EventStartCondition
ReadS [EventStartCondition]
(Int -> ReadS EventStartCondition)
-> ReadS [EventStartCondition]
-> ReadPrec EventStartCondition
-> ReadPrec [EventStartCondition]
-> Read EventStartCondition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EventStartCondition]
$creadListPrec :: ReadPrec [EventStartCondition]
readPrec :: ReadPrec EventStartCondition
$creadPrec :: ReadPrec EventStartCondition
readList :: ReadS [EventStartCondition]
$creadList :: ReadS [EventStartCondition]
readsPrec :: Int -> ReadS EventStartCondition
$creadsPrec :: Int -> ReadS EventStartCondition
Prelude.Read, Int -> EventStartCondition -> ShowS
[EventStartCondition] -> ShowS
EventStartCondition -> String
(Int -> EventStartCondition -> ShowS)
-> (EventStartCondition -> String)
-> ([EventStartCondition] -> ShowS)
-> Show EventStartCondition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EventStartCondition] -> ShowS
$cshowList :: [EventStartCondition] -> ShowS
show :: EventStartCondition -> String
$cshow :: EventStartCondition -> String
showsPrec :: Int -> EventStartCondition -> ShowS
$cshowsPrec :: Int -> EventStartCondition -> ShowS
Prelude.Show, (forall x. EventStartCondition -> Rep EventStartCondition x)
-> (forall x. Rep EventStartCondition x -> EventStartCondition)
-> Generic EventStartCondition
forall x. Rep EventStartCondition x -> EventStartCondition
forall x. EventStartCondition -> Rep EventStartCondition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EventStartCondition x -> EventStartCondition
$cfrom :: forall x. EventStartCondition -> Rep EventStartCondition x
Prelude.Generic)

-- |
-- Create a value of 'EventStartCondition' 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:
--
-- 'eventFilter', 'eventStartCondition_eventFilter' - Undocumented member.
--
-- 'segmentId', 'eventStartCondition_segmentId' - Undocumented member.
newEventStartCondition ::
  EventStartCondition
newEventStartCondition :: EventStartCondition
newEventStartCondition =
  EventStartCondition' :: Maybe EventFilter -> Maybe Text -> EventStartCondition
EventStartCondition'
    { $sel:eventFilter:EventStartCondition' :: Maybe EventFilter
eventFilter = Maybe EventFilter
forall a. Maybe a
Prelude.Nothing,
      $sel:segmentId:EventStartCondition' :: Maybe Text
segmentId = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | Undocumented member.
eventStartCondition_eventFilter :: Lens.Lens' EventStartCondition (Prelude.Maybe EventFilter)
eventStartCondition_eventFilter :: (Maybe EventFilter -> f (Maybe EventFilter))
-> EventStartCondition -> f EventStartCondition
eventStartCondition_eventFilter = (EventStartCondition -> Maybe EventFilter)
-> (EventStartCondition
    -> Maybe EventFilter -> EventStartCondition)
-> Lens
     EventStartCondition
     EventStartCondition
     (Maybe EventFilter)
     (Maybe EventFilter)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventStartCondition' {Maybe EventFilter
eventFilter :: Maybe EventFilter
$sel:eventFilter:EventStartCondition' :: EventStartCondition -> Maybe EventFilter
eventFilter} -> Maybe EventFilter
eventFilter) (\s :: EventStartCondition
s@EventStartCondition' {} Maybe EventFilter
a -> EventStartCondition
s {$sel:eventFilter:EventStartCondition' :: Maybe EventFilter
eventFilter = Maybe EventFilter
a} :: EventStartCondition)

-- | Undocumented member.
eventStartCondition_segmentId :: Lens.Lens' EventStartCondition (Prelude.Maybe Prelude.Text)
eventStartCondition_segmentId :: (Maybe Text -> f (Maybe Text))
-> EventStartCondition -> f EventStartCondition
eventStartCondition_segmentId = (EventStartCondition -> Maybe Text)
-> (EventStartCondition -> Maybe Text -> EventStartCondition)
-> Lens
     EventStartCondition EventStartCondition (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EventStartCondition' {Maybe Text
segmentId :: Maybe Text
$sel:segmentId:EventStartCondition' :: EventStartCondition -> Maybe Text
segmentId} -> Maybe Text
segmentId) (\s :: EventStartCondition
s@EventStartCondition' {} Maybe Text
a -> EventStartCondition
s {$sel:segmentId:EventStartCondition' :: Maybe Text
segmentId = Maybe Text
a} :: EventStartCondition)

instance Core.FromJSON EventStartCondition where
  parseJSON :: Value -> Parser EventStartCondition
parseJSON =
    String
-> (Object -> Parser EventStartCondition)
-> Value
-> Parser EventStartCondition
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"EventStartCondition"
      ( \Object
x ->
          Maybe EventFilter -> Maybe Text -> EventStartCondition
EventStartCondition'
            (Maybe EventFilter -> Maybe Text -> EventStartCondition)
-> Parser (Maybe EventFilter)
-> Parser (Maybe Text -> EventStartCondition)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe EventFilter)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"EventFilter")
            Parser (Maybe Text -> EventStartCondition)
-> Parser (Maybe Text) -> Parser EventStartCondition
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
"SegmentId")
      )

instance Prelude.Hashable EventStartCondition

instance Prelude.NFData EventStartCondition

instance Core.ToJSON EventStartCondition where
  toJSON :: EventStartCondition -> Value
toJSON EventStartCondition' {Maybe Text
Maybe EventFilter
segmentId :: Maybe Text
eventFilter :: Maybe EventFilter
$sel:segmentId:EventStartCondition' :: EventStartCondition -> Maybe Text
$sel:eventFilter:EventStartCondition' :: EventStartCondition -> Maybe EventFilter
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"EventFilter" Text -> EventFilter -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (EventFilter -> Pair) -> Maybe EventFilter -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe EventFilter
eventFilter,
            (Text
"SegmentId" 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
segmentId
          ]
      )