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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Pinpoint.Types.RecencyDimension
import qualified Amazonka.Prelude as Prelude

-- | Specifies dimension settings for including or excluding endpoints from a
-- segment based on how recently an endpoint was active.
--
-- /See:/ 'newSegmentBehaviors' smart constructor.
data SegmentBehaviors = SegmentBehaviors'
  { -- | The dimension settings that are based on how recently an endpoint was
    -- active.
    SegmentBehaviors -> Maybe RecencyDimension
recency :: Prelude.Maybe RecencyDimension
  }
  deriving (SegmentBehaviors -> SegmentBehaviors -> Bool
(SegmentBehaviors -> SegmentBehaviors -> Bool)
-> (SegmentBehaviors -> SegmentBehaviors -> Bool)
-> Eq SegmentBehaviors
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SegmentBehaviors -> SegmentBehaviors -> Bool
$c/= :: SegmentBehaviors -> SegmentBehaviors -> Bool
== :: SegmentBehaviors -> SegmentBehaviors -> Bool
$c== :: SegmentBehaviors -> SegmentBehaviors -> Bool
Prelude.Eq, ReadPrec [SegmentBehaviors]
ReadPrec SegmentBehaviors
Int -> ReadS SegmentBehaviors
ReadS [SegmentBehaviors]
(Int -> ReadS SegmentBehaviors)
-> ReadS [SegmentBehaviors]
-> ReadPrec SegmentBehaviors
-> ReadPrec [SegmentBehaviors]
-> Read SegmentBehaviors
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SegmentBehaviors]
$creadListPrec :: ReadPrec [SegmentBehaviors]
readPrec :: ReadPrec SegmentBehaviors
$creadPrec :: ReadPrec SegmentBehaviors
readList :: ReadS [SegmentBehaviors]
$creadList :: ReadS [SegmentBehaviors]
readsPrec :: Int -> ReadS SegmentBehaviors
$creadsPrec :: Int -> ReadS SegmentBehaviors
Prelude.Read, Int -> SegmentBehaviors -> ShowS
[SegmentBehaviors] -> ShowS
SegmentBehaviors -> String
(Int -> SegmentBehaviors -> ShowS)
-> (SegmentBehaviors -> String)
-> ([SegmentBehaviors] -> ShowS)
-> Show SegmentBehaviors
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SegmentBehaviors] -> ShowS
$cshowList :: [SegmentBehaviors] -> ShowS
show :: SegmentBehaviors -> String
$cshow :: SegmentBehaviors -> String
showsPrec :: Int -> SegmentBehaviors -> ShowS
$cshowsPrec :: Int -> SegmentBehaviors -> ShowS
Prelude.Show, (forall x. SegmentBehaviors -> Rep SegmentBehaviors x)
-> (forall x. Rep SegmentBehaviors x -> SegmentBehaviors)
-> Generic SegmentBehaviors
forall x. Rep SegmentBehaviors x -> SegmentBehaviors
forall x. SegmentBehaviors -> Rep SegmentBehaviors x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SegmentBehaviors x -> SegmentBehaviors
$cfrom :: forall x. SegmentBehaviors -> Rep SegmentBehaviors x
Prelude.Generic)

-- |
-- Create a value of 'SegmentBehaviors' 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:
--
-- 'recency', 'segmentBehaviors_recency' - The dimension settings that are based on how recently an endpoint was
-- active.
newSegmentBehaviors ::
  SegmentBehaviors
newSegmentBehaviors :: SegmentBehaviors
newSegmentBehaviors =
  SegmentBehaviors' :: Maybe RecencyDimension -> SegmentBehaviors
SegmentBehaviors' {$sel:recency:SegmentBehaviors' :: Maybe RecencyDimension
recency = Maybe RecencyDimension
forall a. Maybe a
Prelude.Nothing}

-- | The dimension settings that are based on how recently an endpoint was
-- active.
segmentBehaviors_recency :: Lens.Lens' SegmentBehaviors (Prelude.Maybe RecencyDimension)
segmentBehaviors_recency :: (Maybe RecencyDimension -> f (Maybe RecencyDimension))
-> SegmentBehaviors -> f SegmentBehaviors
segmentBehaviors_recency = (SegmentBehaviors -> Maybe RecencyDimension)
-> (SegmentBehaviors -> Maybe RecencyDimension -> SegmentBehaviors)
-> Lens
     SegmentBehaviors
     SegmentBehaviors
     (Maybe RecencyDimension)
     (Maybe RecencyDimension)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SegmentBehaviors' {Maybe RecencyDimension
recency :: Maybe RecencyDimension
$sel:recency:SegmentBehaviors' :: SegmentBehaviors -> Maybe RecencyDimension
recency} -> Maybe RecencyDimension
recency) (\s :: SegmentBehaviors
s@SegmentBehaviors' {} Maybe RecencyDimension
a -> SegmentBehaviors
s {$sel:recency:SegmentBehaviors' :: Maybe RecencyDimension
recency = Maybe RecencyDimension
a} :: SegmentBehaviors)

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

instance Prelude.Hashable SegmentBehaviors

instance Prelude.NFData SegmentBehaviors

instance Core.ToJSON SegmentBehaviors where
  toJSON :: SegmentBehaviors -> Value
toJSON SegmentBehaviors' {Maybe RecencyDimension
recency :: Maybe RecencyDimension
$sel:recency:SegmentBehaviors' :: SegmentBehaviors -> Maybe RecencyDimension
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"Recency" Text -> RecencyDimension -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (RecencyDimension -> Pair) -> Maybe RecencyDimension -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe RecencyDimension
recency]
      )