{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.PutDashboard
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a dashboard if it does not already exist, or updates an existing
-- dashboard. If you update a dashboard, the entire contents are replaced
-- with what you specify here.
--
-- All dashboards in your account are global, not region-specific.
--
-- A simple way to create a dashboard using @PutDashboard@ is to copy an
-- existing dashboard. To copy an existing dashboard using the console, you
-- can load the dashboard and then use the View\/edit source command in the
-- Actions menu to display the JSON block for that dashboard. Another way
-- to copy a dashboard is to use @GetDashboard@, and then use the data
-- returned within @DashboardBody@ as the template for the new dashboard
-- when you call @PutDashboard@.
--
-- When you create a dashboard with @PutDashboard@, a good practice is to
-- add a text widget at the top of the dashboard with a message that the
-- dashboard was created by script and should not be changed in the
-- console. This message could also point console users to the location of
-- the @DashboardBody@ script or the CloudFormation template used to create
-- the dashboard.
module Amazonka.CloudWatch.PutDashboard
  ( -- * Creating a Request
    PutDashboard (..),
    newPutDashboard,

    -- * Request Lenses
    putDashboard_dashboardName,
    putDashboard_dashboardBody,

    -- * Destructuring the Response
    PutDashboardResponse (..),
    newPutDashboardResponse,

    -- * Response Lenses
    putDashboardResponse_dashboardValidationMessages,
    putDashboardResponse_httpStatus,
  )
where

import Amazonka.CloudWatch.Types
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
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newPutDashboard' smart constructor.
data PutDashboard = PutDashboard'
  { -- | The name of the dashboard. If a dashboard with this name already exists,
    -- this call modifies that dashboard, replacing its current contents.
    -- Otherwise, a new dashboard is created. The maximum length is 255, and
    -- valid characters are A-Z, a-z, 0-9, \"-\", and \"_\". This parameter is
    -- required.
    PutDashboard -> Text
dashboardName :: Prelude.Text,
    -- | The detailed information about the dashboard in JSON format, including
    -- the widgets to include and their location on the dashboard. This
    -- parameter is required.
    --
    -- For more information about the syntax, see
    -- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/CloudWatch-Dashboard-Body-Structure.html Dashboard Body Structure and Syntax>.
    PutDashboard -> Text
dashboardBody :: Prelude.Text
  }
  deriving (PutDashboard -> PutDashboard -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutDashboard -> PutDashboard -> Bool
$c/= :: PutDashboard -> PutDashboard -> Bool
== :: PutDashboard -> PutDashboard -> Bool
$c== :: PutDashboard -> PutDashboard -> Bool
Prelude.Eq, ReadPrec [PutDashboard]
ReadPrec PutDashboard
Int -> ReadS PutDashboard
ReadS [PutDashboard]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutDashboard]
$creadListPrec :: ReadPrec [PutDashboard]
readPrec :: ReadPrec PutDashboard
$creadPrec :: ReadPrec PutDashboard
readList :: ReadS [PutDashboard]
$creadList :: ReadS [PutDashboard]
readsPrec :: Int -> ReadS PutDashboard
$creadsPrec :: Int -> ReadS PutDashboard
Prelude.Read, Int -> PutDashboard -> ShowS
[PutDashboard] -> ShowS
PutDashboard -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutDashboard] -> ShowS
$cshowList :: [PutDashboard] -> ShowS
show :: PutDashboard -> String
$cshow :: PutDashboard -> String
showsPrec :: Int -> PutDashboard -> ShowS
$cshowsPrec :: Int -> PutDashboard -> ShowS
Prelude.Show, forall x. Rep PutDashboard x -> PutDashboard
forall x. PutDashboard -> Rep PutDashboard x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutDashboard x -> PutDashboard
$cfrom :: forall x. PutDashboard -> Rep PutDashboard x
Prelude.Generic)

-- |
-- Create a value of 'PutDashboard' 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:
--
-- 'dashboardName', 'putDashboard_dashboardName' - The name of the dashboard. If a dashboard with this name already exists,
-- this call modifies that dashboard, replacing its current contents.
-- Otherwise, a new dashboard is created. The maximum length is 255, and
-- valid characters are A-Z, a-z, 0-9, \"-\", and \"_\". This parameter is
-- required.
--
-- 'dashboardBody', 'putDashboard_dashboardBody' - The detailed information about the dashboard in JSON format, including
-- the widgets to include and their location on the dashboard. This
-- parameter is required.
--
-- For more information about the syntax, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/CloudWatch-Dashboard-Body-Structure.html Dashboard Body Structure and Syntax>.
newPutDashboard ::
  -- | 'dashboardName'
  Prelude.Text ->
  -- | 'dashboardBody'
  Prelude.Text ->
  PutDashboard
newPutDashboard :: Text -> Text -> PutDashboard
newPutDashboard Text
pDashboardName_ Text
pDashboardBody_ =
  PutDashboard'
    { $sel:dashboardName:PutDashboard' :: Text
dashboardName = Text
pDashboardName_,
      $sel:dashboardBody:PutDashboard' :: Text
dashboardBody = Text
pDashboardBody_
    }

-- | The name of the dashboard. If a dashboard with this name already exists,
-- this call modifies that dashboard, replacing its current contents.
-- Otherwise, a new dashboard is created. The maximum length is 255, and
-- valid characters are A-Z, a-z, 0-9, \"-\", and \"_\". This parameter is
-- required.
putDashboard_dashboardName :: Lens.Lens' PutDashboard Prelude.Text
putDashboard_dashboardName :: Lens' PutDashboard Text
putDashboard_dashboardName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutDashboard' {Text
dashboardName :: Text
$sel:dashboardName:PutDashboard' :: PutDashboard -> Text
dashboardName} -> Text
dashboardName) (\s :: PutDashboard
s@PutDashboard' {} Text
a -> PutDashboard
s {$sel:dashboardName:PutDashboard' :: Text
dashboardName = Text
a} :: PutDashboard)

-- | The detailed information about the dashboard in JSON format, including
-- the widgets to include and their location on the dashboard. This
-- parameter is required.
--
-- For more information about the syntax, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/CloudWatch-Dashboard-Body-Structure.html Dashboard Body Structure and Syntax>.
putDashboard_dashboardBody :: Lens.Lens' PutDashboard Prelude.Text
putDashboard_dashboardBody :: Lens' PutDashboard Text
putDashboard_dashboardBody = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutDashboard' {Text
dashboardBody :: Text
$sel:dashboardBody:PutDashboard' :: PutDashboard -> Text
dashboardBody} -> Text
dashboardBody) (\s :: PutDashboard
s@PutDashboard' {} Text
a -> PutDashboard
s {$sel:dashboardBody:PutDashboard' :: Text
dashboardBody = Text
a} :: PutDashboard)

instance Core.AWSRequest PutDashboard where
  type AWSResponse PutDashboard = PutDashboardResponse
  request :: (Service -> Service) -> PutDashboard -> Request PutDashboard
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.postQuery (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy PutDashboard
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutDashboard)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"PutDashboardResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe [DashboardValidationMessage] -> Int -> PutDashboardResponse
PutDashboardResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x
                            forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"DashboardValidationMessages"
                            forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                            forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"member")
                        )
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable PutDashboard where
  hashWithSalt :: Int -> PutDashboard -> Int
hashWithSalt Int
_salt PutDashboard' {Text
dashboardBody :: Text
dashboardName :: Text
$sel:dashboardBody:PutDashboard' :: PutDashboard -> Text
$sel:dashboardName:PutDashboard' :: PutDashboard -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
dashboardName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
dashboardBody

instance Prelude.NFData PutDashboard where
  rnf :: PutDashboard -> ()
rnf PutDashboard' {Text
dashboardBody :: Text
dashboardName :: Text
$sel:dashboardBody:PutDashboard' :: PutDashboard -> Text
$sel:dashboardName:PutDashboard' :: PutDashboard -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
dashboardName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
dashboardBody

instance Data.ToHeaders PutDashboard where
  toHeaders :: PutDashboard -> ResponseHeaders
toHeaders = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

instance Data.ToPath PutDashboard where
  toPath :: PutDashboard -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Data.ToQuery PutDashboard where
  toQuery :: PutDashboard -> QueryString
toQuery PutDashboard' {Text
dashboardBody :: Text
dashboardName :: Text
$sel:dashboardBody:PutDashboard' :: PutDashboard -> Text
$sel:dashboardName:PutDashboard' :: PutDashboard -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"PutDashboard" :: Prelude.ByteString),
        ByteString
"Version"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"2010-08-01" :: Prelude.ByteString),
        ByteString
"DashboardName" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
dashboardName,
        ByteString
"DashboardBody" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
dashboardBody
      ]

