{-# 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.Cloud9.DescribeEnvironments
-- 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)
--
-- Gets information about Cloud9 development environments.
module Amazonka.Cloud9.DescribeEnvironments
  ( -- * Creating a Request
    DescribeEnvironments (..),
    newDescribeEnvironments,

    -- * Request Lenses
    describeEnvironments_environmentIds,

    -- * Destructuring the Response
    DescribeEnvironmentsResponse (..),
    newDescribeEnvironmentsResponse,

    -- * Response Lenses
    describeEnvironmentsResponse_environments,
    describeEnvironmentsResponse_httpStatus,
  )
where

import Amazonka.Cloud9.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:/ 'newDescribeEnvironments' smart constructor.
data DescribeEnvironments = DescribeEnvironments'
  { -- | The IDs of individual environments to get information about.
    DescribeEnvironments -> NonEmpty Text
environmentIds :: Prelude.NonEmpty Prelude.Text
  }
  deriving (DescribeEnvironments -> DescribeEnvironments -> Bool
(DescribeEnvironments -> DescribeEnvironments -> Bool)
-> (DescribeEnvironments -> DescribeEnvironments -> Bool)
-> Eq DescribeEnvironments
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeEnvironments -> DescribeEnvironments -> Bool
$c/= :: DescribeEnvironments -> DescribeEnvironments -> Bool
== :: DescribeEnvironments -> DescribeEnvironments -> Bool
$c== :: DescribeEnvironments -> DescribeEnvironments -> Bool
Prelude.Eq, ReadPrec [DescribeEnvironments]
ReadPrec DescribeEnvironments
Int -> ReadS DescribeEnvironments
ReadS [DescribeEnvironments]
(Int -> ReadS DescribeEnvironments)
-> ReadS [DescribeEnvironments]
-> ReadPrec DescribeEnvironments
-> ReadPrec [DescribeEnvironments]
-> Read DescribeEnvironments
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeEnvironments]
$creadListPrec :: ReadPrec [DescribeEnvironments]
readPrec :: ReadPrec DescribeEnvironments
$creadPrec :: ReadPrec DescribeEnvironments
readList :: ReadS [DescribeEnvironments]
$creadList :: ReadS [DescribeEnvironments]
readsPrec :: Int -> ReadS DescribeEnvironments
$creadsPrec :: Int -> ReadS DescribeEnvironments
Prelude.Read, Int -> DescribeEnvironments -> ShowS
[DescribeEnvironments] -> ShowS
DescribeEnvironments -> String
(Int -> DescribeEnvironments -> ShowS)
-> (DescribeEnvironments -> String)
-> ([DescribeEnvironments] -> ShowS)
-> Show DescribeEnvironments
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeEnvironments] -> ShowS
$cshowList :: [DescribeEnvironments] -> ShowS
show :: DescribeEnvironments -> String
$cshow :: DescribeEnvironments -> String
showsPrec :: Int -> DescribeEnvironments -> ShowS
$cshowsPrec :: Int -> DescribeEnvironments -> ShowS
Prelude.Show, (forall x. DescribeEnvironments -> Rep DescribeEnvironments x)
-> (forall x. Rep DescribeEnvironments x -> DescribeEnvironments)
-> Generic DescribeEnvironments
forall x. Rep DescribeEnvironments x -> DescribeEnvironments
forall x. DescribeEnvironments -> Rep DescribeEnvironments x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeEnvironments x -> DescribeEnvironments
$cfrom :: forall x. DescribeEnvironments -> Rep DescribeEnvironments x
Prelude.Generic)

-- |
-- Create a value of 'DescribeEnvironments' 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:
--
-- 'environmentIds', 'describeEnvironments_environmentIds' - The IDs of individual environments to get information about.
newDescribeEnvironments ::
  -- | 'environmentIds'
  Prelude.NonEmpty Prelude.Text ->
  DescribeEnvironments
newDescribeEnvironments :: NonEmpty Text -> DescribeEnvironments
newDescribeEnvironments NonEmpty Text
pEnvironmentIds_ =
  DescribeEnvironments' :: NonEmpty Text -> DescribeEnvironments
DescribeEnvironments'
    { $sel:environmentIds:DescribeEnvironments' :: NonEmpty Text
environmentIds =
        Tagged (NonEmpty Text) (Identity (NonEmpty Text))
-> Tagged (NonEmpty Text) (Identity (NonEmpty Text))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Text) (Identity (NonEmpty Text))
 -> Tagged (NonEmpty Text) (Identity (NonEmpty Text)))
