{-# 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.RecencyDimension
-- 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.RecencyDimension 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.Duration
import Amazonka.Pinpoint.Types.RecencyType
import qualified Amazonka.Prelude as Prelude

-- | Specifies criteria for including or excluding endpoints from a segment
-- based on how recently an endpoint was active.
--
-- /See:/ 'newRecencyDimension' smart constructor.
data RecencyDimension = RecencyDimension'
  { -- | The duration to use when determining whether an endpoint is active or
    -- inactive.
    RecencyDimension -> Duration
duration :: Duration,
    -- | The type of recency dimension to use for the segment. Valid values are:
    -- ACTIVE, endpoints that were active within the specified duration are
    -- included in the segment; and, INACTIVE, endpoints that weren\'t active
    -- within the specified duration are included in the segment.
    RecencyDimension -> RecencyType
recencyType :: RecencyType
  }
  deriving (RecencyDimension -> RecencyDimension -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RecencyDimension -> RecencyDimension -> Bool
$c/= :: RecencyDimension -> RecencyDimension -> Bool
== :: RecencyDimension -> RecencyDimension -> Bool
$c== :: RecencyDimension -> RecencyDimension -> Bool
Prelude.Eq, ReadPrec [RecencyDimension]
ReadPrec RecencyDimension
Int -> ReadS RecencyDimension
ReadS [RecencyDimension]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RecencyDimension]
$creadListPrec :: ReadPrec [RecencyDimension]
readPrec :: ReadPrec RecencyDimension
$creadPrec :: ReadPrec RecencyDimension
readList :: ReadS [RecencyDimension]
$creadList :: ReadS [RecencyDimension]
readsPrec :: Int -> ReadS RecencyDimension
$creadsPrec :: Int -> ReadS RecencyDimension
Prelude.Read, Int -> RecencyDimension -> ShowS
[RecencyDimension] -> ShowS
RecencyDimension -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RecencyDimension] -> ShowS
$cshowList :: [RecencyDimension] -> ShowS
show :: RecencyDimension -> String
$cshow :: RecencyDimension -> String
showsPrec :: Int -> RecencyDimension -> ShowS
$cshowsPrec :: Int -> RecencyDimension -> ShowS
Prelude.Show, forall x. Rep RecencyDimension x -> RecencyDimension
forall x. RecencyDimension -> Rep RecencyDimension x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RecencyDimension x -> RecencyDimension
$cfrom :: forall x. RecencyDimension -> Rep RecencyDimension x
Prelude.Generic)

-- |
-- Create a value of 'RecencyDimension' 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:
--
-- 'duration', 'recencyDimension_duration' - The duration to use when determining whether an endpoint is active or
-- inactive.
--
-- 'recencyType', 'recencyDimension_recencyType' - The type of recency dimension to use for the segment. Valid values are:
-- ACTIVE, endpoints that were active within the specified duration are
-- included in the segment; and, INACTIVE, endpoints that weren\'t active
-- within the specified duration are included in the segment.
newRecencyDimension ::
  -- | 'duration'
  Duration ->
  -- | 'recencyType'
  RecencyType ->
  RecencyDimension
newRecencyDimension :: Duration -> RecencyType -> RecencyDimension
newRecencyDimension Duration
pDuration_ RecencyType
pRecencyType_ =
  RecencyDimension'
    { $sel:duration:RecencyDimension' :: Duration
duration = Duration
pDuration_,
      $sel:recencyType:RecencyDimension' :: RecencyType
recencyType = RecencyType
pRecencyType_
    }

-- | The duration to use when determining whether an endpoint is active or
-- inactive.
recencyDimension_duration :: Lens.Lens' RecencyDimension Duration
recencyDimension_duration :: Lens' RecencyDimension Duration
recencyDimension_duration = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RecencyDimension' {Duration
duration :: Duration
$sel:duration:RecencyDimension' :: RecencyDimension -> Duration
duration} -> Duration
duration) (\s :: RecencyDimension
s@RecencyDimension' {} Duration
a -> RecencyDimension
s {$sel:duration:RecencyDimension' :: Duration
duration = Duration
a} :: RecencyDimension)

-- | The type of recency dimension to use for the segment. Valid values are:
-- ACTIVE, endpoints that were active within the specified duration are
-- included in the segment; and, INACTIVE, endpoints that weren\'t active
-- within the specified duration are included in the segment.
recencyDimension_recencyType :: Lens.Lens' RecencyDimension RecencyType
recencyDimension_recencyType :: Lens' RecencyDimension RecencyType
recencyDimension_recencyType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RecencyDimension' {RecencyType
recencyType :: RecencyType
$sel:recencyType:RecencyDimension' :: RecencyDimension -> RecencyType
recencyType} -> RecencyType
recencyType) (\s :: RecencyDimension
s@RecencyDimension' {} RecencyType
a -> RecencyDimension
s {$sel:recencyType:RecencyDimension' :: RecencyType
recencyType = RecencyType
a} :: RecencyDimension)

instance Data.FromJSON RecencyDimension where
  parseJSON :: Value -> Parser RecencyDimension
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RecencyDimension"
      ( \Object
x ->
          Duration -> RecencyType -> RecencyDimension
RecencyDimension'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Duration")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"RecencyType")
      )

instance Prelude.Hashable RecencyDimension where
  hashWithSalt :: Int -> RecencyDimension -> Int
hashWithSalt Int
_salt RecencyDimension' {Duration
RecencyType
recencyType :: RecencyType
duration :: Duration
$sel:recencyType:RecencyDimension' :: RecencyDimension -> RecencyType
$sel:duration:RecencyDimension' :: RecencyDimension -> Duration
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Duration
duration
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` RecencyType
recencyType

instance Prelude.NFData RecencyDimension where
  rnf :: RecencyDimension -> ()
rnf RecencyDimension' {Duration
RecencyType
recencyType :: RecencyType
duration :: Duration
$sel:recencyType:RecencyDimension' :: RecencyDimension -> RecencyType
$sel:duration:RecencyDimension' :: RecencyDimension -> Duration
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Duration
duration
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf RecencyType
recencyType

instance Data.ToJSON RecencyDimension where
  toJSON :: RecencyDimension -> Value
toJSON RecencyDimension' {Duration
RecencyType
recencyType :: RecencyType
duration :: Duration
$sel:recencyType:RecencyDimension' :: RecencyDimension -> RecencyType
$sel:duration:RecencyDimension' :: RecencyDimension -> Duration
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Duration" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Duration
duration),
            forall a. a -> Maybe a
Prelude.Just (Key
"RecencyType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= RecencyType
recencyType)
          ]
      )