-- | /See:/ 'newPutDashboardResponse' smart constructor.
data PutDashboardResponse = PutDashboardResponse'
  { -- | If the input for @PutDashboard@ was correct and the dashboard was
    -- successfully created or modified, this result is empty.
    --
    -- If this result includes only warning messages, then the input was valid
    -- enough for the dashboard to be created or modified, but some elements of
    -- the dashboard might not render.
    --
    -- If this result includes error messages, the input was not valid and the
    -- operation failed.
    PutDashboardResponse -> Maybe [DashboardValidationMessage]
dashboardValidationMessages :: Prelude.Maybe [DashboardValidationMessage],
    -- | The response's http status code.
    PutDashboardResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (PutDashboardResponse -> PutDashboardResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutDashboardResponse -> PutDashboardResponse -> Bool
$c/= :: PutDashboardResponse -> PutDashboardResponse -> Bool
== :: PutDashboardResponse -> PutDashboardResponse -> Bool
$c== :: PutDashboardResponse -> PutDashboardResponse -> Bool
Prelude.Eq, ReadPrec [PutDashboardResponse]
ReadPrec PutDashboardResponse
Int -> ReadS PutDashboardResponse
ReadS [PutDashboardResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutDashboardResponse]
$creadListPrec :: ReadPrec [PutDashboardResponse]
readPrec :: ReadPrec PutDashboardResponse
$creadPrec :: ReadPrec PutDashboardResponse
readList :: ReadS [PutDashboardResponse]
$creadList :: ReadS [PutDashboardResponse]
readsPrec :: Int -> ReadS PutDashboardResponse
$creadsPrec :: Int -> ReadS PutDashboardResponse
Prelude.Read, Int -> PutDashboardResponse -> ShowS
[PutDashboardResponse] -> ShowS
PutDashboardResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutDashboardResponse] -> ShowS
$cshowList :: [PutDashboardResponse] -> ShowS
show :: PutDashboardResponse -> String
$cshow :: PutDashboardResponse -> String
showsPrec :: Int -> PutDashboardResponse -> ShowS
$cshowsPrec :: Int -> PutDashboardResponse -> ShowS
Prelude.Show, forall x. Rep PutDashboardResponse x -> PutDashboardResponse
forall x. PutDashboardResponse -> Rep PutDashboardResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutDashboardResponse x -> PutDashboardResponse
$cfrom :: forall x. PutDashboardResponse -> Rep PutDashboardResponse x
Prelude.Generic)

-- |
-- Create a value of 'PutDashboardResponse' 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:
--
-- 'dashboardValidationMessages', 'putDashboardResponse_dashboardValidationMessages' - If the input for @PutDashboard@ was correct and the dashboard was
-- successfully created or modified, this result is empty.
--
-- If this result includes only warning messages, then the input was valid
-- enough for the dashboard to be created or modified, but some elements of
-- the dashboard might not render.
--
-- If this result includes error messages, the input was not valid and the
-- operation failed.
--
-- 'httpStatus', 'putDashboardResponse_httpStatus' - The response's http status code.
newPutDashboardResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutDashboardResponse
newPutDashboardResponse :: Int -> PutDashboardResponse
newPutDashboardResponse Int
pHttpStatus_ =
  PutDashboardResponse'
    { $sel:dashboardValidationMessages:PutDashboardResponse' :: Maybe [DashboardValidationMessage]
dashboardValidationMessages =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PutDashboardResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | If the input for @PutDashboard@ was correct and the dashboard was
-- successfully created or modified, this result is empty.
--
-- If this result includes only warning messages, then the input was valid
-- enough for the dashboard to be created or modified, but some elements of
-- the dashboard might not render.
--
-- If this result includes error messages, the input was not valid and the
-- operation failed.
putDashboardResponse_dashboardValidationMessages :: Lens.Lens' PutDashboardResponse (Prelude.Maybe [DashboardValidationMessage])
putDashboardResponse_dashboardValidationMessages :: Lens' PutDashboardResponse (Maybe [DashboardValidationMessage])
putDashboardResponse_dashboardValidationMessages = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutDashboardResponse' {Maybe [DashboardValidationMessage]
dashboardValidationMessages :: Maybe [DashboardValidationMessage]
$sel:dashboardValidationMessages:PutDashboardResponse' :: PutDashboardResponse -> Maybe [DashboardValidationMessage]
dashboardValidationMessages} -> Maybe [DashboardValidationMessage]
dashboardValidationMessages) (\s :: PutDashboardResponse
s@PutDashboardResponse' {} Maybe [DashboardValidationMessage]
a -> PutDashboardResponse
s {$sel:dashboardValidationMessages:PutDashboardResponse' :: Maybe [DashboardValidationMessage]
dashboardValidationMessages = Maybe [DashboardValidationMessage]
a} :: PutDashboardResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The response's http status code.
putDashboardResponse_httpStatus :: Lens.Lens' PutDashboardResponse Prelude.Int
putDashboardResponse_httpStatus :: Lens' PutDashboardResponse Int
putDashboardResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutDashboardResponse' {Int
httpStatus :: Int
$sel:httpStatus:PutDashboardResponse' :: PutDashboardResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: PutDashboardResponse
s@PutDashboardResponse' {} Int
a -> PutDashboardResponse
s {$sel:httpStatus:PutDashboardResponse' :: Int
httpStatus = Int
a} :: PutDashboardResponse)

instance Prelude.NFData PutDashboardResponse where
  rnf :: PutDashboardResponse -> ()
rnf PutDashboardResponse' {Int
Maybe [DashboardValidationMessage]
httpStatus :: Int
dashboardValidationMessages :: Maybe [DashboardValidationMessage]
$sel:httpStatus:PutDashboardResponse' :: PutDashboardResponse -> Int
$sel:dashboardValidationMessages:PutDashboardResponse' :: PutDashboardResponse -> Maybe [DashboardValidationMessage]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [DashboardValidationMessage]
dashboardValidationMessages
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus