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

import qualified Amazonka.Core as Core
import Amazonka.IoTSiteWise.Types.DetailedError
import Amazonka.IoTSiteWise.Types.ErrorCode
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains the details of an IoT SiteWise error.
--
-- /See:/ 'newErrorDetails' smart constructor.
data ErrorDetails = ErrorDetails'
  { -- | A list of detailed errors.
    ErrorDetails -> Maybe [DetailedError]
details :: Prelude.Maybe [DetailedError],
    -- | The error code.
    ErrorDetails -> ErrorCode
code :: ErrorCode,
    -- | The error message.
    ErrorDetails -> Text
message :: Prelude.Text
  }
  deriving (ErrorDetails -> ErrorDetails -> Bool
(ErrorDetails -> ErrorDetails -> Bool)
-> (ErrorDetails -> ErrorDetails -> Bool) -> Eq ErrorDetails
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ErrorDetails -> ErrorDetails -> Bool
$c/= :: ErrorDetails -> ErrorDetails -> Bool
== :: ErrorDetails -> ErrorDetails -> Bool
$c== :: ErrorDetails -> ErrorDetails -> Bool
Prelude.Eq, ReadPrec [ErrorDetails]
ReadPrec ErrorDetails
Int -> ReadS ErrorDetails
ReadS [ErrorDetails]
(Int -> ReadS ErrorDetails)
-> ReadS [ErrorDetails]
-> ReadPrec ErrorDetails
-> ReadPrec [ErrorDetails]
-> Read ErrorDetails
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ErrorDetails]
$creadListPrec :: ReadPrec [ErrorDetails]
readPrec :: ReadPrec ErrorDetails
$creadPrec :: ReadPrec ErrorDetails
readList :: ReadS [ErrorDetails]
$creadList :: ReadS [ErrorDetails]
readsPrec :: Int -> ReadS ErrorDetails
$creadsPrec :: Int -> ReadS ErrorDetails
Prelude.Read, Int -> ErrorDetails -> ShowS
[ErrorDetails] -> ShowS
ErrorDetails -> String
(Int -> ErrorDetails -> ShowS)
-> (ErrorDetails -> String)
-> ([ErrorDetails] -> ShowS)
-> Show ErrorDetails
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ErrorDetails] -> ShowS
$cshowList :: [ErrorDetails] -> ShowS
show :: ErrorDetails -> String
$cshow :: ErrorDetails -> String
showsPrec :: Int -> ErrorDetails -> ShowS
$cshowsPrec :: Int -> ErrorDetails -> ShowS
Prelude.Show, (forall x. ErrorDetails -> Rep ErrorDetails x)
-> (forall x. Rep ErrorDetails x -> ErrorDetails)
-> Generic ErrorDetails
forall x. Rep ErrorDetails x -> ErrorDetails
forall x. ErrorDetails -> Rep ErrorDetails x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ErrorDetails x -> ErrorDetails
$cfrom :: forall x. ErrorDetails -> Rep ErrorDetails x
Prelude.Generic)

-- |
-- Create a value of 'ErrorDetails' 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:
--
-- 'details', 'errorDetails_details' - A list of detailed errors.
--
-- 'code', 'errorDetails_code' - The error code.
--
-- 'message', 'errorDetails_message' - The error message.
newErrorDetails ::
  -- | 'code'
  ErrorCode ->
  -- | 'message'
  Prelude.Text ->
  ErrorDetails
newErrorDetails :: ErrorCode -> Text -> ErrorDetails
newErrorDetails ErrorCode
pCode_ Text
pMessage_ =
  ErrorDetails' :: Maybe [DetailedError] -> ErrorCode -> Text -> ErrorDetails
ErrorDetails'
    { $sel:details:ErrorDetails' :: Maybe [DetailedError]
details = Maybe [DetailedError]
forall a. Maybe a
Prelude.Nothing,
      $sel:code:ErrorDetails' :: ErrorCode
code = ErrorCode
pCode_,
      $sel:message:ErrorDetails' :: Text
message = Text
pMessage_
    }

