{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Pinpoint.Types.StartCondition where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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 custom description of the condition.
    StartCondition -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    StartCondition -> Maybe EventStartCondition
eventStartCondition :: Prelude.Maybe EventStartCondition,
    -- | 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
  }
  deriving (StartCondition -> StartCondition -> Bool
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]
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
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. 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:
--
-- 'description', 'startCondition_description' - The custom description of the condition.
--
-- 'eventStartCondition', 'startCondition_eventStartCondition' - Undocumented member.
--
-- '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.
newStartCondition ::
  StartCondition
newStartCondition :: StartCondition
newStartCondition =
  StartCondition'
    { $sel:description:StartCondition' :: Maybe Text
description = forall a. Maybe a
Prelude.Nothing,
      $sel:eventStartCondition:StartCondition' :: Maybe EventStartCondition
eventStartCondition = forall a. Maybe a
Prelude.Nothing,
      $sel:segmentStartCondition:StartCondition' :: Maybe SegmentCondition
segmentStartCondition = forall a. Maybe a
Prelude.Nothing
    }

-- | The custom description of the condition.
startCondition_description :: Lens.Lens' StartCondition (Prelude.Maybe Prelude.Text)
startCondition_description :: Lens' StartCondition (Maybe Text)
startCondition_description = 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)

-- | Undocumented member.
startCondition_eventStartCondition :: Lens.Lens' StartCondition (Prelude.Maybe EventStartCondition)
startCondition_eventStartCondition :: Lens' StartCondition (Maybe EventStartCondition)
startCondition_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 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 :: Lens' StartCondition (Maybe SegmentCondition)
startCondition_segmentStartCondition = 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)

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

instance Prelude.Hashable StartCondition where
  hashWithSalt :: Int -> StartCondition -> Int
hashWithSalt Int
_salt StartCondition' {Maybe Text
Maybe SegmentCondition
Maybe EventStartCondition
segmentStartCondition :: Maybe SegmentCondition
eventStartCondition :: Maybe EventStartCondition
description :: Maybe Text
$sel:segmentStartCondition:StartCondition' :: StartCondition -> Maybe SegmentCondition
$sel:eventStartCondition:StartCondition' :: StartCondition -> Maybe EventStartCondition
$sel:description:StartCondition' :: StartCondition -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
description
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe EventStartCondition
eventStartCondition
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe SegmentCondition
segmentStartCondition

instance Prelude.NFData StartCondition where
  rnf :: StartCondition -> ()
rnf StartCondition' {Maybe Text
Maybe SegmentCondition
Maybe EventStartCondition
segmentStartCondition :: Maybe SegmentCondition
eventStartCondition :: Maybe EventStartCondition
description :: Maybe Text
$sel:segmentStartCondition:StartCondition' :: StartCondition -> Maybe SegmentCondition
$sel:eventStartCondition:StartCondition' :: StartCondition -> Maybe EventStartCondition
$sel:description:StartCondition' :: StartCondition -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
description
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe EventStartCondition
eventStartCondition
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe SegmentCondition
segmentStartCondition

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