{-# 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.AppConfig.UpdateEnvironment
-- 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)
--
-- Updates an environment.
module Amazonka.AppConfig.UpdateEnvironment
  ( -- * Creating a Request
    UpdateEnvironment (..),
    newUpdateEnvironment,

    -- * Request Lenses
    updateEnvironment_monitors,
    updateEnvironment_name,
    updateEnvironment_description,
    updateEnvironment_applicationId,
    updateEnvironment_environmentId,

    -- * Destructuring the Response
    Environment (..),
    newEnvironment,

    -- * Response Lenses
    environment_state,
    environment_monitors,
    environment_applicationId,
    environment_name,
    environment_id,
    environment_description,
  )
where

import Amazonka.AppConfig.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newUpdateEnvironment' smart constructor.
data UpdateEnvironment = UpdateEnvironment'
  { -- | Amazon CloudWatch alarms to monitor during the deployment process.
    UpdateEnvironment -> Maybe [Monitor]
monitors :: Prelude.Maybe [Monitor],
    -- | The name of the environment.
    UpdateEnvironment -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | A description of the environment.
    UpdateEnvironment -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The application ID.
    UpdateEnvironment -> Text
applicationId :: Prelude.Text,
    -- | The environment ID.
    UpdateEnvironment -> Text
environmentId :: Prelude.Text
  }
  deriving (UpdateEnvironment -> UpdateEnvironment -> Bool
(UpdateEnvironment -> UpdateEnvironment -> Bool)
-> (UpdateEnvironment -> UpdateEnvironment -> Bool)
-> Eq UpdateEnvironment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateEnvironment -> UpdateEnvironment -> Bool
$c/= :: UpdateEnvironment -> UpdateEnvironment -> Bool
== :: UpdateEnvironment -> UpdateEnvironment -> Bool
$c== :: UpdateEnvironment -> UpdateEnvironment -> Bool
Prelude.Eq, ReadPrec [UpdateEnvironment]
ReadPrec UpdateEnvironment
Int -> ReadS UpdateEnvironment
ReadS [UpdateEnvironment]
(Int -> ReadS UpdateEnvironment)
-> ReadS [UpdateEnvironment]
-> ReadPrec UpdateEnvironment
-> ReadPrec [UpdateEnvironment]
-> Read UpdateEnvironment
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateEnvironment]
$creadListPrec :: ReadPrec [UpdateEnvironment]
readPrec :: ReadPrec UpdateEnvironment
$creadPrec :: ReadPrec UpdateEnvironment
readList :: ReadS [UpdateEnvironment]
$creadList :: ReadS [UpdateEnvironment]
readsPrec :: Int -> ReadS UpdateEnvironment
$creadsPrec :: Int -> ReadS UpdateEnvironment
Prelude.Read, Int -> UpdateEnvironment -> ShowS
[UpdateEnvironment] -> ShowS
UpdateEnvironment -> String
(Int -> UpdateEnvironment -> ShowS)
-> (UpdateEnvironment -> String)
-> ([UpdateEnvironment] -> ShowS)
-> Show UpdateEnvironment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateEnvironment] -> ShowS
$cshowList :: [UpdateEnvironment] -> ShowS
show :: UpdateEnvironment -> String
$cshow :: UpdateEnvironment -> String
showsPrec :: Int -> UpdateEnvironment -> ShowS
$cshowsPrec :: Int -> UpdateEnvironment -> ShowS
Prelude.Show, (forall x. UpdateEnvironment -> Rep UpdateEnvironment x)
-> (forall x. Rep UpdateEnvironment x -> UpdateEnvironment)
-> Generic UpdateEnvironment
forall x. Rep UpdateEnvironment x -> UpdateEnvironment
forall x. UpdateEnvironment -> Rep UpdateEnvironment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateEnvironment x -> UpdateEnvironment
$cfrom :: forall x. UpdateEnvironment -> Rep UpdateEnvironment x
Prelude.Generic)

-- |
-- Create a value of 'UpdateEnvironment' 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:
--
-- 'monitors', 'updateEnvironment_monitors' - Amazon CloudWatch alarms to monitor during the deployment process.
--
-- 'name', 'updateEnvironment_name' - The name of the environment.
--
-- 'description', 'updateEnvironment_description' - A description of the environment.
--
-- 'applicationId', 'updateEnvironment_applicationId' - The application ID.
--
-- 'environmentId', 'updateEnvironment_environmentId' - The environment ID.
newUpdateEnvironment ::
  -- | 'applicationId'
  Prelude.Text ->
  -- | 'environmentId'
  Prelude.Text ->
  UpdateEnvironment