-- | A list of detailed errors.
errorDetails_details :: Lens.Lens' ErrorDetails (Prelude.Maybe [DetailedError])
errorDetails_details :: (Maybe [DetailedError] -> f (Maybe [DetailedError]))
-> ErrorDetails -> f ErrorDetails
errorDetails_details = (ErrorDetails -> Maybe [DetailedError])
-> (ErrorDetails -> Maybe [DetailedError] -> ErrorDetails)
-> Lens
     ErrorDetails
     ErrorDetails
     (Maybe [DetailedError])
     (Maybe [DetailedError])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ErrorDetails' {Maybe [DetailedError]
details :: Maybe [DetailedError]
$sel:details:ErrorDetails' :: ErrorDetails -> Maybe [DetailedError]
details} -> Maybe [DetailedError]
details) (\s :: ErrorDetails
s@ErrorDetails' {} Maybe [DetailedError]
a -> ErrorDetails
s {$sel:details:ErrorDetails' :: Maybe [DetailedError]
details = Maybe [DetailedError]
a} :: ErrorDetails) ((Maybe [DetailedError] -> f (Maybe [DetailedError]))
 -> ErrorDetails -> f ErrorDetails)
-> ((Maybe [DetailedError] -> f (Maybe [DetailedError]))
    -> Maybe [DetailedError] -> f (Maybe [DetailedError]))
-> (Maybe [DetailedError] -> f (Maybe [DetailedError]))
-> ErrorDetails
-> f ErrorDetails
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [DetailedError] [DetailedError] [DetailedError] [DetailedError]
-> Iso
     (Maybe [DetailedError])
     (Maybe [DetailedError])
     (Maybe [DetailedError])
     (Maybe [DetailedError])
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
  [DetailedError] [DetailedError] [DetailedError] [DetailedError]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The error code.
errorDetails_code :: Lens.Lens' ErrorDetails ErrorCode
errorDetails_code :: (ErrorCode -> f ErrorCode) -> ErrorDetails -> f ErrorDetails
errorDetails_code = (ErrorDetails -> ErrorCode)
-> (ErrorDetails -> ErrorCode -> ErrorDetails)
-> Lens ErrorDetails ErrorDetails ErrorCode ErrorCode
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ErrorDetails' {ErrorCode
code :: ErrorCode
$sel:code:ErrorDetails' :: ErrorDetails -> ErrorCode
code} -> ErrorCode
code) (\s :: ErrorDetails
s@ErrorDetails' {} ErrorCode
a -> ErrorDetails
s {$sel:code:ErrorDetails' :: ErrorCode
code = ErrorCode
a} :: ErrorDetails)

-- | The error message.
errorDetails_message :: Lens.Lens' ErrorDetails Prelude.Text
errorDetails_message :: (Text -> f Text) -> ErrorDetails -> f ErrorDetails
errorDetails_message = (ErrorDetails -> Text)
-> (ErrorDetails -> Text -> ErrorDetails)
-> Lens ErrorDetails ErrorDetails Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ErrorDetails' {Text
message :: Text
$sel:message:ErrorDetails' :: ErrorDetails -> Text
message} -> Text
message) (\s :: ErrorDetails
s@ErrorDetails' {} Text
a -> ErrorDetails
s {$sel:message:ErrorDetails' :: Text
message = Text
a} :: ErrorDetails)

instance Core.FromJSON ErrorDetails where
  parseJSON :: Value -> Parser ErrorDetails
parseJSON =
    String
-> (Object -> Parser ErrorDetails) -> Value -> Parser ErrorDetails
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ErrorDetails"
      ( \Object
x ->
          Maybe [DetailedError] -> ErrorCode -> Text -> ErrorDetails
ErrorDetails'
            (Maybe [DetailedError] -> ErrorCode -> Text -> ErrorDetails)
-> Parser (Maybe [DetailedError])
-> Parser (ErrorCode -> Text -> ErrorDetails)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [DetailedError]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"details" Parser (Maybe (Maybe [DetailedError]))
-> Maybe [DetailedError] -> Parser (Maybe [DetailedError])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [DetailedError]
forall a. Monoid a => a
Prelude.mempty)
            Parser (ErrorCode -> Text -> ErrorDetails)
-> Parser ErrorCode -> Parser (Text -> ErrorDetails)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ErrorCode
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"code")
            Parser (Text -> ErrorDetails) -> Parser Text -> Parser ErrorDetails
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"message")
      )

instance Prelude.Hashable ErrorDetails

instance Prelude.NFData ErrorDetails