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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Pinpoint.Types.Include
import Amazonka.Pinpoint.Types.SegmentGroup
import qualified Amazonka.Prelude as Prelude

-- | Specifies the settings that define the relationships between segment
-- groups for a segment.
--
-- /See:/ 'newSegmentGroupList' smart constructor.
data SegmentGroupList = SegmentGroupList'
  { -- | Specifies how to handle multiple segment groups for the segment. For
    -- example, if the segment includes three segment groups, whether the
    -- resulting segment includes endpoints that match all, any, or none of the
    -- segment groups.
    SegmentGroupList -> Maybe Include
include :: Prelude.Maybe Include,
    -- | An array that defines the set of segment criteria to evaluate when
    -- handling segment groups for the segment.
    SegmentGroupList -> Maybe [SegmentGroup]
groups :: Prelude.Maybe [SegmentGroup]
  }
  deriving (SegmentGroupList -> SegmentGroupList -> Bool
(SegmentGroupList -> SegmentGroupList -> Bool)
-> (SegmentGroupList -> SegmentGroupList -> Bool)
-> Eq SegmentGroupList
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SegmentGroupList -> SegmentGroupList -> Bool
$c/= :: SegmentGroupList -> SegmentGroupList -> Bool
== :: SegmentGroupList -> SegmentGroupList -> Bool
$c== :: SegmentGroupList -> SegmentGroupList -> Bool
Prelude.Eq, ReadPrec [SegmentGroupList]
ReadPrec SegmentGroupList
Int -> ReadS SegmentGroupList
ReadS [SegmentGroupList]
(Int -> ReadS SegmentGroupList)
-> ReadS [SegmentGroupList]
-> ReadPrec SegmentGroupList
-> ReadPrec [SegmentGroupList]
-> Read SegmentGroupList
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SegmentGroupList]
$creadListPrec :: ReadPrec [SegmentGroupList]
readPrec :: ReadPrec SegmentGroupList
$creadPrec :: ReadPrec SegmentGroupList
readList :: ReadS [SegmentGroupList]
$creadList :: ReadS [SegmentGroupList]
readsPrec :: Int -> ReadS SegmentGroupList
$creadsPrec :: Int -> ReadS SegmentGroupList
Prelude.Read, Int -> SegmentGroupList -> ShowS
[SegmentGroupList] -> ShowS
SegmentGroupList -> String
(Int -> SegmentGroupList -> ShowS)
-> (SegmentGroupList -> String)
-> ([SegmentGroupList] -> ShowS)
-> Show SegmentGroupList
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SegmentGroupList] -> ShowS
$cshowList :: [SegmentGroupList] -> ShowS
show :: SegmentGroupList -> String
$cshow :: SegmentGroupList -> String
showsPrec :: Int -> SegmentGroupList -> ShowS
$cshowsPrec :: Int -> SegmentGroupList -> ShowS
Prelude.Show, (forall x. SegmentGroupList -> Rep SegmentGroupList x)
-> (forall x. Rep SegmentGroupList x -> SegmentGroupList)
-> Generic SegmentGroupList
forall x. Rep SegmentGroupList x -> SegmentGroupList
forall x. SegmentGroupList -> Rep SegmentGroupList x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SegmentGroupList x -> SegmentGroupList
$cfrom :: forall x. SegmentGroupList -> Rep SegmentGroupList x
Prelude.Generic)

-- |
-- Create a value of 'SegmentGroupList' 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:
--
-- 'include', 'segmentGroupList_include' - Specifies how to handle multiple segment groups for the segment. For
-- example, if the segment includes three segment groups, whether the
-- resulting segment includes endpoints that match all, any, or none of the
-- segment groups.
--
-- 'groups', 'segmentGroupList_groups' - An array that defines the set of segment criteria to evaluate when
-- handling segment groups for the segment.
newSegmentGroupList ::
  SegmentGroupList
newSegmentGroupList :: SegmentGroupList
newSegmentGroupList =
  SegmentGroupList' :: Maybe Include -> Maybe [SegmentGroup] -> SegmentGroupList
SegmentGroupList'
    { $sel:include:SegmentGroupList' :: Maybe Include
include = Maybe Include
forall a. Maybe a
Prelude.Nothing,
      $sel:groups:SegmentGroupList' :: Maybe [SegmentGroup]
groups = Maybe [SegmentGroup]
forall a. Maybe a
Prelude.Nothing
    }

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

-- | An array that defines the set of segment criteria to evaluate when
-- handling segment groups for the segment.
segmentGroupList_groups :: Lens.Lens' SegmentGroupList (Prelude.Maybe [SegmentGroup])
segmentGroupList_groups :: (Maybe [SegmentGroup] -> f (Maybe [SegmentGroup]))
-> SegmentGroupList -> f SegmentGroupList
segmentGroupList_groups = (SegmentGroupList -> Maybe [SegmentGroup])
-> (SegmentGroupList -> Maybe [SegmentGroup] -> SegmentGroupList)
-> Lens
     SegmentGroupList
     SegmentGroupList
     (Maybe [SegmentGroup])
     (Maybe [SegmentGroup])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SegmentGroupList' {Maybe [SegmentGroup]
groups :: Maybe [SegmentGroup]
$sel:groups:SegmentGroupList' :: SegmentGroupList -> Maybe [SegmentGroup]
groups} -> Maybe [SegmentGroup]
groups) (\s :: SegmentGroupList
s@SegmentGroupList' {} Maybe [SegmentGroup]
a -> SegmentGroupList
s {$sel:groups:SegmentGroupList' :: Maybe [SegmentGroup]
groups = Maybe [SegmentGroup]
a} :: SegmentGroupList) ((Maybe [SegmentGroup] -> f (Maybe [SegmentGroup]))
 -> SegmentGroupList -> f SegmentGroupList)
-> ((Maybe [SegmentGroup] -> f (Maybe [SegmentGroup]))
    -> Maybe [SegmentGroup] -> f (Maybe [SegmentGroup]))
-> (Maybe [SegmentGroup] -> f (Maybe [SegmentGroup]))
-> SegmentGroupList
-> f SegmentGroupList
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [SegmentGroup] [SegmentGroup] [SegmentGroup] [SegmentGroup]
-> Iso
     (Maybe [SegmentGroup])
     (Maybe [SegmentGroup])
     (Maybe [SegmentGroup])
     (Maybe [SegmentGroup])
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 [SegmentGroup] [SegmentGroup] [SegmentGroup] [SegmentGroup]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable SegmentGroupList

instance Prelude.NFData SegmentGroupList

instance Core.ToJSON SegmentGroupList where
  toJSON :: SegmentGroupList -> Value
toJSON SegmentGroupList' {Maybe [SegmentGroup]
Maybe Include
groups :: Maybe [SegmentGroup]
include :: Maybe Include
$sel:groups:SegmentGroupList' :: SegmentGroupList -> Maybe [SegmentGroup]
$sel:include:SegmentGroupList' :: SegmentGroupList -> Maybe Include
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Include" Text -> Include -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Include -> Pair) -> Maybe Include -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Include
include,
            (Text
"Groups" Text -> [SegmentGroup] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([SegmentGroup] -> Pair) -> Maybe [SegmentGroup] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [SegmentGroup]
groups
          ]
      )