{-# 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.IoT.Types.ThingConnectivity
-- 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.IoT.Types.ThingConnectivity 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

-- | The connectivity status of the thing.
--
-- /See:/ 'newThingConnectivity' smart constructor.
data ThingConnectivity = ThingConnectivity'
  { -- | True if the thing is connected to the Amazon Web Services IoT Core
    -- service; false if it is not connected.
    ThingConnectivity -> Maybe Bool
connected :: Prelude.Maybe Prelude.Bool,
    -- | The reason why the client is disconnected. If the thing has been
    -- disconnected for approximately an hour, the @disconnectReason@ value
    -- might be missing.
    ThingConnectivity -> Maybe Text
disconnectReason :: Prelude.Maybe Prelude.Text,
    -- | The epoch time (in milliseconds) when the thing last connected or
    -- disconnected. If the thing has been disconnected for approximately an
    -- hour, the time value might be missing.
    ThingConnectivity -> Maybe Integer
timestamp :: Prelude.Maybe Prelude.Integer
  }
  deriving (ThingConnectivity -> ThingConnectivity -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ThingConnectivity -> ThingConnectivity -> Bool
$c/= :: ThingConnectivity -> ThingConnectivity -> Bool
== :: ThingConnectivity -> ThingConnectivity -> Bool
$c== :: ThingConnectivity -> ThingConnectivity -> Bool
Prelude.Eq, ReadPrec [ThingConnectivity]
ReadPrec ThingConnectivity
Int -> ReadS ThingConnectivity
ReadS [ThingConnectivity]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ThingConnectivity]
$creadListPrec :: ReadPrec [ThingConnectivity]
readPrec :: ReadPrec ThingConnectivity
$creadPrec :: ReadPrec ThingConnectivity
readList :: ReadS [ThingConnectivity]
$creadList :: ReadS [ThingConnectivity]
readsPrec :: Int -> ReadS ThingConnectivity
$creadsPrec :: Int -> ReadS ThingConnectivity
Prelude.Read, Int -> ThingConnectivity -> ShowS
[ThingConnectivity] -> ShowS
ThingConnectivity -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ThingConnectivity] -> ShowS
$cshowList :: [ThingConnectivity] -> ShowS
show :: ThingConnectivity -> String
$cshow :: ThingConnectivity -> String
showsPrec :: Int -> ThingConnectivity -> ShowS
$cshowsPrec :: Int -> ThingConnectivity -> ShowS
Prelude.Show, forall x. Rep ThingConnectivity x -> ThingConnectivity
forall x. ThingConnectivity -> Rep ThingConnectivity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ThingConnectivity x -> ThingConnectivity
$cfrom :: forall x. ThingConnectivity -> Rep ThingConnectivity x
Prelude.Generic)

-- |
-- Create a value of 'ThingConnectivity' 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:
--
-- 'connected', 'thingConnectivity_connected' - True if the thing is connected to the Amazon Web Services IoT Core
-- service; false if it is not connected.
--
-- 'disconnectReason', 'thingConnectivity_disconnectReason' - The reason why the client is disconnected. If the thing has been
-- disconnected for approximately an hour, the @disconnectReason@ value
-- might be missing.
--
-- 'timestamp', 'thingConnectivity_timestamp' - The epoch time (in milliseconds) when the thing last connected or
-- disconnected. If the thing has been disconnected for approximately an
-- hour, the time value might be missing.
newThingConnectivity ::
  ThingConnectivity
newThingConnectivity :: ThingConnectivity
newThingConnectivity =
  ThingConnectivity'
    { $sel:connected:ThingConnectivity' :: Maybe Bool
connected = forall a. Maybe a
Prelude.Nothing,
      $sel:disconnectReason:ThingConnectivity' :: Maybe Text
disconnectReason = forall a. Maybe a
Prelude.Nothing,
      $sel:timestamp:ThingConnectivity' :: Maybe Integer
timestamp = forall a. Maybe a
Prelude.Nothing
    }

-- | True if the thing is connected to the Amazon Web Services IoT Core
-- service; false if it is not connected.
thingConnectivity_connected :: Lens.Lens' ThingConnectivity (Prelude.Maybe Prelude.Bool)
thingConnectivity_connected :: Lens' ThingConnectivity (Maybe Bool)
thingConnectivity_connected = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ThingConnectivity' {Maybe Bool
connected :: Maybe Bool
$sel:connected:ThingConnectivity' :: ThingConnectivity -> Maybe Bool
connected} -> Maybe Bool
connected) (\s :: ThingConnectivity
s@ThingConnectivity' {} Maybe Bool
a -> ThingConnectivity
s {$sel:connected:ThingConnectivity' :: Maybe Bool
connected = Maybe Bool
a} :: ThingConnectivity)

-- | The reason why the client is disconnected. If the thing has been
-- disconnected for approximately an hour, the @disconnectReason@ value
-- might be missing.
thingConnectivity_disconnectReason :: Lens.Lens' ThingConnectivity (Prelude.Maybe Prelude.Text)
thingConnectivity_disconnectReason :: Lens' ThingConnectivity (Maybe Text)
thingConnectivity_disconnectReason = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ThingConnectivity' {Maybe Text
disconnectReason :: Maybe Text
$sel:disconnectReason:ThingConnectivity' :: ThingConnectivity -> Maybe Text
disconnectReason} -> Maybe Text
disconnectReason) (\s :: ThingConnectivity
s@ThingConnectivity' {} Maybe Text
a -> ThingConnectivity
s {$sel:disconnectReason:ThingConnectivity' :: Maybe Text
disconnectReason = Maybe Text
a} :: ThingConnectivity)

-- | The epoch time (in milliseconds) when the thing last connected or
-- disconnected. If the thing has been disconnected for approximately an
-- hour, the time value might be missing.
thingConnectivity_timestamp :: Lens.Lens' ThingConnectivity (Prelude.Maybe Prelude.Integer)
thingConnectivity_timestamp :: Lens' ThingConnectivity (Maybe Integer)
thingConnectivity_timestamp = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ThingConnectivity' {Maybe Integer
timestamp :: Maybe Integer
$sel:timestamp:ThingConnectivity' :: ThingConnectivity -> Maybe Integer
timestamp} -> Maybe Integer
timestamp) (\s :: ThingConnectivity
s@ThingConnectivity' {} Maybe Integer
a -> ThingConnectivity
s {$sel:timestamp:ThingConnectivity' :: Maybe Integer
timestamp = Maybe Integer
a} :: ThingConnectivity)

instance Data.FromJSON ThingConnectivity where
  parseJSON :: Value -> Parser ThingConnectivity
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ThingConnectivity"
      ( \Object
x ->
          Maybe Bool -> Maybe Text -> Maybe Integer -> ThingConnectivity
ThingConnectivity'
            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
"connected")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"disconnectReason")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"timestamp")
      )

instance Prelude.Hashable ThingConnectivity where
  hashWithSalt :: Int -> ThingConnectivity -> Int
hashWithSalt Int
_salt ThingConnectivity' {Maybe Bool
Maybe Integer
Maybe Text
timestamp :: Maybe Integer
disconnectReason :: Maybe Text
connected :: Maybe Bool
$sel:timestamp:ThingConnectivity' :: ThingConnectivity -> Maybe Integer
$sel:disconnectReason:ThingConnectivity' :: ThingConnectivity -> Maybe Text
$sel:connected:ThingConnectivity' :: ThingConnectivity -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
connected
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
disconnectReason
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Integer
timestamp

instance Prelude.NFData ThingConnectivity where
  rnf :: ThingConnectivity -> ()
rnf ThingConnectivity' {Maybe Bool
Maybe Integer
Maybe Text
timestamp :: Maybe Integer
disconnectReason :: Maybe Text
connected :: Maybe Bool
$sel:timestamp:ThingConnectivity' :: ThingConnectivity -> Maybe Integer
$sel:disconnectReason:ThingConnectivity' :: ThingConnectivity -> Maybe Text
$sel:connected:ThingConnectivity' :: ThingConnectivity -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
connected
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
disconnectReason
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Integer
timestamp