newUpdateEnvironment :: Text -> Text -> UpdateEnvironment
newUpdateEnvironment Text
pApplicationId_ Text
pEnvironmentId_ =
  UpdateEnvironment' :: Maybe [Monitor]
-> Maybe Text -> Maybe Text -> Text -> Text -> UpdateEnvironment
UpdateEnvironment'
    { $sel:monitors:UpdateEnvironment' :: Maybe [Monitor]
monitors = Maybe [Monitor]
forall a. Maybe a
Prelude.Nothing,
      $sel:name:UpdateEnvironment' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:description:UpdateEnvironment' :: Maybe Text
description = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:applicationId:UpdateEnvironment' :: Text
applicationId = Text
pApplicationId_,
      $sel:environmentId:UpdateEnvironment' :: Text
environmentId = Text
pEnvironmentId_
    }

-- | Amazon CloudWatch alarms to monitor during the deployment process.
updateEnvironment_monitors :: Lens.Lens' UpdateEnvironment (Prelude.Maybe [Monitor])
updateEnvironment_monitors :: (Maybe [Monitor] -> f (Maybe [Monitor]))
-> UpdateEnvironment -> f UpdateEnvironment
updateEnvironment_monitors = (UpdateEnvironment -> Maybe [Monitor])
-> (UpdateEnvironment -> Maybe [Monitor] -> UpdateEnvironment)
-> Lens
     UpdateEnvironment
     UpdateEnvironment
     (Maybe [Monitor])
     (Maybe [Monitor])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateEnvironment' {Maybe [Monitor]
monitors :: Maybe [Monitor]
$sel:monitors:UpdateEnvironment' :: UpdateEnvironment -> Maybe [Monitor]
monitors} -> Maybe [Monitor]
monitors) (\s :: UpdateEnvironment
s@UpdateEnvironment' {} Maybe [Monitor]
a -> UpdateEnvironment
s {$sel:monitors:UpdateEnvironment' :: Maybe [Monitor]
monitors = Maybe [Monitor]
a} :: UpdateEnvironment) ((Maybe [Monitor] -> f (Maybe [Monitor]))
 -> UpdateEnvironment -> f UpdateEnvironment)
-> ((Maybe [Monitor] -> f (Maybe [Monitor]))
    -> Maybe [Monitor] -> f (Maybe [Monitor]))
-> (Maybe [Monitor] -> f (Maybe [Monitor]))
-> UpdateEnvironment
-> f UpdateEnvironment
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Monitor] [Monitor] [Monitor] [Monitor]
-> Iso
     (Maybe [Monitor])
     (Maybe [Monitor])
     (Maybe [Monitor])
     (Maybe [Monitor])
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 AnIso [Monitor] [Monitor] [Monitor] [Monitor]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the environment.
updateEnvironment_name :: Lens.Lens' UpdateEnvironment (Prelude.Maybe Prelude.Text)
updateEnvironment_name :: (Maybe Text -> f (Maybe Text))
-> UpdateEnvironment -> f UpdateEnvironment
updateEnvironment_name = (UpdateEnvironment -> Maybe Text)
-> (UpdateEnvironment -> Maybe Text -> UpdateEnvironment)
-> Lens
     UpdateEnvironment UpdateEnvironment (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateEnvironment' {Maybe Text
name :: Maybe Text
$sel:name:UpdateEnvironment' :: UpdateEnvironment -> Maybe Text
name} -> Maybe Text
name) (\s :: UpdateEnvironment
s@UpdateEnvironment' {} Maybe Text
a -> UpdateEnvironment
s {$sel:name:UpdateEnvironment' :: Maybe Text
name = Maybe Text
a} :: UpdateEnvironment)

-- | A description of the environment.
updateEnvironment_description :: Lens.Lens' UpdateEnvironment (Prelude.Maybe Prelude.Text)
updateEnvironment_description :: (Maybe Text -> f (Maybe Text))
-> UpdateEnvironment -> f UpdateEnvironment
updateEnvironment_description = (UpdateEnvironment -> Maybe Text)
-> (UpdateEnvironment -> Maybe Text -> UpdateEnvironment)
-> Lens
     UpdateEnvironment UpdateEnvironment (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateEnvironment' {Maybe Text
description :: Maybe Text
$sel:description:UpdateEnvironment' :: UpdateEnvironment -> Maybe Text
description} -> Maybe Text
description) (\s :: UpdateEnvironment
s@UpdateEnvironment' {} Maybe Text
a -> UpdateEnvironment
s {$sel:description:UpdateEnvironment' :: Maybe Text
description = Maybe Text
a} :: UpdateEnvironment)

