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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Pinpoint.Types.EventStartCondition
import Amazonka.Pinpoint.Types.SegmentCondition
import qualified Amazonka.Prelude as Prelude

-- | Specifies the conditions for the first activity in a journey. This
-- activity and its conditions determine which users are participants in a
-- journey.
--
-- /See:/ 'newStartCondition' smart constructor.
data StartCondition = StartCondition'
  { -- | The segment that\'s associated with the first activity in the journey.
    -- This segment determines which users are participants in the journey.
    StartCondition -> Maybe SegmentCondition
segmentStartCondition :: Prelude.Maybe SegmentCondition,
    StartCondition -> Maybe EventStartCondition
eventStartCondition :: Prelude.Maybe EventStartCondition,
    -- | The custom description of the condition.
    StartCondition -> Maybe Text
description :: Prelude.Maybe Prelude.Text
  }
  deriving (StartCondition -> StartCondition -> Bool
(StartCondition -> StartCondition -> Bool)
-> (StartCondition -> StartCondition -> Bool) -> Eq StartCondition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartCondition -> StartCondition -> Bool
$c/= :: StartCondition -> StartCondition -> Bool
== :: StartCondition -> StartCondition -> Bool
$c== :: StartCondition -> StartCondition -> Bool
Prelude.Eq, ReadPrec [StartCondition]
ReadPrec StartCondition
Int -> ReadS StartCondition
ReadS [StartCondition]
(Int -> ReadS StartCondition)
-> ReadS [StartCondition]
-> ReadPrec StartCondition
-> ReadPrec [StartCondition]
-> Read StartCondition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartCondition]
$creadListPrec :: ReadPrec [StartCondition]
readPrec :: ReadPrec StartCondition
$creadPrec :: ReadPrec StartCondition
readList :: ReadS [StartCondition]
$creadList :: ReadS [StartCondition]
readsPrec :: Int -> ReadS StartCondition
$creadsPrec :: Int -> ReadS StartCondition
Prelude.Read, Int -> StartCondition -> ShowS
[StartCondition] -> ShowS
StartCondition -> String
(Int -> StartCondition -> ShowS)
-> (StartCondition -> String)
-> ([StartCondition] -> ShowS)
-> Show StartCondition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartCondition] -> ShowS
$cshowList :: [StartCondition] -> ShowS
show :: StartCondition -> String
$cshow :: StartCondition -> String
showsPrec :: Int -> StartCondition -> ShowS
$cshowsPrec :: Int -> StartCondition -> ShowS
Prelude.Show, (forall x. StartCondition -> Rep StartCondition x)
-> (forall x. Rep StartCondition x -> StartCondition)
-> Generic StartCondition
forall x. Rep StartCondition x -> StartCondition
forall x. StartCondition -> Rep StartCondition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartCondition x -> StartCondition
$cfrom :: forall x. StartCondition -> Rep StartCondition x
Prelude.Generic)

-- |
-- Create a value of 'StartCondition' 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:
--
-- 'segmentStartCondition', 'startCondition_segmentStartCondition' - The segment that\'s associated with the first activity in the journey.
-- This segment determines which users are participants in the journey.
--
-- 'eventStartCondition', 'startCondition_eventStartCondition' - Undocumented member.
--
-- 'description', 'startCondition_description' - The custom description of the condition.
newStartCondition ::
  StartCondition
newStartCondition :: StartCondition
newStartCondition =
  StartCondition' :: Maybe SegmentCondition
-> Maybe EventStartCondition -> Maybe Text -> StartCondition
StartCondition'
    { $sel:segmentStartCondition:StartCondition' :: Maybe SegmentCondition
segmentStartCondition =
        Maybe SegmentCondition
forall a. Maybe a
Prelude.Nothing,
      $sel:eventStartCondition:StartCondition' :: Maybe EventStartCondition
eventStartCondition = Maybe EventStartCondition
forall a. Maybe a
Prelude.Nothing,
      $sel:description:StartCondition' :: Maybe Text
description = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The segment that\'s associated with the first activity in the journey.
-- This segment determines which users are participants in the journey.
startCondition_segmentStartCondition :: Lens.Lens' StartCondition (Prelude.Maybe SegmentCondition)
startCondition_segmentStartCondition :: (Maybe SegmentCondition -> f (Maybe SegmentCondition))
-> StartCondition -> f StartCondition
startCondition_segmentStartCondition = (StartCondition -> Maybe SegmentCondition)
-> (StartCondition -> Maybe SegmentCondition -> StartCondition)
-> Lens
     StartCondition
     StartCondition
     (Maybe SegmentCondition)
     (Maybe SegmentCondition)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartCondition' {Maybe SegmentCondition
segmentStartCondition :: Maybe SegmentCondition
$sel:segmentStartCondition:StartCondition' :: StartCondition -> Maybe SegmentCondition
segmentStartCondition} -> Maybe SegmentCondition
segmentStartCondition) (\s :: StartCondition
s@StartCondition' {} Maybe SegmentCondition
a -> StartCondition
s {$sel:segmentStartCondition:StartCondition' :: Maybe SegmentCondition
segmentStartCondition = Maybe SegmentCondition
a} :: StartCondition)

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

-- | The custom description of the condition.
startCondition_description :: Lens.Lens' StartCondition (Prelude.Maybe Prelude.Text)
startCondition_description :: (Maybe Text -> f (Maybe Text))
-> StartCondition -> f StartCondition
startCondition_description = (StartCondition -> Maybe Text)
-> (StartCondition -> Maybe Text -> StartCondition)
-> Lens StartCondition StartCondition (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartCondition' {Maybe Text
description :: Maybe Text
$sel:description:StartCondition' :: StartCondition -> Maybe Text
description} -> Maybe Text
description) (\s :: StartCondition
s@StartCondition' {} Maybe Text
a -> StartCondition
s {$sel:description:StartCondition' :: Maybe Text
description = Maybe Text
a} :: StartCondition)

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

instance Prelude.Hashable StartCondition

instance Prelude.NFData StartCondition

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