{-# 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.ResourceGroupsTagging.Types.FailureInfo
-- 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.ResourceGroupsTagging.Types.FailureInfo where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.ResourceGroupsTagging.Types.ResourceErrorCode

-- | Information about the errors that are returned for each failed resource.
-- This information can include @InternalServiceException@ and
-- @InvalidParameterException@ errors. It can also include any valid error
-- code returned by the AWS service that hosts the resource that the ARN
-- key represents.
--
-- The following are common error codes that you might receive from other
-- AWS services:
--
-- -   __InternalServiceException__ – This can mean that the Resource
--     Groups Tagging API didn\'t receive a response from another AWS
--     service. It can also mean the the resource type in the request is
--     not supported by the Resource Groups Tagging API. In these cases,
--     it\'s safe to retry the request and then call
--     <http://docs.aws.amazon.com/resourcegroupstagging/latest/APIReference/API_GetResources.html GetResources>
--     to verify the changes.
--
-- -   __AccessDeniedException__ – This can mean that you need permission
--     to calling tagging operations in the AWS service that contains the
--     resource. For example, to use the Resource Groups Tagging API to tag
--     a CloudWatch alarm resource, you need permission to call
--     <http://docs.aws.amazon.com/resourcegroupstagging/latest/APIReference/API_TagResources.html TagResources>
--     /and/
--     <http://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_TagResource.html TagResource>
--     in the CloudWatch API.
--
-- For more information on errors that are generated from other AWS
-- services, see the documentation for that service.
--
-- /See:/ 'newFailureInfo' smart constructor.
data FailureInfo = FailureInfo'
  { -- | The code of the common error. Valid values include
    -- @InternalServiceException@, @InvalidParameterException@, and any valid
    -- error code returned by the AWS service that hosts the resource that you
    -- want to tag.
    FailureInfo -> Maybe ResourceErrorCode
errorCode :: Prelude.Maybe ResourceErrorCode,
    -- | The message of the common error.
    FailureInfo -> Maybe Text
errorMessage :: Prelude.Maybe Prelude.Text,
    -- | The HTTP status code of the common error.
    FailureInfo -> Maybe Int
statusCode :: Prelude.Maybe Prelude.Int
  }
  deriving (FailureInfo -> FailureInfo -> Bool
(FailureInfo -> FailureInfo -> Bool)
-> (FailureInfo -> FailureInfo -> Bool) -> Eq FailureInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FailureInfo -> FailureInfo -> Bool
$c/= :: FailureInfo -> FailureInfo -> Bool
== :: FailureInfo -> FailureInfo -> Bool
$c== :: FailureInfo -> FailureInfo -> Bool
Prelude.Eq, ReadPrec [FailureInfo]
ReadPrec FailureInfo
Int -> ReadS FailureInfo
ReadS [FailureInfo]
(Int -> ReadS FailureInfo)
-> ReadS [FailureInfo]
-> ReadPrec FailureInfo
-> ReadPrec [FailureInfo]
-> Read FailureInfo
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FailureInfo]
$creadListPrec :: ReadPrec [FailureInfo]
readPrec :: ReadPrec FailureInfo
$creadPrec :: ReadPrec FailureInfo
readList :: ReadS [FailureInfo]
$creadList :: ReadS [FailureInfo]
readsPrec :: Int -> ReadS FailureInfo
$creadsPrec :: Int -> ReadS FailureInfo
Prelude.Read, Int -> FailureInfo -> ShowS
[FailureInfo] -> ShowS
FailureInfo -> String
(Int -> FailureInfo -> ShowS)
-> (FailureInfo -> String)
-> ([FailureInfo] -> ShowS)
-> Show FailureInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FailureInfo] -> ShowS
$cshowList :: [FailureInfo] -> ShowS
show :: FailureInfo -> String
$cshow :: FailureInfo -> String
showsPrec :: Int -> FailureInfo -> ShowS
$cshowsPrec :: Int -> FailureInfo -> ShowS
Prelude.Show, (forall x. FailureInfo -> Rep FailureInfo x)
-> (forall x. Rep FailureInfo x -> FailureInfo)
-> Generic FailureInfo
forall x. Rep FailureInfo x -> FailureInfo
forall x. FailureInfo -> Rep FailureInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FailureInfo x -> FailureInfo
$cfrom :: forall x. FailureInfo -> Rep FailureInfo x
Prelude.Generic)

-- |
-- Create a value of 'FailureInfo' 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', 'failureInfo_errorCode' - The code of the common error. Valid values include
-- @InternalServiceException@, @InvalidParameterException@, and any valid
-- error code returned by the AWS service that hosts the resource that you
-- want to tag.
--
-- 'errorMessage', 'failureInfo_errorMessage' - The message of the common error.
--
-- 'statusCode', 'failureInfo_statusCode' - The HTTP status code of the common error.
newFailureInfo ::
  FailureInfo
newFailureInfo :: FailureInfo
newFailureInfo =
  FailureInfo' :: Maybe ResourceErrorCode -> Maybe Text -> Maybe Int -> FailureInfo
FailureInfo'
    { $sel:errorCode:FailureInfo' :: Maybe ResourceErrorCode
errorCode = Maybe ResourceErrorCode
forall a. Maybe a
Prelude.Nothing,
      $sel:errorMessage:FailureInfo' :: Maybe Text
errorMessage = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:statusCode:FailureInfo' :: Maybe Int
statusCode = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | The code of the common error. Valid values include
-- @InternalServiceException@, @InvalidParameterException@, and any valid
-- error code returned by the AWS service that hosts the resource that you
-- want to tag.
failureInfo_errorCode :: Lens.Lens' FailureInfo (Prelude.Maybe ResourceErrorCode)
failureInfo_errorCode :: (Maybe ResourceErrorCode -> f (Maybe ResourceErrorCode))
-> FailureInfo -> f FailureInfo
failureInfo_errorCode = (FailureInfo -> Maybe ResourceErrorCode)
-> (FailureInfo -> Maybe ResourceErrorCode -> FailureInfo)
-> Lens
     FailureInfo
     FailureInfo
     (Maybe ResourceErrorCode)
     (Maybe ResourceErrorCode)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FailureInfo' {Maybe ResourceErrorCode
errorCode :: Maybe ResourceErrorCode
$sel:errorCode:FailureInfo' :: FailureInfo -> Maybe ResourceErrorCode
errorCode} -> Maybe ResourceErrorCode
errorCode) (\s :: FailureInfo
s@FailureInfo' {} Maybe ResourceErrorCode
a -> FailureInfo
s {$sel:errorCode:FailureInfo' :: Maybe ResourceErrorCode
errorCode = Maybe ResourceErrorCode
a} :: FailureInfo)

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

-- | The HTTP status code of the common error.
failureInfo_statusCode :: Lens.Lens' FailureInfo (Prelude.Maybe Prelude.Int)
failureInfo_statusCode :: (Maybe Int -> f (Maybe Int)) -> FailureInfo -> f FailureInfo
failureInfo_statusCode = (FailureInfo -> Maybe Int)
-> (FailureInfo -> Maybe Int -> FailureInfo)
-> Lens FailureInfo FailureInfo (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FailureInfo' {Maybe Int
statusCode :: Maybe Int
$sel:statusCode:FailureInfo' :: FailureInfo -> Maybe Int
statusCode} -> Maybe Int
statusCode) (\s :: FailureInfo
s@FailureInfo' {} Maybe Int
a -> FailureInfo
s {$sel:statusCode:FailureInfo' :: Maybe Int
statusCode = Maybe Int
a} :: FailureInfo)

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

instance Prelude.Hashable FailureInfo

instance Prelude.NFData FailureInfo