{-# 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.GreengrassV2.Types.CoreDevice
-- 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.GreengrassV2.Types.CoreDevice where

import qualified Amazonka.Core as Core
import Amazonka.GreengrassV2.Types.CoreDeviceStatus
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains information about a Greengrass core device, which is an IoT
-- thing that runs the IoT Greengrass Core software.
--
-- /See:/ 'newCoreDevice' smart constructor.
data CoreDevice = CoreDevice'
  { -- | The status of the core device. Core devices can have the following
    -- statuses:
    --
    -- -   @HEALTHY@ – The IoT Greengrass Core software and all components run
    --     on the core device without issue.
    --
    -- -   @UNHEALTHY@ – The IoT Greengrass Core software or a component is in
    --     a failed state on the core device.
    CoreDevice -> Maybe CoreDeviceStatus
status :: Prelude.Maybe CoreDeviceStatus,
    -- | The name of the core device. This is also the name of the IoT thing.
    CoreDevice -> Maybe Text
coreDeviceThingName :: Prelude.Maybe Prelude.Text,
    -- | The time at which the core device\'s status last updated, expressed in
    -- ISO 8601 format.
    CoreDevice -> Maybe POSIX
lastStatusUpdateTimestamp :: Prelude.Maybe Core.POSIX
  }
  deriving (CoreDevice -> CoreDevice -> Bool
(CoreDevice -> CoreDevice -> Bool)
-> (CoreDevice -> CoreDevice -> Bool) -> Eq CoreDevice
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CoreDevice -> CoreDevice -> Bool
$c/= :: CoreDevice -> CoreDevice -> Bool
== :: CoreDevice -> CoreDevice -> Bool
$c== :: CoreDevice -> CoreDevice -> Bool
Prelude.Eq, ReadPrec [CoreDevice]
ReadPrec CoreDevice
Int -> ReadS CoreDevice
ReadS [CoreDevice]
(Int -> ReadS CoreDevice)
-> ReadS [CoreDevice]
-> ReadPrec CoreDevice
-> ReadPrec [CoreDevice]
-> Read CoreDevice
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CoreDevice]
$creadListPrec :: ReadPrec [CoreDevice]
readPrec :: ReadPrec CoreDevice
$creadPrec :: ReadPrec CoreDevice
readList :: ReadS [CoreDevice]
$creadList :: ReadS [CoreDevice]
readsPrec :: Int -> ReadS CoreDevice
$creadsPrec :: Int -> ReadS CoreDevice
Prelude.Read, Int -> CoreDevice -> ShowS
[CoreDevice] -> ShowS
CoreDevice -> String
(Int -> CoreDevice -> ShowS)
-> (CoreDevice -> String)
-> ([CoreDevice] -> ShowS)
-> Show CoreDevice
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CoreDevice] -> ShowS
$cshowList :: [CoreDevice] -> ShowS
show :: CoreDevice -> String
$cshow :: CoreDevice -> String
showsPrec :: Int -> CoreDevice -> ShowS
$cshowsPrec :: Int -> CoreDevice -> ShowS
Prelude.Show, (forall x. CoreDevice -> Rep CoreDevice x)
-> (forall x. Rep CoreDevice x -> CoreDevice) -> Generic CoreDevice
forall x. Rep CoreDevice x -> CoreDevice
forall x. CoreDevice -> Rep CoreDevice x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CoreDevice x -> CoreDevice
$cfrom :: forall x. CoreDevice -> Rep CoreDevice x
Prelude.Generic)

-- |
-- Create a value of 'CoreDevice' 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:
--
-- 'status', 'coreDevice_status' - The status of the core device. Core devices can have the following
-- statuses:
--
-- -   @HEALTHY@ – The IoT Greengrass Core software and all components run
--     on the core device without issue.
--
-- -   @UNHEALTHY@ – The IoT Greengrass Core software or a component is in
--     a failed state on the core device.
--
-- 'coreDeviceThingName', 'coreDevice_coreDeviceThingName' - The name of the core device. This is also the name of the IoT thing.
--
-- 'lastStatusUpdateTimestamp', 'coreDevice_lastStatusUpdateTimestamp' - The time at which the core device\'s status last updated, expressed in
-- ISO 8601 format.
newCoreDevice ::
  CoreDevice
newCoreDevice :: CoreDevice
newCoreDevice =
  CoreDevice' :: Maybe CoreDeviceStatus -> Maybe Text -> Maybe POSIX -> CoreDevice
CoreDevice'
    { $sel:status:CoreDevice' :: Maybe CoreDeviceStatus
status = Maybe CoreDeviceStatus
forall a. Maybe a
Prelude.Nothing,
      $sel:coreDeviceThingName:CoreDevice' :: Maybe Text
coreDeviceThingName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:lastStatusUpdateTimestamp:CoreDevice' :: Maybe POSIX
lastStatusUpdateTimestamp = Maybe POSIX
forall a. Maybe a
Prelude.Nothing
    }

