{-# 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.AppSync.Types.CodeError
-- 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.AppSync.Types.CodeError where

import Amazonka.AppSync.Types.CodeErrorLocation
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

-- | Describes an AppSync error.
--
-- /See:/ 'newCodeError' smart constructor.
data CodeError = CodeError'
  { -- | The type of code error.
    --
    -- Examples include, but aren\'t limited to: @LINT_ERROR@, @PARSER_ERROR@.
    CodeError -> Maybe Text
errorType :: Prelude.Maybe Prelude.Text,
    -- | The line, column, and span location of the error in the code.
    CodeError -> Maybe CodeErrorLocation
location :: Prelude.Maybe CodeErrorLocation,
    -- | A user presentable error.
    --
    -- Examples include, but aren\'t limited to:
    -- @Parsing error: Unterminated string literal@.
    CodeError -> Maybe Text
value :: Prelude.Maybe Prelude.Text
  }
  deriving (CodeError -> CodeError -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CodeError -> CodeError -> Bool
$c/= :: CodeError -> CodeError -> Bool
== :: CodeError -> CodeError -> Bool
$c== :: CodeError -> CodeError -> Bool
Prelude.Eq, ReadPrec [CodeError]
ReadPrec CodeError
Int -> ReadS CodeError
ReadS [CodeError]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CodeError]
$creadListPrec :: ReadPrec [CodeError]
readPrec :: ReadPrec CodeError
$creadPrec :: ReadPrec CodeError
readList :: ReadS [CodeError]
$creadList :: ReadS [CodeError]
readsPrec :: Int -> ReadS CodeError
$creadsPrec :: Int -> ReadS CodeError
Prelude.Read, Int -> CodeError -> ShowS
[CodeError] -> ShowS
CodeError -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CodeError] -> ShowS
$cshowList :: [CodeError] -> ShowS
show :: CodeError -> String
$cshow :: CodeError -> String
showsPrec :: Int -> CodeError -> ShowS
$cshowsPrec :: Int -> CodeError -> ShowS
Prelude.Show, forall x. Rep CodeError x -> CodeError
forall x. CodeError -> Rep CodeError x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CodeError x -> CodeError
$cfrom :: forall x. CodeError -> Rep CodeError x
Prelude.Generic)

-- |
-- Create a value of 'CodeError' 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:
--
-- 'errorType', 'codeError_errorType' - The type of code error.
--
-- Examples include, but aren\'t limited to: @LINT_ERROR@, @PARSER_ERROR@.
--
-- 'location', 'codeError_location' - The line, column, and span location of the error in the code.
--
-- 'value', 'codeError_value' - A user presentable error.
--
-- Examples include, but aren\'t limited to:
-- @Parsing error: Unterminated string literal@.
newCodeError ::
  CodeError
newCodeError :: CodeError
newCodeError =
  CodeError'
    { $sel:errorType:CodeError' :: Maybe Text
errorType = forall a. Maybe a
Prelude.Nothing,
      $sel:location:CodeError' :: Maybe CodeErrorLocation
location = forall a. Maybe a
Prelude.Nothing,
      $sel:value:CodeError' :: Maybe Text
value = forall a. Maybe a
Prelude.Nothing
    }

-- | The type of code error.
--
-- Examples include, but aren\'t limited to: @LINT_ERROR@, @PARSER_ERROR@.
codeError_errorType :: Lens.Lens' CodeError (Prelude.Maybe Prelude.Text)
codeError_errorType :: Lens' CodeError (Maybe Text)
codeError_errorType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CodeError' {Maybe Text
errorType :: Maybe Text
$sel:errorType:CodeError' :: CodeError -> Maybe Text
errorType} -> Maybe Text
errorType) (\s :: CodeError
s@CodeError' {} Maybe Text
a -> CodeError
s {$sel:errorType:CodeError' :: Maybe Text
errorType = Maybe Text
a} :: CodeError)

-- | The line, column, and span location of the error in the code.
codeError_location :: Lens.Lens' CodeError (Prelude.Maybe CodeErrorLocation)
codeError_location :: Lens' CodeError (Maybe CodeErrorLocation)
codeError_location = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CodeError' {Maybe CodeErrorLocation
location :: Maybe CodeErrorLocation
$sel:location:CodeError' :: CodeError -> Maybe CodeErrorLocation
location} -> Maybe CodeErrorLocation
location) (\s :: CodeError
s@CodeError' {} Maybe CodeErrorLocation
a -> CodeError
s {$sel:location:CodeError' :: Maybe CodeErrorLocation
location = Maybe CodeErrorLocation
a} :: CodeError)

-- | A user presentable error.
--
-- Examples include, but aren\'t limited to:
-- @Parsing error: Unterminated string literal@.
codeError_value :: Lens.Lens' CodeError (Prelude.Maybe Prelude.Text)
codeError_value :: Lens' CodeError (Maybe Text)
codeError_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CodeError' {Maybe Text
value :: Maybe Text
$sel:value:CodeError' :: CodeError -> Maybe Text
value} -> Maybe Text
value) (\s :: CodeError
s@CodeError' {} Maybe Text
a -> CodeError
s {$sel:value:CodeError' :: Maybe Text
value = Maybe Text
a} :: CodeError)

instance Data.FromJSON CodeError where
  parseJSON :: Value -> Parser CodeError
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CodeError"
      ( \Object
x ->
          Maybe Text -> Maybe CodeErrorLocation -> Maybe Text -> CodeError
CodeError'
            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
"errorType")
            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
"location")
            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
"value")
      )

instance Prelude.Hashable CodeError where
  hashWithSalt :: Int -> CodeError -> Int
hashWithSalt Int
_salt CodeError' {Maybe Text
Maybe CodeErrorLocation
value :: Maybe Text
location :: Maybe CodeErrorLocation
errorType :: Maybe Text
$sel:value:CodeError' :: CodeError -> Maybe Text
$sel:location:CodeError' :: CodeError -> Maybe CodeErrorLocation
$sel:errorType:CodeError' :: CodeError -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
errorType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CodeErrorLocation
location
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
value

instance Prelude.NFData CodeError where
  rnf :: CodeError -> ()
rnf CodeError' {Maybe Text
Maybe CodeErrorLocation
value :: Maybe Text
location :: Maybe CodeErrorLocation
errorType :: Maybe Text
$sel:value:CodeError' :: CodeError -> Maybe Text
$sel:location:CodeError' :: CodeError -> Maybe CodeErrorLocation
$sel:errorType:CodeError' :: CodeError -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
errorType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe CodeErrorLocation
location
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
value