-> NonEmpty Text -> NonEmpty Text
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pEnvironmentIds_
    }

-- | The IDs of individual environments to get information about.
describeEnvironments_environmentIds :: Lens.Lens' DescribeEnvironments (Prelude.NonEmpty Prelude.Text)
describeEnvironments_environmentIds :: (NonEmpty Text -> f (NonEmpty Text))
-> DescribeEnvironments -> f DescribeEnvironments
describeEnvironments_environmentIds = (DescribeEnvironments -> NonEmpty Text)
-> (DescribeEnvironments -> NonEmpty Text -> DescribeEnvironments)
-> Lens
     DescribeEnvironments
     DescribeEnvironments
     (NonEmpty Text)
     (NonEmpty Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeEnvironments' {NonEmpty Text
environmentIds :: NonEmpty Text
$sel:environmentIds:DescribeEnvironments' :: DescribeEnvironments -> NonEmpty Text
environmentIds} -> NonEmpty Text
environmentIds) (\s :: DescribeEnvironments
s@DescribeEnvironments' {} NonEmpty Text
a -> DescribeEnvironments
s {$sel:environmentIds:DescribeEnvironments' :: NonEmpty Text
environmentIds = NonEmpty Text
a} :: DescribeEnvironments) ((NonEmpty Text -> f (NonEmpty Text))
 -> DescribeEnvironments -> f DescribeEnvironments)
-> ((NonEmpty Text -> f (NonEmpty Text))
    -> NonEmpty Text -> f (NonEmpty Text))
-> (NonEmpty Text -> f (NonEmpty Text))
-> DescribeEnvironments
-> f DescribeEnvironments
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Text -> f (NonEmpty Text))
-> NonEmpty Text -> f (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest DescribeEnvironments where
  type
    AWSResponse DescribeEnvironments =
      DescribeEnvironmentsResponse
  request :: DescribeEnvironments -> Request DescribeEnvironments
request = Service -> DescribeEnvironments -> Request DescribeEnvironments
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DescribeEnvironments
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DescribeEnvironments)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DescribeEnvironments))
-> Logger
-> Service
-> Proxy DescribeEnvironments
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DescribeEnvironments)))
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 ->
          Maybe [Environment] -> Int -> DescribeEnvironmentsResponse
DescribeEnvironmentsResponse'
            (Maybe [Environment] -> Int -> DescribeEnvironmentsResponse)
-> Either String (Maybe [Environment])
-> Either String (Int -> DescribeEnvironmentsResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe (Maybe [Environment]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"environments" Either String (Maybe (Maybe [Environment]))
-> Maybe [Environment] -> Either String (Maybe [Environment])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [Environment]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> DescribeEnvironmentsResponse)
-> Either String Int -> Either String DescribeEnvironmentsResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable DescribeEnvironments

instance Prelude.NFData DescribeEnvironments

instance Core.ToHeaders DescribeEnvironments where
  toHeaders :: DescribeEnvironments -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DescribeEnvironments -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"AWSCloud9WorkspaceManagementService.DescribeEnvironments" ::
                          Prelude.ByteString
                      ),
            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 DescribeEnvironments where
  toJSON :: DescribeEnvironments -> Value
toJSON DescribeEnvironments' {NonEmpty Text
environmentIds :: NonEmpty Text
$sel:environmentIds:DescribeEnvironments' :: DescribeEnvironments -> NonEmpty Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"environmentIds" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Text
environmentIds)
          ]
      )

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

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

-- | /See:/ 'newDescribeEnvironmentsResponse' smart constructor.
data DescribeEnvironmentsResponse = DescribeEnvironmentsResponse'
  { -- | Information about the environments that are returned.
    DescribeEnvironmentsResponse -> Maybe [Environment]
environments :: Prelude.Maybe [Environment],
    -- | The response's http status code.
    DescribeEnvironmentsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DescribeEnvironmentsResponse
-> DescribeEnvironmentsResponse -> Bool
(DescribeEnvironmentsResponse
 -> DescribeEnvironmentsResponse -> Bool)
-> (DescribeEnvironmentsResponse
    -> DescribeEnvironmentsResponse -> Bool)
-> Eq DescribeEnvironmentsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeEnvironmentsResponse
-> DescribeEnvironmentsResponse -> Bool
$c/= :: DescribeEnvironmentsResponse
-> DescribeEnvironmentsResponse -> Bool
== :: DescribeEnvironmentsResponse
-> DescribeEnvironmentsResponse -> Bool
$c== :: DescribeEnvironmentsResponse
-> DescribeEnvironmentsResponse -> Bool
Prelude.Eq, Int -> DescribeEnvironmentsResponse -> ShowS
[DescribeEnvironmentsResponse] -> ShowS
DescribeEnvironmentsResponse -> String
(Int -> DescribeEnvironmentsResponse -> ShowS)
-> (DescribeEnvironmentsResponse -> String)
-> ([DescribeEnvironmentsResponse] -> ShowS)
-> Show DescribeEnvironmentsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeEnvironmentsResponse] -> ShowS
$cshowList :: [DescribeEnvironmentsResponse] -> ShowS
show :: DescribeEnvironmentsResponse -> String
$cshow :: DescribeEnvironmentsResponse -> String
showsPrec :: Int -> DescribeEnvironmentsResponse -> ShowS
$cshowsPrec :: Int -> DescribeEnvironmentsResponse -> ShowS
Prelude.Show, (forall x.
 DescribeEnvironmentsResponse -> Rep DescribeEnvironmentsResponse x)
-> (forall x.
    Rep DescribeEnvironmentsResponse x -> DescribeEnvironmentsResponse)
-> Generic DescribeEnvironmentsResponse
forall x.
Rep DescribeEnvironmentsResponse x -> DescribeEnvironmentsResponse
forall x.
DescribeEnvironmentsResponse -> Rep DescribeEnvironmentsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DescribeEnvironmentsResponse x -> DescribeEnvironmentsResponse
$cfrom :: forall x.
DescribeEnvironmentsResponse -> Rep DescribeEnvironmentsResponse x
Prelude.Generic)

-- |
-- Create a value of 'DescribeEnvironmentsResponse' 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:
--
-- 'environments', 'describeEnvironmentsResponse_environments' - Information about the environments that are returned.
--
-- 'httpStatus', 'describeEnvironmentsResponse_httpStatus' - The response's http status code.
newDescribeEnvironmentsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeEnvironmentsResponse
newDescribeEnvironmentsResponse :: Int -> DescribeEnvironmentsResponse
newDescribeEnvironmentsResponse Int
pHttpStatus_ =
  DescribeEnvironmentsResponse' :: Maybe [Environment] -> Int -> DescribeEnvironmentsResponse
DescribeEnvironmentsResponse'
    { $sel:environments:DescribeEnvironmentsResponse' :: Maybe [Environment]
environments =
        Maybe [Environment]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeEnvironmentsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about the environments that are returned.
describeEnvironmentsResponse_environments :: Lens.Lens' DescribeEnvironmentsResponse (Prelude.Maybe [Environment])
describeEnvironmentsResponse_environments :: (Maybe [Environment] -> f (Maybe [Environment]))
-> DescribeEnvironmentsResponse -> f DescribeEnvironmentsResponse
describeEnvironmentsResponse_environments = (DescribeEnvironmentsResponse -> Maybe [Environment])
-> (DescribeEnvironmentsResponse
    -> Maybe [Environment] -> DescribeEnvironmentsResponse)
-> Lens
     DescribeEnvironmentsResponse
     DescribeEnvironmentsResponse
     (Maybe [Environment])
     (Maybe [Environment])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeEnvironmentsResponse' {Maybe [Environment]
environments :: Maybe [Environment]
$sel:environments:DescribeEnvironmentsResponse' :: DescribeEnvironmentsResponse -> Maybe [Environment]
environments} -> Maybe [Environment]
environments) (\s :: DescribeEnvironmentsResponse
s@DescribeEnvironmentsResponse' {} Maybe [Environment]
a -> DescribeEnvironmentsResponse
s {$sel:environments:DescribeEnvironmentsResponse' :: Maybe [Environment]
environments = Maybe [Environment]
a} :: DescribeEnvironmentsResponse) ((Maybe [Environment] -> f (Maybe [Environment]))
 -> DescribeEnvironmentsResponse -> f DescribeEnvironmentsResponse)
-> ((Maybe [Environment] -> f (Maybe [Environment]))
    -> Maybe [Environment] -> f (Maybe [Environment]))
-> (Maybe [Environment] -> f (Maybe [Environment]))
-> DescribeEnvironmentsResponse
-> f DescribeEnvironmentsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Environment] [Environment] [Environment] [Environment]
-> Iso
     (Maybe [Environment])
     (Maybe [Environment])
     (Maybe [Environment])
     (Maybe [Environment])
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 [Environment] [Environment] [Environment] [Environment]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData DescribeEnvironmentsResponse