-- | The status of the core device. Core devices can have the following
-- statuses:
--
-- -   @HEALTHY@ – The IoT Greengrass Core software and all components run
--     on the core device without issue.
--
-- -   @UNHEALTHY@ – The IoT Greengrass Core software or a component is in
--     a failed state on the core device.
coreDevice_status :: Lens.Lens' CoreDevice (Prelude.Maybe CoreDeviceStatus)
coreDevice_status :: (Maybe CoreDeviceStatus -> f (Maybe CoreDeviceStatus))
-> CoreDevice -> f CoreDevice
coreDevice_status = (CoreDevice -> Maybe CoreDeviceStatus)
-> (CoreDevice -> Maybe CoreDeviceStatus -> CoreDevice)
-> Lens
     CoreDevice
     CoreDevice
     (Maybe CoreDeviceStatus)
     (Maybe CoreDeviceStatus)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CoreDevice' {Maybe CoreDeviceStatus
status :: Maybe CoreDeviceStatus
$sel:status:CoreDevice' :: CoreDevice -> Maybe CoreDeviceStatus
status} -> Maybe CoreDeviceStatus
status) (\s :: CoreDevice
s@CoreDevice' {} Maybe CoreDeviceStatus
a -> CoreDevice
s {$sel:status:CoreDevice' :: Maybe CoreDeviceStatus
status = Maybe CoreDeviceStatus
a} :: CoreDevice)

-- | The name of the core device. This is also the name of the IoT thing.
coreDevice_coreDeviceThingName :: Lens.Lens' CoreDevice (Prelude.Maybe Prelude.Text)
coreDevice_coreDeviceThingName :: (Maybe Text -> f (Maybe Text)) -> CoreDevice -> f CoreDevice
coreDevice_coreDeviceThingName = (CoreDevice -> Maybe Text)
-> (CoreDevice -> Maybe Text -> CoreDevice)
-> Lens CoreDevice CoreDevice (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CoreDevice' {Maybe Text
coreDeviceThingName :: Maybe Text
$sel:coreDeviceThingName:CoreDevice' :: CoreDevice -> Maybe Text
coreDeviceThingName} -> Maybe Text
coreDeviceThingName) (\s :: CoreDevice
s@CoreDevice' {} Maybe Text
a -> CoreDevice
s {$sel:coreDeviceThingName:CoreDevice' :: Maybe Text
coreDeviceThingName = Maybe Text
a} :: CoreDevice)

-- | The time at which the core device\'s status last updated, expressed in
-- ISO 8601 format.
coreDevice_lastStatusUpdateTimestamp :: Lens.Lens' CoreDevice (Prelude.Maybe Prelude.UTCTime)
coreDevice_lastStatusUpdateTimestamp :: (Maybe UTCTime -> f (Maybe UTCTime)) -> CoreDevice -> f CoreDevice
coreDevice_lastStatusUpdateTimestamp = (CoreDevice -> Maybe POSIX)
-> (CoreDevice -> Maybe POSIX -> CoreDevice)
-> Lens CoreDevice CoreDevice (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CoreDevice' {Maybe POSIX
lastStatusUpdateTimestamp :: Maybe POSIX
$sel:lastStatusUpdateTimestamp:CoreDevice' :: CoreDevice -> Maybe POSIX
lastStatusUpdateTimestamp} -> Maybe POSIX
lastStatusUpdateTimestamp) (\s :: CoreDevice
s@CoreDevice' {} Maybe POSIX
a -> CoreDevice
s {$sel:lastStatusUpdateTimestamp:CoreDevice' :: Maybe POSIX
lastStatusUpdateTimestamp = Maybe POSIX
a} :: CoreDevice) ((Maybe POSIX -> f (Maybe POSIX)) -> CoreDevice -> f CoreDevice)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> CoreDevice
-> f CoreDevice
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

instance Core.FromJSON CoreDevice where
  parseJSON :: Value -> Parser CoreDevice
parseJSON =
    String
-> (Object -> Parser CoreDevice) -> Value -> Parser CoreDevice
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CoreDevice"
      ( \Object
x ->
          Maybe CoreDeviceStatus -> Maybe Text -> Maybe POSIX -> CoreDevice
CoreDevice'
            (Maybe CoreDeviceStatus -> Maybe Text -> Maybe POSIX -> CoreDevice)
-> Parser (Maybe CoreDeviceStatus)
-> Parser (Maybe Text -> Maybe POSIX -> CoreDevice)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe CoreDeviceStatus)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"status")
            Parser (Maybe Text -> Maybe POSIX -> CoreDevice)
-> Parser (Maybe Text) -> Parser (Maybe POSIX -> CoreDevice)
forall (f :: * -> *) a b. Applicative f => 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
"coreDeviceThingName")
            Parser (Maybe POSIX -> CoreDevice)
-> Parser (Maybe POSIX) -> Parser CoreDevice
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"lastStatusUpdateTimestamp")
      )

instance Prelude.Hashable CoreDevice

instance Prelude.NFData CoreDevice