{-# 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.ServiceQuotas.Types.ErrorReason
-- 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.ServiceQuotas.Types.ErrorReason where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.ServiceQuotas.Types.ErrorCode

-- | An error that explains why an action did not succeed.
--
-- /See:/ 'newErrorReason' smart constructor.
data ErrorReason = ErrorReason'
  { -- | Service Quotas returns the following error values:
    --
    -- -   @DEPENDENCY_ACCESS_DENIED_ERROR@ - The caller does not have the
    --     required permissions to complete the action. To resolve the error,
    --     you must have permission to access the service or quota.
    --
    -- -   @DEPENDENCY_THROTTLING_ERROR@ - The service is throttling Service
    --     Quotas.
    --
    -- -   @DEPENDENCY_SERVICE_ERROR@ - The service is not available.
    --
    -- -   @SERVICE_QUOTA_NOT_AVAILABLE_ERROR@ - There was an error in Service
    --     Quotas.
    ErrorReason -> Maybe ErrorCode
errorCode :: Prelude.Maybe ErrorCode,
    -- | The error message.
    ErrorReason -> Maybe Text
errorMessage :: Prelude.Maybe Prelude.Text
  }
  deriving (ErrorReason -> ErrorReason -> Bool
(ErrorReason -> ErrorReason -> Bool)
-> (ErrorReason -> ErrorReason -> Bool) -> Eq ErrorReason
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ErrorReason -> ErrorReason -> Bool
$c/= :: ErrorReason -> ErrorReason -> Bool
== :: ErrorReason -> ErrorReason -> Bool
$c== :: ErrorReason -> ErrorReason -> Bool
Prelude.Eq, ReadPrec [ErrorReason]
ReadPrec ErrorReason
Int -> ReadS ErrorReason
ReadS [ErrorReason]
(Int -> ReadS ErrorReason)
-> ReadS [ErrorReason]
-> ReadPrec ErrorReason
-> ReadPrec [ErrorReason]
-> Read ErrorReason
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ErrorReason]
$creadListPrec :: ReadPrec [ErrorReason]
readPrec :: ReadPrec ErrorReason
$creadPrec :: ReadPrec ErrorReason
readList :: ReadS [ErrorReason]
$creadList :: ReadS [ErrorReason]
readsPrec :: Int -> ReadS ErrorReason
$creadsPrec :: Int -> ReadS ErrorReason
Prelude.Read, Int -> ErrorReason -> ShowS
[ErrorReason] -> ShowS
ErrorReason -> String
(Int -> ErrorReason -> ShowS)
-> (ErrorReason -> String)
-> ([ErrorReason] -> ShowS)
-> Show ErrorReason
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ErrorReason] -> ShowS
$cshowList :: [ErrorReason] -> ShowS
show :: ErrorReason -> String
$cshow :: ErrorReason -> String
showsPrec :: Int -> ErrorReason -> ShowS
$cshowsPrec :: Int -> ErrorReason -> ShowS
Prelude.Show, (forall x. ErrorReason -> Rep ErrorReason x)
-> (forall x. Rep ErrorReason x -> ErrorReason)
-> Generic ErrorReason
forall x. Rep ErrorReason x -> ErrorReason
forall x. ErrorReason -> Rep ErrorReason x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ErrorReason x -> ErrorReason
$cfrom :: forall x. ErrorReason -> Rep ErrorReason x
Prelude.Generic)

-- |
-- Create a value of 'ErrorReason' 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:
--
-- 'errorCode', 'errorReason_errorCode' - Service Quotas returns the following error values:
--
-- -   @DEPENDENCY_ACCESS_DENIED_ERROR@ - The caller does not have the
--     required permissions to complete the action. To resolve the error,
--     you must have permission to access the service or quota.
--
-- -   @DEPENDENCY_THROTTLING_ERROR@ - The service is throttling Service
--     Quotas.
--
-- -   @DEPENDENCY_SERVICE_ERROR@ - The service is not available.
--
-- -   @SERVICE_QUOTA_NOT_AVAILABLE_ERROR@ - There was an error in Service
--     Quotas.
--
-- 'errorMessage', 'errorReason_errorMessage' - The error message.
newErrorReason ::
  ErrorReason
newErrorReason :: ErrorReason
newErrorReason =
  ErrorReason' :: Maybe ErrorCode -> Maybe Text -> ErrorReason
ErrorReason'
    { $sel:errorCode:ErrorReason' :: Maybe ErrorCode
errorCode = Maybe ErrorCode
forall a. Maybe a
Prelude.Nothing,
      $sel:errorMessage:ErrorReason' :: Maybe Text
errorMessage = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | Service Quotas returns the following error values:
--
-- -   @DEPENDENCY_ACCESS_DENIED_ERROR@ - The caller does not have the
--     required permissions to complete the action. To resolve the error,
--     you must have permission to access the service or quota.
--
-- -   @DEPENDENCY_THROTTLING_ERROR@ - The service is throttling Service
--     Quotas.
--
-- -   @DEPENDENCY_SERVICE_ERROR@ - The service is not available.
--
-- -   @SERVICE_QUOTA_NOT_AVAILABLE_ERROR@ - There was an error in Service
--     Quotas.
errorReason_errorCode :: Lens.Lens' ErrorReason (Prelude.Maybe ErrorCode)
errorReason_errorCode :: (Maybe ErrorCode -> f (Maybe ErrorCode))
-> ErrorReason -> f ErrorReason
errorReason_errorCode = (ErrorReason -> Maybe ErrorCode)
-> (ErrorReason -> Maybe ErrorCode -> ErrorReason)
-> Lens ErrorReason ErrorReason (Maybe ErrorCode) (Maybe ErrorCode)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ErrorReason' {Maybe ErrorCode
errorCode :: Maybe ErrorCode
$sel:errorCode:ErrorReason' :: ErrorReason -> Maybe ErrorCode
errorCode} -> Maybe ErrorCode
errorCode) (\s :: ErrorReason
s@ErrorReason' {} Maybe ErrorCode
a -> ErrorReason
s {$sel:errorCode:ErrorReason' :: Maybe ErrorCode
errorCode = Maybe ErrorCode
a} :: ErrorReason)

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

instance Core.FromJSON ErrorReason where
  parseJSON :: Value -> Parser ErrorReason
parseJSON =
    String
-> (Object -> Parser ErrorReason) -> Value -> Parser ErrorReason
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ErrorReason"
      ( \Object
x ->
          Maybe ErrorCode -> Maybe Text -> ErrorReason
ErrorReason'
            (Maybe ErrorCode -> Maybe Text -> ErrorReason)
-> Parser (Maybe ErrorCode) -> Parser (Maybe Text -> ErrorReason)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe ErrorCode)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ErrorCode")
            Parser (Maybe Text -> ErrorReason)
-> Parser (Maybe Text) -> Parser ErrorReason
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
"ErrorMessage")
      )

instance Prelude.Hashable ErrorReason

instance Prelude.NFData ErrorReason