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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Pinpoint.Types.SegmentDimensions
import Amazonka.Pinpoint.Types.SegmentReference
import Amazonka.Pinpoint.Types.SourceType
import Amazonka.Pinpoint.Types.Type
import qualified Amazonka.Prelude as Prelude

-- | Specifies the base segments and dimensions for a segment, and the
-- relationships between these base segments and dimensions.
--
-- /See:/ 'newSegmentGroup' smart constructor.
data SegmentGroup = SegmentGroup'
  { -- | The base segment to build the segment on. A base segment, also referred
    -- to as a /source segment/, defines the initial population of endpoints
    -- for a segment. When you add dimensions to a segment, Amazon Pinpoint
    -- filters the base segment by using the dimensions that you specify.
    --
    -- You can specify more than one dimensional segment or only one imported
    -- segment. If you specify an imported segment, the Amazon Pinpoint console
    -- displays a segment size estimate that indicates the size of the imported
    -- segment without any filters applied to it.
    SegmentGroup -> Maybe [SegmentReference]
sourceSegments :: Prelude.Maybe [SegmentReference],
    -- | Specifies how to handle multiple base segments for the segment. For
    -- example, if you specify three base segments for the segment, whether the
    -- resulting segment is based on all, any, or none of the base segments.
    SegmentGroup -> Maybe SourceType
sourceType :: Prelude.Maybe SourceType,
    -- | Specifies how to handle multiple dimensions for the segment. For
    -- example, if you specify three dimensions for the segment, whether the
    -- resulting segment includes endpoints that match all, any, or none of the
    -- dimensions.
    SegmentGroup -> Maybe Type
type' :: Prelude.Maybe Type,
    -- | An array that defines the dimensions for the segment.
    SegmentGroup -> Maybe [SegmentDimensions]
dimensions :: Prelude.Maybe [SegmentDimensions]
  }
  deriving (SegmentGroup -> SegmentGroup -> Bool
(SegmentGroup -> SegmentGroup -> Bool)
-> (SegmentGroup -> SegmentGroup -> Bool) -> Eq SegmentGroup
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SegmentGroup -> SegmentGroup -> Bool
$c/= :: SegmentGroup -> SegmentGroup -> Bool
== :: SegmentGroup -> SegmentGroup -> Bool
$c== :: SegmentGroup -> SegmentGroup -> Bool
Prelude.Eq, ReadPrec [SegmentGroup]
ReadPrec SegmentGroup
Int -> ReadS SegmentGroup
ReadS [SegmentGroup]
(Int -> ReadS SegmentGroup)
-> ReadS [SegmentGroup]
-> ReadPrec SegmentGroup
-> ReadPrec [SegmentGroup]
-> Read SegmentGroup
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SegmentGroup]
$creadListPrec :: ReadPrec [SegmentGroup]
readPrec :: ReadPrec SegmentGroup
$creadPrec :: ReadPrec SegmentGroup
readList :: ReadS [SegmentGroup]
$creadList :: ReadS [SegmentGroup]
readsPrec :: Int -> ReadS SegmentGroup
$creadsPrec :: Int -> ReadS SegmentGroup
Prelude.Read, Int -> SegmentGroup -> ShowS
[SegmentGroup] -> ShowS
SegmentGroup -> String
(Int -> SegmentGroup -> ShowS)
-> (SegmentGroup -> String)
-> ([SegmentGroup] -> ShowS)
-> Show SegmentGroup
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SegmentGroup] -> ShowS
$cshowList :: [SegmentGroup] -> ShowS
show :: SegmentGroup -> String
$cshow :: SegmentGroup -> String
showsPrec :: Int -> SegmentGroup -> ShowS
$cshowsPrec :: Int -> SegmentGroup -> ShowS
Prelude.Show, (forall x. SegmentGroup -> Rep SegmentGroup x)
-> (forall x. Rep SegmentGroup x -> SegmentGroup)
-> Generic SegmentGroup
forall x. Rep SegmentGroup x -> SegmentGroup
forall x. SegmentGroup -> Rep SegmentGroup x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SegmentGroup x -> SegmentGroup
$cfrom :: forall x. SegmentGroup -> Rep SegmentGroup x
Prelude.Generic)

