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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Provides information about a session.
--
-- /See:/ 'newSession' smart constructor.
data Session = Session'
  { -- | The date and time when the session ended.
    Session -> Maybe Text
stopTimestamp :: Prelude.Maybe Prelude.Text,
    -- | The duration of the session, in milliseconds.
    Session -> Maybe Int
duration :: Prelude.Maybe Prelude.Int,
    -- | The date and time when the session began.
    Session -> Text
startTimestamp :: Prelude.Text,
    -- | The unique identifier for the session.
    Session -> Text
id :: Prelude.Text
  }
  deriving (Session -> Session -> Bool
(Session -> Session -> Bool)
-> (Session -> Session -> Bool) -> Eq Session
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Session -> Session -> Bool
$c/= :: Session -> Session -> Bool
== :: Session -> Session -> Bool
$c== :: Session -> Session -> Bool
Prelude.Eq, ReadPrec [Session]
ReadPrec Session
Int -> ReadS Session
ReadS [Session]
(Int -> ReadS Session)
-> ReadS [Session]
-> ReadPrec Session
-> ReadPrec [Session]
-> Read Session
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Session]
$creadListPrec :: ReadPrec [Session]
readPrec :: ReadPrec Session
$creadPrec :: ReadPrec Session
readList :: ReadS [Session]
$creadList :: ReadS [Session]
readsPrec :: Int -> ReadS Session
$creadsPrec :: Int -> ReadS Session
Prelude.Read, Int -> Session -> ShowS
[Session] -> ShowS
Session -> String
(Int -> Session -> ShowS)
-> (Session -> String) -> ([Session] -> ShowS) -> Show Session
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Session] -> ShowS
$cshowList :: [Session] -> ShowS
show :: Session -> String
$cshow :: Session -> String
showsPrec :: Int -> Session -> ShowS
$cshowsPrec :: Int -> Session -> ShowS
Prelude.Show, (forall x. Session -> Rep Session x)
-> (forall x. Rep Session x -> Session) -> Generic Session
forall x. Rep Session x -> Session
forall x. Session -> Rep Session x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Session x -> Session
$cfrom :: forall x. Session -> Rep Session x
Prelude.Generic)

-- |
-- Create a value of 'Session' 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:
--
-- 'stopTimestamp', 'session_stopTimestamp' - The date and time when the session ended.
--
-- 'duration', 'session_duration' - The duration of the session, in milliseconds.
--
-- 'startTimestamp', 'session_startTimestamp' - The date and time when the session began.
--
-- 'id', 'session_id' - The unique identifier for the session.
newSession ::
  -- | 'startTimestamp'
  Prelude.Text ->
  -- | 'id'
  Prelude.Text ->
  Session
newSession :: Text -> Text -> Session
newSession Text
pStartTimestamp_ Text
pId_ =
  Session' :: Maybe Text -> Maybe Int -> Text -> Text -> Session
Session'
    { $sel:stopTimestamp:Session' :: Maybe Text
stopTimestamp = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:duration:Session' :: Maybe Int
duration = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:startTimestamp:Session' :: Text
startTimestamp = Text
pStartTimestamp_,
      $sel:id:Session' :: Text
id = Text
pId_
    }

-- | The date and time when the session ended.
session_stopTimestamp :: Lens.Lens' Session (Prelude.Maybe Prelude.Text)
session_stopTimestamp :: (Maybe Text -> f (Maybe Text)) -> Session -> f Session
session_stopTimestamp = (Session -> Maybe Text)
-> (Session -> Maybe Text -> Session)
-> Lens Session Session (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Session' {Maybe Text
stopTimestamp :: Maybe Text
$sel:stopTimestamp:Session' :: Session -> Maybe Text
stopTimestamp} -> Maybe Text
stopTimestamp) (\s :: Session
s@Session' {} Maybe Text
a -> Session
s {$sel:stopTimestamp:Session' :: Maybe Text
stopTimestamp = Maybe Text
a} :: Session)

-- | The duration of the session, in milliseconds.
session_duration :: Lens.Lens' Session (Prelude.Maybe Prelude.Int)
session_duration :: (Maybe Int -> f (Maybe Int)) -> Session -> f Session
session_duration = (Session -> Maybe Int)
-> (Session -> Maybe Int -> Session)
-> Lens Session Session (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Session' {Maybe Int
duration :: Maybe Int
$sel:duration:Session' :: Session -> Maybe Int
duration} -> Maybe Int
duration) (\s :: Session
s@Session' {} Maybe Int
a -> Session
s {$sel:duration:Session' :: Maybe Int
duration = Maybe Int
a} :: Session)

-- | The date and time when the session began.
session_startTimestamp :: Lens.Lens' Session Prelude.Text
session_startTimestamp :: (Text -> f Text) -> Session -> f Session
session_startTimestamp = (Session -> Text)
-> (Session -> Text -> Session) -> Lens Session Session Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Session' {Text
startTimestamp :: Text
$sel:startTimestamp:Session' :: Session -> Text
startTimestamp} -> Text
startTimestamp) (\s :: Session
s@Session' {} Text
a -> Session
s {$sel:startTimestamp:Session' :: Text
startTimestamp = Text
a} :: Session)

-- | The unique identifier for the session.
session_id :: Lens.Lens' Session Prelude.Text
session_id :: (Text -> f Text) -> Session -> f Session
session_id = (Session -> Text)
-> (Session -> Text -> Session) -> Lens Session Session Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Session' {Text
id :: Text
$sel:id:Session' :: Session -> Text
id} -> Text
id) (\s :: Session
s@Session' {} Text
a -> Session
s {$sel:id:Session' :: Text
id = Text
a} :: Session)

instance Prelude.Hashable Session

instance Prelude.NFData Session

instance Core.ToJSON Session where
  toJSON :: Session -> Value
toJSON Session' {Maybe Int
Maybe Text
Text
id :: Text
startTimestamp :: Text
duration :: Maybe Int
stopTimestamp :: Maybe Text
$sel:id:Session' :: Session -> Text
$sel:startTimestamp:Session' :: Session -> Text
$sel:duration:Session' :: Session -> Maybe Int
$sel:stopTimestamp:Session' :: Session -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"StopTimestamp" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
stopTimestamp,
            (Text
"Duration" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
duration,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"StartTimestamp" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
startTimestamp),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Id" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
id)
          ]
      )