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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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 reason for the failure.
    Failure -> Maybe Text
reason :: Prelude.Maybe Prelude.Text,
    -- | The details of the failure.
    Failure -> Maybe Text
detail :: Prelude.Maybe Prelude.Text
  }
  deriving (Failure -> Failure -> Bool
(Failure -> Failure -> Bool)
-> (Failure -> Failure -> Bool) -> Eq Failure
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]
(Int -> ReadS Failure)
-> ReadS [Failure]
-> ReadPrec Failure
-> ReadPrec [Failure]
-> Read 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
(Int -> Failure -> ShowS)
-> (Failure -> String) -> ([Failure] -> ShowS) -> Show Failure
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. Failure -> Rep Failure x)
-> (forall x. Rep Failure x -> Failure) -> Generic Failure
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.
--
-- 'reason', 'failure_reason' - The reason for the failure.
--
-- 'detail', 'failure_detail' - The details of the failure.
newFailure ::
  Failure
newFailure :: Failure
newFailure =
  Failure' :: Maybe Text -> Maybe Text -> Maybe Text -> Failure
Failure'
    { $sel:arn:Failure' :: Maybe Text
arn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:reason:Failure' :: Maybe Text
reason = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:detail:Failure' :: Maybe Text
detail = Maybe Text
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 :: (Maybe Text -> f (Maybe Text)) -> Failure -> f Failure
failure_arn = (Failure -> Maybe Text)
-> (Failure -> Maybe Text -> Failure)
-> Lens Failure Failure (Maybe Text) (Maybe Text)
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 reason for the failure.
failure_reason :: Lens.Lens' Failure (Prelude.Maybe Prelude.Text)
failure_reason :: (Maybe Text -> f (Maybe Text)) -> Failure -> f Failure
failure_reason = (Failure -> Maybe Text)
-> (Failure -> Maybe Text -> Failure)
-> Lens Failure Failure (Maybe Text) (Maybe Text)
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)

-- | The details of the failure.
failure_detail :: Lens.Lens' Failure (Prelude.Maybe Prelude.Text)
failure_detail :: (Maybe Text -> f (Maybe Text)) -> Failure -> f Failure
failure_detail = (Failure -> Maybe Text)
-> (Failure -> Maybe Text -> Failure)
-> Lens Failure Failure (Maybe Text) (Maybe Text)
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)

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

instance Prelude.Hashable Failure

instance Prelude.NFData Failure