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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Specifies a segment to associate with an activity in a journey.
--
-- /See:/ 'newSegmentCondition' smart constructor.
data SegmentCondition = SegmentCondition'
  { -- | The unique identifier for the segment to associate with the activity.
    SegmentCondition -> Text
segmentId :: Prelude.Text
  }
  deriving (SegmentCondition -> SegmentCondition -> Bool
(SegmentCondition -> SegmentCondition -> Bool)
-> (SegmentCondition -> SegmentCondition -> Bool)
-> Eq SegmentCondition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SegmentCondition -> SegmentCondition -> Bool
$c/= :: SegmentCondition -> SegmentCondition -> Bool
== :: SegmentCondition -> SegmentCondition -> Bool
$c== :: SegmentCondition -> SegmentCondition -> Bool
Prelude.Eq, ReadPrec [SegmentCondition]
ReadPrec SegmentCondition
Int -> ReadS SegmentCondition
ReadS [SegmentCondition]
(Int -> ReadS SegmentCondition)
-> ReadS [SegmentCondition]
-> ReadPrec SegmentCondition
-> ReadPrec [SegmentCondition]
-> Read SegmentCondition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SegmentCondition]
$creadListPrec :: ReadPrec [SegmentCondition]
readPrec :: ReadPrec SegmentCondition
$creadPrec :: ReadPrec SegmentCondition
readList :: ReadS [SegmentCondition]
$creadList :: ReadS [SegmentCondition]
readsPrec :: Int -> ReadS SegmentCondition
$creadsPrec :: Int -> ReadS SegmentCondition
Prelude.Read, Int -> SegmentCondition -> ShowS
[SegmentCondition] -> ShowS
SegmentCondition -> String
(Int -> SegmentCondition -> ShowS)
-> (SegmentCondition -> String)
-> ([SegmentCondition] -> ShowS)
-> Show SegmentCondition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SegmentCondition] -> ShowS
$cshowList :: [SegmentCondition] -> ShowS
show :: SegmentCondition -> String
$cshow :: SegmentCondition -> String
showsPrec :: Int -> SegmentCondition -> ShowS
$cshowsPrec :: Int -> SegmentCondition -> ShowS
Prelude.Show, (forall x. SegmentCondition -> Rep SegmentCondition x)
-> (forall x. Rep SegmentCondition x -> SegmentCondition)
-> Generic SegmentCondition
forall x. Rep SegmentCondition x -> SegmentCondition
forall x. SegmentCondition -> Rep SegmentCondition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SegmentCondition x -> SegmentCondition
$cfrom :: forall x. SegmentCondition -> Rep SegmentCondition x
Prelude.Generic)

-- |
-- Create a value of 'SegmentCondition' 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:
--
-- 'segmentId', 'segmentCondition_segmentId' - The unique identifier for the segment to associate with the activity.
newSegmentCondition ::
  -- | 'segmentId'
  Prelude.Text ->
  SegmentCondition
newSegmentCondition :: Text -> SegmentCondition
newSegmentCondition Text
pSegmentId_ =
  SegmentCondition' :: Text -> SegmentCondition
SegmentCondition' {$sel:segmentId:SegmentCondition' :: Text
segmentId = Text
pSegmentId_}

-- | The unique identifier for the segment to associate with the activity.
segmentCondition_segmentId :: Lens.Lens' SegmentCondition Prelude.Text
segmentCondition_segmentId :: (Text -> f Text) -> SegmentCondition -> f SegmentCondition
segmentCondition_segmentId = (SegmentCondition -> Text)
-> (SegmentCondition -> Text -> SegmentCondition)
-> Lens SegmentCondition SegmentCondition Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SegmentCondition' {Text
segmentId :: Text
$sel:segmentId:SegmentCondition' :: SegmentCondition -> Text
segmentId} -> Text
segmentId) (\s :: SegmentCondition
s@SegmentCondition' {} Text
a -> SegmentCondition
s {$sel:segmentId:SegmentCondition' :: Text
segmentId = Text
a} :: SegmentCondition)

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

instance Prelude.Hashable SegmentCondition

instance Prelude.NFData SegmentCondition

instance Core.ToJSON SegmentCondition where
  toJSON :: SegmentCondition -> Value
toJSON SegmentCondition' {Text
segmentId :: Text
$sel:segmentId:SegmentCondition' :: SegmentCondition -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"SegmentId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
segmentId)]
      )