{-# 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-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.SegmentBehaviors 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.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
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]
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
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. 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' {$sel:recency:SegmentBehaviors' :: Maybe RecencyDimension
recency = 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 :: Lens' SegmentBehaviors (Maybe RecencyDimension)
segmentBehaviors_recency = 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 Data.FromJSON SegmentBehaviors where
  parseJSON :: Value -> Parser SegmentBehaviors
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"SegmentBehaviors"
      ( \Object
x ->
          Maybe RecencyDimension -> SegmentBehaviors
SegmentBehaviors' 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
"Recency")
      )

instance Prelude.Hashable SegmentBehaviors where
  hashWithSalt :: Int -> SegmentBehaviors -> Int
hashWithSalt Int
_salt SegmentBehaviors' {Maybe RecencyDimension
recency :: Maybe RecencyDimension
$sel:recency:SegmentBehaviors' :: SegmentBehaviors -> Maybe RecencyDimension
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe RecencyDimension
recency

instance Prelude.NFData SegmentBehaviors where
  rnf :: SegmentBehaviors -> ()
rnf SegmentBehaviors' {Maybe RecencyDimension
recency :: Maybe RecencyDimension
$sel:recency:SegmentBehaviors' :: SegmentBehaviors -> Maybe RecencyDimension
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe RecencyDimension
recency

instance Data.ToJSON SegmentBehaviors where
  toJSON :: SegmentBehaviors -> Value
toJSON SegmentBehaviors' {Maybe RecencyDimension
recency :: Maybe RecencyDimension
$sel:recency:SegmentBehaviors' :: SegmentBehaviors -> Maybe RecencyDimension
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Key
"Recency" 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 RecencyDimension
recency]
      )