{-# 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.Proton.GetEnvironment
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Get detailed data for an environment.
module Amazonka.Proton.GetEnvironment
  ( -- * Creating a Request
    GetEnvironment (..),
    newGetEnvironment,

    -- * Request Lenses
    getEnvironment_name,

    -- * Destructuring the Response
    GetEnvironmentResponse (..),
    newGetEnvironmentResponse,

    -- * Response Lenses
    getEnvironmentResponse_httpStatus,
    getEnvironmentResponse_environment,
  )
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
import Amazonka.Proton.Types
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newGetEnvironment' smart constructor.
data GetEnvironment = GetEnvironment'
  { -- | The name of the environment that you want to get the detailed data for.
    GetEnvironment -> Text
name :: Prelude.Text
  }
  deriving (GetEnvironment -> GetEnvironment -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetEnvironment -> GetEnvironment -> Bool
$c/= :: GetEnvironment -> GetEnvironment -> Bool
== :: GetEnvironment -> GetEnvironment -> Bool
$c== :: GetEnvironment -> GetEnvironment -> Bool
Prelude.Eq, ReadPrec [GetEnvironment]
ReadPrec GetEnvironment
Int -> ReadS GetEnvironment
ReadS [GetEnvironment]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetEnvironment]
$creadListPrec :: ReadPrec [GetEnvironment]
readPrec :: ReadPrec GetEnvironment
$creadPrec :: ReadPrec GetEnvironment
readList :: ReadS [GetEnvironment]
$creadList :: ReadS [GetEnvironment]
readsPrec :: Int -> ReadS GetEnvironment
$creadsPrec :: Int -> ReadS GetEnvironment
Prelude.Read, Int -> GetEnvironment -> ShowS
[GetEnvironment] -> ShowS
GetEnvironment -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetEnvironment] -> ShowS
$cshowList :: [GetEnvironment] -> ShowS
show :: GetEnvironment -> String
$cshow :: GetEnvironment -> String
showsPrec :: Int -> GetEnvironment -> ShowS
$cshowsPrec :: Int -> GetEnvironment -> ShowS
Prelude.Show, forall x. Rep GetEnvironment x -> GetEnvironment
forall x. GetEnvironment -> Rep GetEnvironment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetEnvironment x -> GetEnvironment
$cfrom :: forall x. GetEnvironment -> Rep GetEnvironment x
Prelude.Generic)

-- |
-- Create a value of 'GetEnvironment' 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:
--
-- 'name', 'getEnvironment_name' - The name of the environment that you want to get the detailed data for.
newGetEnvironment ::
  -- | 'name'
  Prelude.Text ->
  GetEnvironment
newGetEnvironment :: Text -> GetEnvironment
newGetEnvironment Text
pName_ =
  GetEnvironment' {$sel:name:GetEnvironment' :: Text
name = Text
pName_}

-- | The name of the environment that you want to get the detailed data for.
getEnvironment_name :: Lens.Lens' GetEnvironment Prelude.Text
getEnvironment_name :: Lens' GetEnvironment Text
getEnvironment_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetEnvironment' {Text
name :: Text
$sel:name:GetEnvironment' :: GetEnvironment -> Text
name} -> Text
name) (\s :: GetEnvironment
s@GetEnvironment' {} Text
a -> GetEnvironment
s {$sel:name:GetEnvironment' :: Text
name = Text
a} :: GetEnvironment)

instance Core.AWSRequest GetEnvironment where
  type
    AWSResponse GetEnvironment =
      GetEnvironmentResponse
  request :: (Service -> Service) -> GetEnvironment -> Request GetEnvironment
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetEnvironment
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetEnvironment)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int -> Environment -> GetEnvironmentResponse
GetEnvironmentResponse'
            forall (f :: * -> *) a b. Functor 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))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String a
Data..:> Key
"environment")
      )

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

instance Prelude.NFData GetEnvironment where
  rnf :: GetEnvironment -> ()
rnf GetEnvironment' {Text
name :: Text
$sel:name:GetEnvironment' :: GetEnvironment -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
name

instance Data.ToHeaders GetEnvironment where
  toHeaders :: GetEnvironment -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"AwsProton20200720.GetEnvironment" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON GetEnvironment where
  toJSON :: GetEnvironment -> Value
toJSON GetEnvironment' {Text
name :: Text
$sel:name:GetEnvironment' :: GetEnvironment -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name)]
      )

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

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

-- | /See:/ 'newGetEnvironmentResponse' smart constructor.
data GetEnvironmentResponse = GetEnvironmentResponse'
  { -- | The response's http status code.
    GetEnvironmentResponse -> Int
httpStatus :: Prelude.Int,
    -- | The detailed data of the requested environment.
    GetEnvironmentResponse -> Environment
environment :: Environment
  }
  deriving (GetEnvironmentResponse -> GetEnvironmentResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetEnvironmentResponse -> GetEnvironmentResponse -> Bool
$c/= :: GetEnvironmentResponse -> GetEnvironmentResponse -> Bool
== :: GetEnvironmentResponse -> GetEnvironmentResponse -> Bool
$c== :: GetEnvironmentResponse -> GetEnvironmentResponse -> Bool
Prelude.Eq, Int -> GetEnvironmentResponse -> ShowS
[GetEnvironmentResponse] -> ShowS
GetEnvironmentResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetEnvironmentResponse] -> ShowS
$cshowList :: [GetEnvironmentResponse] -> ShowS
show :: GetEnvironmentResponse -> String
$cshow :: GetEnvironmentResponse -> String
showsPrec :: Int -> GetEnvironmentResponse -> ShowS
$cshowsPrec :: Int -> GetEnvironmentResponse -> ShowS
Prelude.Show, forall x. Rep GetEnvironmentResponse x -> GetEnvironmentResponse
forall x. GetEnvironmentResponse -> Rep GetEnvironmentResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetEnvironmentResponse x -> GetEnvironmentResponse
$cfrom :: forall x. GetEnvironmentResponse -> Rep GetEnvironmentResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetEnvironmentResponse' 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:
--
-- 'httpStatus', 'getEnvironmentResponse_httpStatus' - The response's http status code.
--
-- 'environment', 'getEnvironmentResponse_environment' - The detailed data of the requested environment.
newGetEnvironmentResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'environment'
  Environment ->
  GetEnvironmentResponse
newGetEnvironmentResponse :: Int -> Environment -> GetEnvironmentResponse
newGetEnvironmentResponse Int
pHttpStatus_ Environment
pEnvironment_ =
  GetEnvironmentResponse'
    { $sel:httpStatus:GetEnvironmentResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:environment:GetEnvironmentResponse' :: Environment
environment = Environment
pEnvironment_
    }

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

-- | The detailed data of the requested environment.
getEnvironmentResponse_environment :: Lens.Lens' GetEnvironmentResponse Environment
getEnvironmentResponse_environment :: Lens' GetEnvironmentResponse Environment
getEnvironmentResponse_environment = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetEnvironmentResponse' {Environment
environment :: Environment
$sel:environment:GetEnvironmentResponse' :: GetEnvironmentResponse -> Environment
environment} -> Environment
environment) (\s :: GetEnvironmentResponse
s@GetEnvironmentResponse' {} Environment
a -> GetEnvironmentResponse
s {$sel:environment:GetEnvironmentResponse' :: Environment
environment = Environment
a} :: GetEnvironmentResponse)

instance Prelude.NFData GetEnvironmentResponse where
  rnf :: GetEnvironmentResponse -> ()
rnf GetEnvironmentResponse' {Int
Environment
environment :: Environment
httpStatus :: Int
$sel:environment:GetEnvironmentResponse' :: GetEnvironmentResponse -> Environment
$sel:httpStatus:GetEnvironmentResponse' :: GetEnvironmentResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Environment
environment