{-# 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.IoTSiteWise.Types.AssetStatus
-- 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.IoTSiteWise.Types.AssetStatus where

import qualified Amazonka.Core as Core
import Amazonka.IoTSiteWise.Types.AssetState
import Amazonka.IoTSiteWise.Types.ErrorDetails
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains information about the current status of an asset. For more
-- information, see
-- <https://docs.aws.amazon.com/iot-sitewise/latest/userguide/asset-and-model-states.html Asset and model states>
-- in the /IoT SiteWise User Guide/.
--
-- /See:/ 'newAssetStatus' smart constructor.
data AssetStatus = AssetStatus'
  { -- | Contains associated error information, if any.
    AssetStatus -> Maybe ErrorDetails
error :: Prelude.Maybe ErrorDetails,
    -- | The current status of the asset.
    AssetStatus -> AssetState
state :: AssetState
  }
  deriving (AssetStatus -> AssetStatus -> Bool
(AssetStatus -> AssetStatus -> Bool)
-> (AssetStatus -> AssetStatus -> Bool) -> Eq AssetStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssetStatus -> AssetStatus -> Bool
$c/= :: AssetStatus -> AssetStatus -> Bool
== :: AssetStatus -> AssetStatus -> Bool
$c== :: AssetStatus -> AssetStatus -> Bool
Prelude.Eq, ReadPrec [AssetStatus]
ReadPrec AssetStatus
Int -> ReadS AssetStatus
ReadS [AssetStatus]
(Int -> ReadS AssetStatus)
-> ReadS [AssetStatus]
-> ReadPrec AssetStatus
-> ReadPrec [AssetStatus]
-> Read AssetStatus
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssetStatus]
$creadListPrec :: ReadPrec [AssetStatus]
readPrec :: ReadPrec AssetStatus
$creadPrec :: ReadPrec AssetStatus
readList :: ReadS [AssetStatus]
$creadList :: ReadS [AssetStatus]
readsPrec :: Int -> ReadS AssetStatus
$creadsPrec :: Int -> ReadS AssetStatus
Prelude.Read, Int -> AssetStatus -> ShowS
[AssetStatus] -> ShowS
AssetStatus -> String
(Int -> AssetStatus -> ShowS)
-> (AssetStatus -> String)
-> ([AssetStatus] -> ShowS)
-> Show AssetStatus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssetStatus] -> ShowS
$cshowList :: [AssetStatus] -> ShowS
show :: AssetStatus -> String
$cshow :: AssetStatus -> String
showsPrec :: Int -> AssetStatus -> ShowS
$cshowsPrec :: Int -> AssetStatus -> ShowS
Prelude.Show, (forall x. AssetStatus -> Rep AssetStatus x)
-> (forall x. Rep AssetStatus x -> AssetStatus)
-> Generic AssetStatus
forall x. Rep AssetStatus x -> AssetStatus
forall x. AssetStatus -> Rep AssetStatus x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssetStatus x -> AssetStatus
$cfrom :: forall x. AssetStatus -> Rep AssetStatus x
Prelude.Generic)

-- |
-- Create a value of 'AssetStatus' 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:
--
-- 'error', 'assetStatus_error' - Contains associated error information, if any.
--
-- 'state', 'assetStatus_state' - The current status of the asset.
newAssetStatus ::
  -- | 'state'
  AssetState ->
  AssetStatus
newAssetStatus :: AssetState -> AssetStatus
newAssetStatus AssetState
pState_ =
  AssetStatus' :: Maybe ErrorDetails -> AssetState -> AssetStatus
AssetStatus'
    { $sel:error:AssetStatus' :: Maybe ErrorDetails
error = Maybe ErrorDetails
forall a. Maybe a
Prelude.Nothing,
      $sel:state:AssetStatus' :: AssetState
state = AssetState
pState_
    }

-- | Contains associated error information, if any.
assetStatus_error :: Lens.Lens' AssetStatus (Prelude.Maybe ErrorDetails)
assetStatus_error :: (Maybe ErrorDetails -> f (Maybe ErrorDetails))
-> AssetStatus -> f AssetStatus
assetStatus_error = (AssetStatus -> Maybe ErrorDetails)
-> (AssetStatus -> Maybe ErrorDetails -> AssetStatus)
-> Lens
     AssetStatus AssetStatus (Maybe ErrorDetails) (Maybe ErrorDetails)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssetStatus' {Maybe ErrorDetails
error :: Maybe ErrorDetails
$sel:error:AssetStatus' :: AssetStatus -> Maybe ErrorDetails
error} -> Maybe ErrorDetails
error) (\s :: AssetStatus
s@AssetStatus' {} Maybe ErrorDetails
a -> AssetStatus
s {$sel:error:AssetStatus' :: Maybe ErrorDetails
error = Maybe ErrorDetails
a} :: AssetStatus)

-- | The current status of the asset.
assetStatus_state :: Lens.Lens' AssetStatus AssetState
assetStatus_state :: (AssetState -> f AssetState) -> AssetStatus -> f AssetStatus
assetStatus_state = (AssetStatus -> AssetState)
-> (AssetStatus -> AssetState -> AssetStatus)
-> Lens AssetStatus AssetStatus AssetState AssetState
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssetStatus' {AssetState
state :: AssetState
$sel:state:AssetStatus' :: AssetStatus -> AssetState
state} -> AssetState
state) (\s :: AssetStatus
s@AssetStatus' {} AssetState
a -> AssetStatus
s {$sel:state:AssetStatus' :: AssetState
state = AssetState
a} :: AssetStatus)

instance Core.FromJSON AssetStatus where
  parseJSON :: Value -> Parser AssetStatus
parseJSON =
    String
-> (Object -> Parser AssetStatus) -> Value -> Parser AssetStatus
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AssetStatus"
      ( \Object
x ->
          Maybe ErrorDetails -> AssetState -> AssetStatus
AssetStatus'
            (Maybe ErrorDetails -> AssetState -> AssetStatus)
-> Parser (Maybe ErrorDetails)
-> Parser (AssetState -> AssetStatus)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe ErrorDetails)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"error") Parser (AssetState -> AssetStatus)
-> Parser AssetState -> Parser AssetStatus
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser AssetState
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"state")
      )

instance Prelude.Hashable AssetStatus

instance Prelude.NFData AssetStatus