-- |
-- Create a value of 'SegmentGroup' 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:
--
-- 'sourceSegments', 'segmentGroup_sourceSegments' - The base segment to build the segment on. A base segment, also referred
-- to as a /source segment/, defines the initial population of endpoints
-- for a segment. When you add dimensions to a segment, Amazon Pinpoint
-- filters the base segment by using the dimensions that you specify.
--
-- You can specify more than one dimensional segment or only one imported
-- segment. If you specify an imported segment, the Amazon Pinpoint console
-- displays a segment size estimate that indicates the size of the imported
-- segment without any filters applied to it.
--
-- 'sourceType', 'segmentGroup_sourceType' - Specifies how to handle multiple base segments for the segment. For
-- example, if you specify three base segments for the segment, whether the
-- resulting segment is based on all, any, or none of the base segments.
--
-- 'type'', 'segmentGroup_type' - Specifies how to handle multiple dimensions for the segment. For
-- example, if you specify three dimensions for the segment, whether the
-- resulting segment includes endpoints that match all, any, or none of the
-- dimensions.
--
-- 'dimensions', 'segmentGroup_dimensions' - An array that defines the dimensions for the segment.
newSegmentGroup ::
  SegmentGroup
newSegmentGroup :: SegmentGroup
newSegmentGroup =
  SegmentGroup' :: Maybe [SegmentReference]
-> Maybe SourceType
-> Maybe Type
-> Maybe [SegmentDimensions]
-> SegmentGroup
SegmentGroup'
    { $sel:sourceSegments:SegmentGroup' :: Maybe [SegmentReference]
sourceSegments = Maybe [SegmentReference]
forall a. Maybe a
Prelude.Nothing,
      $sel:sourceType:SegmentGroup' :: Maybe SourceType
sourceType = Maybe SourceType
forall a. Maybe a
Prelude.Nothing,
      $sel:type':SegmentGroup' :: Maybe Type
type' = Maybe Type
forall a. Maybe a
Prelude.Nothing,
      $sel:dimensions:SegmentGroup' :: Maybe [SegmentDimensions]
dimensions = Maybe [SegmentDimensions]
forall a. Maybe a
Prelude.Nothing
    }

-- | The base segment to build the segment on. A base segment, also referred
-- to as a /source segment/, defines the initial population of endpoints
-- for a segment. When you add dimensions to a segment, Amazon Pinpoint
-- filters the base segment by using the dimensions that you specify.
--
-- You can specify more than one dimensional segment or only one imported
-- segment. If you specify an imported segment, the Amazon Pinpoint console
-- displays a segment size estimate that indicates the size of the imported
-- segment without any filters applied to it.
segmentGroup_sourceSegments :: Lens.Lens' SegmentGroup (Prelude.Maybe [SegmentReference])
segmentGroup_sourceSegments :: (Maybe [SegmentReference] -> f (Maybe [SegmentReference]))
-> SegmentGroup -> f SegmentGroup
segmentGroup_sourceSegments = (SegmentGroup -> Maybe [SegmentReference])
-> (SegmentGroup -> Maybe [SegmentReference] -> SegmentGroup)
-> Lens
     SegmentGroup
     SegmentGroup
     (Maybe [SegmentReference])
     (Maybe [SegmentReference])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SegmentGroup' {Maybe [SegmentReference]
sourceSegments :: Maybe [SegmentReference]
$sel:sourceSegments:SegmentGroup' :: SegmentGroup -> Maybe [SegmentReference]
sourceSegments} -> Maybe [SegmentReference]
sourceSegments) (\s :: SegmentGroup
s@SegmentGroup' {} Maybe [SegmentReference]
a -> SegmentGroup
s {$sel:sourceSegments:SegmentGroup' :: Maybe [SegmentReference]
sourceSegments = Maybe [SegmentReference]
a} :: SegmentGroup) ((Maybe [SegmentReference] -> f (Maybe [SegmentReference]))
 -> SegmentGroup -> f SegmentGroup)
