{-# 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.CloudWatch.Types.MessageData
-- 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.CloudWatch.Types.MessageData where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A message returned by the @GetMetricData@API, including a code and a
-- description.
--
-- If a cross-Region @GetMetricData@ operation fails with a code of
-- @Forbidden@ and a value of
-- @Authentication too complex to retrieve cross region data@, you can
-- correct the problem by running the @GetMetricData@ operation in the same
-- Region where the metric data is.
--
-- /See:/ 'newMessageData' smart constructor.
data MessageData = MessageData'
  { -- | The message text.
    MessageData -> Maybe Text
value :: Prelude.Maybe Prelude.Text,
    -- | The error code or status code associated with the message.
    MessageData -> Maybe Text
code :: Prelude.Maybe Prelude.Text
  }
  deriving (MessageData -> MessageData -> Bool
(MessageData -> MessageData -> Bool)
-> (MessageData -> MessageData -> Bool) -> Eq MessageData
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MessageData -> MessageData -> Bool
$c/= :: MessageData -> MessageData -> Bool
== :: MessageData -> MessageData -> Bool
$c== :: MessageData -> MessageData -> Bool
Prelude.Eq, ReadPrec [MessageData]
ReadPrec MessageData
Int -> ReadS MessageData
ReadS [MessageData]
(Int -> ReadS MessageData)
-> ReadS [MessageData]
-> ReadPrec MessageData
-> ReadPrec [MessageData]
-> Read MessageData
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MessageData]
$creadListPrec :: ReadPrec [MessageData]
readPrec :: ReadPrec MessageData
$creadPrec :: ReadPrec MessageData
readList :: ReadS [MessageData]
$creadList :: ReadS [MessageData]
readsPrec :: Int -> ReadS MessageData
$creadsPrec :: Int -> ReadS MessageData
Prelude.Read, Int -> MessageData -> ShowS
[MessageData] -> ShowS
MessageData -> String
(Int -> MessageData -> ShowS)
-> (MessageData -> String)
-> ([MessageData] -> ShowS)
-> Show MessageData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MessageData] -> ShowS
$cshowList :: [MessageData] -> ShowS
show :: MessageData -> String
$cshow :: MessageData -> String
showsPrec :: Int -> MessageData -> ShowS
$cshowsPrec :: Int -> MessageData -> ShowS
Prelude.Show, (forall x. MessageData -> Rep MessageData x)
-> (forall x. Rep MessageData x -> MessageData)
-> Generic MessageData
forall x. Rep MessageData x -> MessageData
forall x. MessageData -> Rep MessageData x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MessageData x -> MessageData
$cfrom :: forall x. MessageData -> Rep MessageData x
Prelude.Generic)

-- |
-- Create a value of 'MessageData' 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:
--
-- 'value', 'messageData_value' - The message text.
--
-- 'code', 'messageData_code' - The error code or status code associated with the message.
newMessageData ::
  MessageData
newMessageData :: MessageData
newMessageData =
  MessageData' :: Maybe Text -> Maybe Text -> MessageData
MessageData'
    { $sel:value:MessageData' :: Maybe Text
value = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:code:MessageData' :: Maybe Text
code = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The message text.
messageData_value :: Lens.Lens' MessageData (Prelude.Maybe Prelude.Text)
messageData_value :: (Maybe Text -> f (Maybe Text)) -> MessageData -> f MessageData
messageData_value = (MessageData -> Maybe Text)
-> (MessageData -> Maybe Text -> MessageData)
-> Lens MessageData MessageData (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MessageData' {Maybe Text
value :: Maybe Text
$sel:value:MessageData' :: MessageData -> Maybe Text
value} -> Maybe Text
value) (\s :: MessageData
s@MessageData' {} Maybe Text
a -> MessageData
s {$sel:value:MessageData' :: Maybe Text
value = Maybe Text
a} :: MessageData)

-- | The error code or status code associated with the message.
messageData_code :: Lens.Lens' MessageData (Prelude.Maybe Prelude.Text)
messageData_code :: (Maybe Text -> f (Maybe Text)) -> MessageData -> f MessageData
messageData_code = (MessageData -> Maybe Text)
-> (MessageData -> Maybe Text -> MessageData)
-> Lens MessageData MessageData (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MessageData' {Maybe Text
code :: Maybe Text
$sel:code:MessageData' :: MessageData -> Maybe Text
code} -> Maybe Text
code) (\s :: MessageData
s@MessageData' {} Maybe Text
a -> MessageData
s {$sel:code:MessageData' :: Maybe Text
code = Maybe Text
a} :: MessageData)

instance Core.FromXML MessageData where
  parseXML :: [Node] -> Either String MessageData
parseXML [Node]
x =
    Maybe Text -> Maybe Text -> MessageData
MessageData'
      (Maybe Text -> Maybe Text -> MessageData)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> MessageData)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Value") Either String (Maybe Text -> MessageData)
-> Either String (Maybe Text) -> Either String MessageData
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Code")

instance Prelude.Hashable MessageData

instance Prelude.NFData MessageData