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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(RecencyDimension -> RecencyDimension -> Bool)
-> (RecencyDimension -> RecencyDimension -> Bool)
-> Eq RecencyDimension
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]
(Int -> ReadS RecencyDimension)
-> ReadS [RecencyDimension]
-> ReadPrec RecencyDimension
-> ReadPrec [RecencyDimension]
-> Read 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
(Int -> RecencyDimension -> ShowS)
-> (RecencyDimension -> String)
-> ([RecencyDimension] -> ShowS)
-> Show RecencyDimension
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. RecencyDimension -> Rep RecencyDimension x)
-> (forall x. Rep RecencyDimension x -> RecencyDimension)
-> Generic RecencyDimension
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' :: Duration -> RecencyType -> RecencyDimension
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 :: (Duration -> f Duration) -> RecencyDimension -> f RecencyDimension
recencyDimension_duration = (RecencyDimension -> Duration)
-> (RecencyDimension -> Duration -> RecencyDimension)
-> Lens RecencyDimension RecencyDimension Duration 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 :: (RecencyType -> f RecencyType)
-> RecencyDimension -> f RecencyDimension
recencyDimension_recencyType = (RecencyDimension -> RecencyType)
-> (RecencyDimension -> RecencyType -> RecencyDimension)
-> Lens RecencyDimension RecencyDimension RecencyType 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 Core.FromJSON RecencyDimension where
  parseJSON :: Value -> Parser RecencyDimension
parseJSON =
    String
-> (Object -> Parser RecencyDimension)
-> Value
-> Parser RecencyDimension
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RecencyDimension"
      ( \Object
x ->
          Duration -> RecencyType -> RecencyDimension
RecencyDimension'
            (Duration -> RecencyType -> RecencyDimension)
-> Parser Duration -> Parser (RecencyType -> RecencyDimension)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Duration
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Duration")
            Parser (RecencyType -> RecencyDimension)
-> Parser RecencyType -> Parser RecencyDimension
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser RecencyType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"RecencyType")
      )

instance Prelude.Hashable RecencyDimension

instance Prelude.NFData RecencyDimension

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Duration" Text -> Duration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Duration
duration),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"RecencyType" Text -> RecencyType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= RecencyType
recencyType)
          ]
      )