-> ((Maybe [SegmentReference] -> f (Maybe [SegmentReference]))
    -> Maybe [SegmentReference] -> f (Maybe [SegmentReference]))
-> (Maybe [SegmentReference] -> f (Maybe [SegmentReference]))
-> SegmentGroup
-> f SegmentGroup
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [SegmentReference]
  [SegmentReference]
  [SegmentReference]
  [SegmentReference]
-> Iso
     (Maybe [SegmentReference])
     (Maybe [SegmentReference])
     (Maybe [SegmentReference])
     (Maybe [SegmentReference])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [SegmentReference]
  [SegmentReference]
  [SegmentReference]
  [SegmentReference]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Specifies how to handle multiple base segments for the segment. For
-- example, if you specify three base segments for the segment, whether the
-- resulting segment is based on all, any, or none of the base segments.
segmentGroup_sourceType :: Lens.Lens' SegmentGroup (Prelude.Maybe SourceType)
segmentGroup_sourceType :: (Maybe SourceType -> f (Maybe SourceType))
-> SegmentGroup -> f SegmentGroup
segmentGroup_sourceType = (SegmentGroup -> Maybe SourceType)
-> (SegmentGroup -> Maybe SourceType -> SegmentGroup)
-> Lens
     SegmentGroup SegmentGroup (Maybe SourceType) (Maybe SourceType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SegmentGroup' {Maybe SourceType
sourceType :: Maybe SourceType
$sel:sourceType:SegmentGroup' :: SegmentGroup -> Maybe SourceType
sourceType} -> Maybe SourceType
sourceType) (\s :: SegmentGroup
s@SegmentGroup' {} Maybe SourceType
a -> SegmentGroup
s {$sel:sourceType:SegmentGroup' :: Maybe SourceType
sourceType = Maybe SourceType
a} :: SegmentGroup)

-- | Specifies how to handle multiple dimensions for the segment. For
-- example, if you specify three dimensions for the segment, whether the
-- resulting segment includes endpoints that match all, any, or none of the
-- dimensions.
segmentGroup_type :: Lens.Lens' SegmentGroup (Prelude.Maybe Type)
segmentGroup_type :: (Maybe Type -> f (Maybe Type)) -> SegmentGroup -> f SegmentGroup
segmentGroup_type = (SegmentGroup -> Maybe Type)
-> (SegmentGroup -> Maybe Type -> SegmentGroup)
-> Lens SegmentGroup SegmentGroup (Maybe Type) (Maybe Type)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SegmentGroup' {Maybe Type
type' :: Maybe Type
$sel:type':SegmentGroup' :: SegmentGroup -> Maybe Type
type'} -> Maybe Type
type') (\s :: SegmentGroup
s@SegmentGroup' {} Maybe Type
a -> SegmentGroup
s {$sel:type':SegmentGroup' :: Maybe Type
type' = Maybe Type
a} :: SegmentGroup)

-- | An array that defines the dimensions for the segment.
segmentGroup_dimensions :: Lens.Lens' SegmentGroup (Prelude.Maybe [SegmentDimensions])
segmentGroup_dimensions :: (Maybe [SegmentDimensions] -> f (Maybe [SegmentDimensions]))
-> SegmentGroup -> f SegmentGroup
segmentGroup_dimensions = (SegmentGroup -> Maybe [SegmentDimensions])
-> (SegmentGroup -> Maybe [SegmentDimensions] -> SegmentGroup)
-> Lens
     SegmentGroup
     SegmentGroup
     (Maybe [SegmentDimensions])
     (Maybe [SegmentDimensions])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SegmentGroup' {Maybe [SegmentDimensions]
dimensions :: Maybe [SegmentDimensions]
$sel:dimensions:SegmentGroup' :: SegmentGroup -> Maybe [SegmentDimensions]
dimensions} -> Maybe [SegmentDimensions]
dimensions) (\s :: SegmentGroup
s@SegmentGroup' {} Maybe [SegmentDimensions]
a -> SegmentGroup
s {$sel:dimensions:SegmentGroup' :: Maybe [SegmentDimensions]
dimensions = Maybe [SegmentDimensions]
a} :: SegmentGroup) ((Maybe [SegmentDimensions] -> f (Maybe [SegmentDimensions]))
 -> SegmentGroup -> f SegmentGroup)
