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

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

-- | Provides information about a session.
--
-- /See:/ 'newSession' smart constructor.
data Session = Session'
  { -- | The duration of the session, in milliseconds.
    Session -> Maybe Int
duration :: Prelude.Maybe Prelude.Int,
    -- | The date and time when the session ended.
    Session -> Maybe Text
stopTimestamp :: Prelude.Maybe Prelude.Text,
    -- | 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
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]
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
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. 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:
--
-- 'duration', 'session_duration' - The duration of the session, in milliseconds.
--
-- 'stopTimestamp', 'session_stopTimestamp' - The date and time when the session ended.
--
-- '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'
    { $sel:duration:Session' :: Maybe Int
duration = forall a. Maybe a
Prelude.Nothing,
      $sel:stopTimestamp:Session' :: Maybe Text
stopTimestamp = forall a. Maybe a
Prelude.Nothing,
      $sel:startTimestamp:Session' :: Text
startTimestamp = Text
pStartTimestamp_,
      $sel:id:Session' :: Text
id = Text
pId_
    }

-- | The duration of the session, in milliseconds.
session_duration :: Lens.Lens' Session (Prelude.Maybe Prelude.Int)
session_duration :: Lens' Session (Maybe Int)
session_duration = 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 ended.
session_stopTimestamp :: Lens.Lens' Session (Prelude.Maybe Prelude.Text)
session_stopTimestamp :: Lens' Session (Maybe Text)
session_stopTimestamp = 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 date and time when the session began.
session_startTimestamp :: Lens.Lens' Session Prelude.Text
session_startTimestamp :: Lens' Session Text
session_startTimestamp = 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 :: Lens' Session Text
session_id = 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 where
  hashWithSalt :: Int -> Session -> Int
hashWithSalt Int
_salt Session' {Maybe Int
Maybe Text
Text
id :: Text
startTimestamp :: Text
stopTimestamp :: Maybe Text
duration :: Maybe Int
$sel:id:Session' :: Session -> Text
$sel:startTimestamp:Session' :: Session -> Text
$sel:stopTimestamp:Session' :: Session -> Maybe Text
$sel:duration:Session' :: Session -> Maybe Int
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
duration
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
stopTimestamp
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
startTimestamp
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
id

instance Prelude.NFData Session where
  rnf :: Session -> ()
rnf Session' {Maybe Int
Maybe Text
Text
id :: Text
startTimestamp :: Text
stopTimestamp :: Maybe Text
duration :: Maybe Int
$sel:id:Session' :: Session -> Text
$sel:startTimestamp:Session' :: Session -> Text
$sel:stopTimestamp:Session' :: Session -> Maybe Text
$sel:duration:Session' :: Session -> Maybe Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
duration
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
stopTimestamp
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
startTimestamp
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
id

instance Data.ToJSON Session where
  toJSON :: Session -> Value
toJSON Session' {Maybe Int
Maybe Text
Text
id :: Text
startTimestamp :: Text
stopTimestamp :: Maybe Text
duration :: Maybe Int
$sel:id:Session' :: Session -> Text
$sel:startTimestamp:Session' :: Session -> Text
$sel:stopTimestamp:Session' :: Session -> Maybe Text
$sel:duration:Session' :: Session -> Maybe Int
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Duration" 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 Int
duration,
            (Key
"StopTimestamp" 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 Text
stopTimestamp,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"StartTimestamp" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
startTimestamp),
            forall a. a -> Maybe a
Prelude.Just (Key
"Id" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
id)
          ]
      )