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

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

-- | The connectivity status of the thing.
--
-- /See:/ 'newThingConnectivity' smart constructor.
data ThingConnectivity = 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 -> Maybe Text
disconnectReason :: Prelude.Maybe Prelude.Text,
    -- | 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 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
(ThingConnectivity -> ThingConnectivity -> Bool)
-> (ThingConnectivity -> ThingConnectivity -> Bool)
-> Eq ThingConnectivity
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]
(Int -> ReadS ThingConnectivity)
-> ReadS [ThingConnectivity]
-> ReadPrec ThingConnectivity
-> ReadPrec [ThingConnectivity]
-> Read 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
(Int -> ThingConnectivity -> ShowS)
-> (ThingConnectivity -> String)
-> ([ThingConnectivity] -> ShowS)
-> Show ThingConnectivity
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. ThingConnectivity -> Rep ThingConnectivity x)
-> (forall x. Rep ThingConnectivity x -> ThingConnectivity)
-> Generic ThingConnectivity
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:
--
-- '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.
--
-- 'connected', 'thingConnectivity_connected' - True if the thing is connected to the Amazon Web Services IoT Core
-- service; false if it is not connected.
--
-- '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' :: Maybe Text -> Maybe Bool -> Maybe Integer -> ThingConnectivity
ThingConnectivity'
    { $sel:disconnectReason:ThingConnectivity' :: Maybe Text
disconnectReason =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:connected:ThingConnectivity' :: Maybe Bool
connected = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:timestamp:ThingConnectivity' :: Maybe Integer
timestamp = Maybe Integer
forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: (Maybe Text -> f (Maybe Text))
-> ThingConnectivity -> f ThingConnectivity
thingConnectivity_disconnectReason = (ThingConnectivity -> Maybe Text)
-> (ThingConnectivity -> Maybe Text -> ThingConnectivity)
-> Lens
     ThingConnectivity ThingConnectivity (Maybe Text) (Maybe Text)
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)

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

instance Prelude.Hashable ThingConnectivity

instance Prelude.NFData ThingConnectivity