-> ((Maybe [SegmentDimensions] -> f (Maybe [SegmentDimensions]))
    -> Maybe [SegmentDimensions] -> f (Maybe [SegmentDimensions]))
-> (Maybe [SegmentDimensions] -> f (Maybe [SegmentDimensions]))
-> SegmentGroup
-> f SegmentGroup
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [SegmentDimensions]
  [SegmentDimensions]
  [SegmentDimensions]
  [SegmentDimensions]
-> Iso
     (Maybe [SegmentDimensions])
     (Maybe [SegmentDimensions])
     (Maybe [SegmentDimensions])
     (Maybe [SegmentDimensions])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [SegmentDimensions]
  [SegmentDimensions]
  [SegmentDimensions]
  [SegmentDimensions]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON SegmentGroup where
  parseJSON :: Value -> Parser SegmentGroup
parseJSON =
    String
-> (Object -> Parser SegmentGroup) -> Value -> Parser SegmentGroup
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SegmentGroup"
      ( \Object
x ->
          Maybe [SegmentReference]
-> Maybe SourceType
-> Maybe Type
-> Maybe [SegmentDimensions]
-> SegmentGroup
SegmentGroup'
            (Maybe [SegmentReference]
 -> Maybe SourceType
 -> Maybe Type
 -> Maybe [SegmentDimensions]
 -> SegmentGroup)
-> Parser (Maybe [SegmentReference])
-> Parser
     (Maybe SourceType
      -> Maybe Type -> Maybe [SegmentDimensions] -> SegmentGroup)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [SegmentReference]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"SourceSegments" Parser (Maybe (Maybe [SegmentReference]))
-> Maybe [SegmentReference] -> Parser (Maybe [SegmentReference])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [SegmentReference]
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe SourceType
   -> Maybe Type -> Maybe [SegmentDimensions] -> SegmentGroup)
-> Parser (Maybe SourceType)
-> Parser (Maybe Type -> Maybe [SegmentDimensions] -> SegmentGroup)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe SourceType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"SourceType")
            Parser (Maybe Type -> Maybe [SegmentDimensions] -> SegmentGroup)
-> Parser (Maybe Type)
-> Parser (Maybe [SegmentDimensions] -> SegmentGroup)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Type)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Type")
            Parser (Maybe [SegmentDimensions] -> SegmentGroup)
-> Parser (Maybe [SegmentDimensions]) -> Parser SegmentGroup
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [SegmentDimensions]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Dimensions" Parser (Maybe (Maybe [SegmentDimensions]))
-> Maybe [SegmentDimensions] -> Parser (Maybe [SegmentDimensions])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [SegmentDimensions]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable SegmentGroup

instance Prelude.NFData SegmentGroup

instance Core.ToJSON SegmentGroup where
  toJSON :: SegmentGroup -> Value
toJSON SegmentGroup' {Maybe [SegmentReference]
Maybe [SegmentDimensions]
Maybe SourceType
Maybe Type
dimensions :: Maybe [SegmentDimensions]
type' :: Maybe Type
sourceType :: Maybe SourceType
sourceSegments :: Maybe [SegmentReference]
$sel:dimensions:SegmentGroup' :: SegmentGroup -> Maybe [SegmentDimensions]
$sel:type':SegmentGroup' :: SegmentGroup -> Maybe Type
$sel:sourceType:SegmentGroup' :: SegmentGroup -> Maybe SourceType
$sel:sourceSegments:SegmentGroup' :: SegmentGroup -> Maybe [SegmentReference]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"SourceSegments" Text -> [SegmentReference] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([SegmentReference] -> Pair)
-> Maybe [SegmentReference] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [SegmentReference]
sourceSegments,
            (Text
"SourceType" Text -> SourceType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (SourceType -> Pair) -> Maybe SourceType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SourceType
sourceType,
            (Text
"Type" Text -> Type -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Type -> Pair) -> Maybe Type -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Type
type',
            (Text
"Dimensions" 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]
dimensions
          ]
      )