{-# 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.ResourceGroups.Types.QueryError
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.ResourceGroups.Types.QueryError where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import Amazonka.ResourceGroups.Types.QueryErrorCode

-- | A two-part error structure that can occur in @ListGroupResources@ or
-- @SearchResources@ operations on CloudFormation stack-based queries. The
-- error occurs if the CloudFormation stack on which the query is based
-- either does not exist, or has a status that renders the stack inactive.
-- A @QueryError@ occurrence does not necessarily mean that AWS Resource
-- Groups could not complete the operation, but the resulting group might
-- have no member resources.
--
-- /See:/ 'newQueryError' smart constructor.
data QueryError = QueryError'
  { -- | Possible values are @CLOUDFORMATION_STACK_INACTIVE@ and
    -- @CLOUDFORMATION_STACK_NOT_EXISTING@.
    QueryError -> Maybe QueryErrorCode
errorCode :: Prelude.Maybe QueryErrorCode,
    -- | A message that explains the @ErrorCode@ value. Messages might state that
    -- the specified CloudFormation stack does not exist (or no longer exists).
    -- For @CLOUDFORMATION_STACK_INACTIVE@, the message typically states that
    -- the CloudFormation stack has a status that is not (or no longer) active,
    -- such as @CREATE_FAILED@.
    QueryError -> Maybe Text
message :: Prelude.Maybe Prelude.Text
  }
  deriving (QueryError -> QueryError -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: QueryError -> QueryError -> Bool
$c/= :: QueryError -> QueryError -> Bool
== :: QueryError -> QueryError -> Bool
$c== :: QueryError -> QueryError -> Bool
Prelude.Eq, ReadPrec [QueryError]
ReadPrec QueryError
Int -> ReadS QueryError
ReadS [QueryError]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [QueryError]
$creadListPrec :: ReadPrec [QueryError]
readPrec :: ReadPrec QueryError
$creadPrec :: ReadPrec QueryError
readList :: ReadS [QueryError]
$creadList :: ReadS [QueryError]
readsPrec :: Int -> ReadS QueryError
$creadsPrec :: Int -> ReadS QueryError
Prelude.Read, Int -> QueryError -> ShowS
[QueryError] -> ShowS
QueryError -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [QueryError] -> ShowS
$cshowList :: [QueryError] -> ShowS
show :: QueryError -> String
$cshow :: QueryError -> String
showsPrec :: Int -> QueryError -> ShowS
$cshowsPrec :: Int -> QueryError -> ShowS
Prelude.Show, forall x. Rep QueryError x -> QueryError
forall x. QueryError -> Rep QueryError x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep QueryError x -> QueryError
$cfrom :: forall x. QueryError -> Rep QueryError x
Prelude.Generic)

-- |
-- Create a value of 'QueryError' 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', 'queryError_errorCode' - Possible values are @CLOUDFORMATION_STACK_INACTIVE@ and
-- @CLOUDFORMATION_STACK_NOT_EXISTING@.
--
-- 'message', 'queryError_message' - A message that explains the @ErrorCode@ value. Messages might state that
-- the specified CloudFormation stack does not exist (or no longer exists).
-- For @CLOUDFORMATION_STACK_INACTIVE@, the message typically states that
-- the CloudFormation stack has a status that is not (or no longer) active,
-- such as @CREATE_FAILED@.
newQueryError ::
  QueryError
newQueryError :: QueryError
newQueryError =
  QueryError'
    { $sel:errorCode:QueryError' :: Maybe QueryErrorCode
errorCode = forall a. Maybe a
Prelude.Nothing,
      $sel:message:QueryError' :: Maybe Text
message = forall a. Maybe a
Prelude.Nothing
    }

-- | Possible values are @CLOUDFORMATION_STACK_INACTIVE@ and
-- @CLOUDFORMATION_STACK_NOT_EXISTING@.
queryError_errorCode :: Lens.Lens' QueryError (Prelude.Maybe QueryErrorCode)
queryError_errorCode :: Lens' QueryError (Maybe QueryErrorCode)
queryError_errorCode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryError' {Maybe QueryErrorCode
errorCode :: Maybe QueryErrorCode
$sel:errorCode:QueryError' :: QueryError -> Maybe QueryErrorCode
errorCode} -> Maybe QueryErrorCode
errorCode) (\s :: QueryError
s@QueryError' {} Maybe QueryErrorCode
a -> QueryError
s {$sel:errorCode:QueryError' :: Maybe QueryErrorCode
errorCode = Maybe QueryErrorCode
a} :: QueryError)

-- | A message that explains the @ErrorCode@ value. Messages might state that
-- the specified CloudFormation stack does not exist (or no longer exists).
-- For @CLOUDFORMATION_STACK_INACTIVE@, the message typically states that
-- the CloudFormation stack has a status that is not (or no longer) active,
-- such as @CREATE_FAILED@.
queryError_message :: Lens.Lens' QueryError (Prelude.Maybe Prelude.Text)
queryError_message :: Lens' QueryError (Maybe Text)
queryError_message = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryError' {Maybe Text
message :: Maybe Text
$sel:message:QueryError' :: QueryError -> Maybe Text
message} -> Maybe Text
message) (\s :: QueryError
s@QueryError' {} Maybe Text
a -> QueryError
s {$sel:message:QueryError' :: Maybe Text
message = Maybe Text
a} :: QueryError)

instance Data.FromJSON QueryError where
  parseJSON :: Value -> Parser QueryError
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"QueryError"
      ( \Object
x ->
          Maybe QueryErrorCode -> Maybe Text -> QueryError
QueryError'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"ErrorCode")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Message")
      )

instance Prelude.Hashable QueryError where
  hashWithSalt :: Int -> QueryError -> Int
hashWithSalt Int
_salt QueryError' {Maybe Text
Maybe QueryErrorCode
message :: Maybe Text
errorCode :: Maybe QueryErrorCode
$sel:message:QueryError' :: QueryError -> Maybe Text
$sel:errorCode:QueryError' :: QueryError -> Maybe QueryErrorCode
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe QueryErrorCode
errorCode
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
message

instance Prelude.NFData QueryError where
  rnf :: QueryError -> ()
rnf QueryError' {Maybe Text
Maybe QueryErrorCode
message :: Maybe Text
errorCode :: Maybe QueryErrorCode
$sel:message:QueryError' :: QueryError -> Maybe Text
$sel:errorCode:QueryError' :: QueryError -> Maybe QueryErrorCode
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe QueryErrorCode
errorCode
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
message