{-# 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.ECS.Types.Failure
-- 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.ECS.Types.Failure 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

-- | A failed resource. For a list of common causes, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/api_failures_messages.html API failure reasons>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- /See:/ 'newFailure' smart constructor.
data Failure = Failure'
  { -- | The Amazon Resource Name (ARN) of the failed resource.
    Failure -> Maybe Text
arn :: Prelude.Maybe Prelude.Text,
    -- | The details of the failure.
    Failure -> Maybe Text
detail :: Prelude.Maybe Prelude.Text,
    -- | The reason for the failure.
    Failure -> Maybe Text
reason :: Prelude.Maybe Prelude.Text
  }
  deriving (Failure -> Failure -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Failure -> Failure -> Bool
$c/= :: Failure -> Failure -> Bool
== :: Failure -> Failure -> Bool
$c== :: Failure -> Failure -> Bool
Prelude.Eq, ReadPrec [Failure]
ReadPrec Failure
Int -> ReadS Failure
ReadS [Failure]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Failure]
$creadListPrec :: ReadPrec [Failure]
readPrec :: ReadPrec Failure
$creadPrec :: ReadPrec Failure
readList :: ReadS [Failure]
$creadList :: ReadS [Failure]
readsPrec :: Int -> ReadS Failure
$creadsPrec :: Int -> ReadS Failure
Prelude.Read, Int -> Failure -> ShowS
[Failure] -> ShowS
Failure -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Failure] -> ShowS
$cshowList :: [Failure] -> ShowS
show :: Failure -> String
$cshow :: Failure -> String
showsPrec :: Int -> Failure -> ShowS
$cshowsPrec :: Int -> Failure -> ShowS
Prelude.Show, forall x. Rep Failure x -> Failure
forall x. Failure -> Rep Failure x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Failure x -> Failure
$cfrom :: forall x. Failure -> Rep Failure x
Prelude.Generic)

-- |
-- Create a value of 'Failure' 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:
--
-- 'arn', 'failure_arn' - The Amazon Resource Name (ARN) of the failed resource.
--
-- 'detail', 'failure_detail' - The details of the failure.
--
-- 'reason', 'failure_reason' - The reason for the failure.
newFailure ::
  Failure
newFailure :: Failure
newFailure =
  Failure'
    { $sel:arn:Failure' :: Maybe Text
arn = forall a. Maybe a
Prelude.Nothing,
      $sel:detail:Failure' :: Maybe Text
detail = forall a. Maybe a
Prelude.Nothing,
      $sel:reason:Failure' :: Maybe Text
reason = forall a. Maybe a
Prelude.Nothing
    }

-- | The Amazon Resource Name (ARN) of the failed resource.
failure_arn :: Lens.Lens' Failure (Prelude.Maybe Prelude.Text)
failure_arn :: Lens' Failure (Maybe Text)
failure_arn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Failure' {Maybe Text
arn :: Maybe Text
$sel:arn:Failure' :: Failure -> Maybe Text
arn} -> Maybe Text
arn) (\s :: Failure
s@Failure' {} Maybe Text
a -> Failure
s {$sel:arn:Failure' :: Maybe Text
arn = Maybe Text
a} :: Failure)

-- | The details of the failure.
failure_detail :: Lens.Lens' Failure (Prelude.Maybe Prelude.Text)
failure_detail :: Lens' Failure (Maybe Text)
failure_detail = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Failure' {Maybe Text
detail :: Maybe Text
$sel:detail:Failure' :: Failure -> Maybe Text
detail} -> Maybe Text
detail) (\s :: Failure
s@Failure' {} Maybe Text
a -> Failure
s {$sel:detail:Failure' :: Maybe Text
detail = Maybe Text
a} :: Failure)

-- | The reason for the failure.
failure_reason :: Lens.Lens' Failure (Prelude.Maybe Prelude.Text)
failure_reason :: Lens' Failure (Maybe Text)
failure_reason = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Failure' {Maybe Text
reason :: Maybe Text
$sel:reason:Failure' :: Failure -> Maybe Text
reason} -> Maybe Text
reason) (\s :: Failure
s@Failure' {} Maybe Text
a -> Failure
s {$sel:reason:Failure' :: Maybe Text
reason = Maybe Text
a} :: Failure)

instance Data.FromJSON Failure where
  parseJSON :: Value -> Parser Failure
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Failure"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Maybe Text -> Failure
Failure'
            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
"arn")
            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
"detail")
            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
"reason")
      )

instance Prelude.Hashable Failure where
  hashWithSalt :: Int -> Failure -> Int
hashWithSalt Int
_salt Failure' {Maybe Text
reason :: Maybe Text
detail :: Maybe Text
arn :: Maybe Text
$sel:reason:Failure' :: Failure -> Maybe Text
$sel:detail:Failure' :: Failure -> Maybe Text
$sel:arn:Failure' :: Failure -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
arn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
detail
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
reason

instance Prelude.NFData Failure where
  rnf :: Failure -> ()
rnf Failure' {Maybe Text
reason :: Maybe Text
detail :: Maybe Text
arn :: Maybe Text
$sel:reason:Failure' :: Failure -> Maybe Text
$sel:detail:Failure' :: Failure -> Maybe Text
$sel:arn:Failure' :: Failure -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
arn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
detail
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
reason