{-# 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-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.ResourceGroups.Types.QueryError where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(QueryError -> QueryError -> Bool)
-> (QueryError -> QueryError -> Bool) -> Eq QueryError
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]
(Int -> ReadS QueryError)
-> ReadS [QueryError]
-> ReadPrec QueryError
-> ReadPrec [QueryError]
-> Read 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
(Int -> QueryError -> ShowS)
-> (QueryError -> String)
-> ([QueryError] -> ShowS)
-> Show QueryError
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. QueryError -> Rep QueryError x)
-> (forall x. Rep QueryError x -> QueryError) -> Generic QueryError
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' :: Maybe QueryErrorCode -> Maybe Text -> QueryError
QueryError'
    { $sel:errorCode:QueryError' :: Maybe QueryErrorCode
errorCode = Maybe QueryErrorCode
forall a. Maybe a
Prelude.Nothing,
      $sel:message:QueryError' :: Maybe Text
message = Maybe Text
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 :: (Maybe QueryErrorCode -> f (Maybe QueryErrorCode))
-> QueryError -> f QueryError
queryError_errorCode = (QueryError -> Maybe QueryErrorCode)
-> (QueryError -> Maybe QueryErrorCode -> QueryError)
-> Lens
     QueryError QueryError (Maybe QueryErrorCode) (Maybe QueryErrorCode)
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 :: (Maybe Text -> f (Maybe Text)) -> QueryError -> f QueryError
queryError_message = (QueryError -> Maybe Text)
-> (QueryError -> Maybe Text -> QueryError)
-> Lens QueryError QueryError (Maybe Text) (Maybe Text)
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 Core.FromJSON QueryError where
  parseJSON :: Value -> Parser QueryError
parseJSON =
    String
-> (Object -> Parser QueryError) -> Value -> Parser QueryError
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"QueryError"
      ( \Object
x ->
          Maybe QueryErrorCode -> Maybe Text -> QueryError
QueryError'
            (Maybe QueryErrorCode -> Maybe Text -> QueryError)
-> Parser (Maybe QueryErrorCode)
-> Parser (Maybe Text -> QueryError)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe QueryErrorCode)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ErrorCode")
            Parser (Maybe Text -> QueryError)
-> Parser (Maybe Text) -> Parser QueryError
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
"Message")
      )

instance Prelude.Hashable QueryError

instance Prelude.NFData QueryError