-- | The application ID.
updateEnvironment_applicationId :: Lens.Lens' UpdateEnvironment Prelude.Text
updateEnvironment_applicationId :: (Text -> f Text) -> UpdateEnvironment -> f UpdateEnvironment
updateEnvironment_applicationId = (UpdateEnvironment -> Text)
-> (UpdateEnvironment -> Text -> UpdateEnvironment)
-> Lens UpdateEnvironment UpdateEnvironment Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateEnvironment' {Text
applicationId :: Text
$sel:applicationId:UpdateEnvironment' :: UpdateEnvironment -> Text
applicationId} -> Text
applicationId) (\s :: UpdateEnvironment
s@UpdateEnvironment' {} Text
a -> UpdateEnvironment
s {$sel:applicationId:UpdateEnvironment' :: Text
applicationId = Text
a} :: UpdateEnvironment)

-- | The environment ID.
updateEnvironment_environmentId :: Lens.Lens' UpdateEnvironment Prelude.Text
updateEnvironment_environmentId :: (Text -> f Text) -> UpdateEnvironment -> f UpdateEnvironment
updateEnvironment_environmentId = (UpdateEnvironment -> Text)
-> (UpdateEnvironment -> Text -> UpdateEnvironment)
-> Lens UpdateEnvironment UpdateEnvironment Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateEnvironment' {Text
environmentId :: Text
$sel:environmentId:UpdateEnvironment' :: UpdateEnvironment -> Text
environmentId} -> Text
environmentId) (\s :: UpdateEnvironment
s@UpdateEnvironment' {} Text
a -> UpdateEnvironment
s {$sel:environmentId:UpdateEnvironment' :: Text
environmentId = Text
a} :: UpdateEnvironment)

instance Core.AWSRequest UpdateEnvironment where
  type AWSResponse UpdateEnvironment = Environment
  request :: UpdateEnvironment -> Request UpdateEnvironment
request = Service -> UpdateEnvironment -> Request UpdateEnvironment
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.patchJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdateEnvironment
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateEnvironment)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse UpdateEnvironment))
-> Logger
-> Service
-> Proxy UpdateEnvironment
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateEnvironment)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      (\Int
s ResponseHeaders
h Object
x -> Object -> Either String Environment
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)

instance Prelude.Hashable UpdateEnvironment

instance Prelude.NFData UpdateEnvironment

instance Core.ToHeaders UpdateEnvironment where
  toHeaders :: UpdateEnvironment -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdateEnvironment -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON UpdateEnvironment where
  toJSON :: UpdateEnvironment -> Value
toJSON UpdateEnvironment' {Maybe [Monitor]
Maybe Text
Text
environmentId :: Text
applicationId :: Text
description :: Maybe Text
name :: Maybe Text
monitors :: Maybe [Monitor]
$sel:environmentId:UpdateEnvironment' :: UpdateEnvironment -> Text
$sel:applicationId:UpdateEnvironment' :: UpdateEnvironment -> Text
$sel:description:UpdateEnvironment' :: UpdateEnvironment -> Maybe Text
$sel:name:UpdateEnvironment' :: UpdateEnvironment -> Maybe Text
$sel:monitors:UpdateEnvironment' :: UpdateEnvironment -> Maybe [Monitor]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Monitors" Text -> [Monitor] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Monitor] -> Pair) -> Maybe [Monitor] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Monitor]
monitors,
            (Text
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
name,
            (Text
"Description" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
description
          ]
      )

instance Core.ToPath UpdateEnvironment where
  toPath :: UpdateEnvironment -> ByteString
toPath UpdateEnvironment' {Maybe [Monitor]
Maybe Text
Text
environmentId :: Text
applicationId :: Text
description :: Maybe Text
name :: Maybe Text
monitors :: Maybe [Monitor]
$sel:environmentId:UpdateEnvironment' :: UpdateEnvironment -> Text
$sel:applicationId:UpdateEnvironment' :: UpdateEnvironment -> Text
$sel:description:UpdateEnvironment' :: UpdateEnvironment -> Maybe Text
$sel:name:UpdateEnvironment' :: UpdateEnvironment -> Maybe Text
$sel:monitors:UpdateEnvironment' :: UpdateEnvironment -> Maybe [Monitor]
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/applications/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
applicationId,
        ByteString
"/environments/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
environmentId
      ]

instance Core.ToQuery UpdateEnvironment where
  toQuery :: UpdateEnvironment -> QueryString
toQuery = QueryString -> UpdateEnvironment -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty