{-# 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.DirectConnect.DescribeLocations
-- 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)
--
-- Lists the Direct Connect locations in the current Amazon Web Services
-- Region. These are the locations that can be selected when calling
-- CreateConnection or CreateInterconnect.
module Amazonka.DirectConnect.DescribeLocations
  ( -- * Creating a Request
    DescribeLocations (..),
    newDescribeLocations,

    -- * Destructuring the Response
    DescribeLocationsResponse (..),
    newDescribeLocationsResponse,

    -- * Response Lenses
    describeLocationsResponse_locations,
    describeLocationsResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.DirectConnect.Types
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:/ 'newDescribeLocations' smart constructor.
data DescribeLocations = DescribeLocations'
  {
  }
  deriving (DescribeLocations -> DescribeLocations -> Bool
(DescribeLocations -> DescribeLocations -> Bool)
-> (DescribeLocations -> DescribeLocations -> Bool)
-> Eq DescribeLocations
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeLocations -> DescribeLocations -> Bool
$c/= :: DescribeLocations -> DescribeLocations -> Bool
== :: DescribeLocations -> DescribeLocations -> Bool
$c== :: DescribeLocations -> DescribeLocations -> Bool
Prelude.Eq, ReadPrec [DescribeLocations]
ReadPrec DescribeLocations
Int -> ReadS DescribeLocations
ReadS [DescribeLocations]
(Int -> ReadS DescribeLocations)
-> ReadS [DescribeLocations]
-> ReadPrec DescribeLocations
-> ReadPrec [DescribeLocations]
-> Read DescribeLocations
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeLocations]
$creadListPrec :: ReadPrec [DescribeLocations]
readPrec :: ReadPrec DescribeLocations
$creadPrec :: ReadPrec DescribeLocations
readList :: ReadS [DescribeLocations]
$creadList :: ReadS [DescribeLocations]
readsPrec :: Int -> ReadS DescribeLocations
$creadsPrec :: Int -> ReadS DescribeLocations
Prelude.Read, Int -> DescribeLocations -> ShowS
[DescribeLocations] -> ShowS
DescribeLocations -> String
(Int -> DescribeLocations -> ShowS)
-> (DescribeLocations -> String)
-> ([DescribeLocations] -> ShowS)
-> Show DescribeLocations
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeLocations] -> ShowS
$cshowList :: [DescribeLocations] -> ShowS
show :: DescribeLocations -> String
$cshow :: DescribeLocations -> String
showsPrec :: Int -> DescribeLocations -> ShowS
$cshowsPrec :: Int -> DescribeLocations -> ShowS
Prelude.Show, (forall x. DescribeLocations -> Rep DescribeLocations x)
-> (forall x. Rep DescribeLocations x -> DescribeLocations)
-> Generic DescribeLocations
forall x. Rep DescribeLocations x -> DescribeLocations
forall x. DescribeLocations -> Rep DescribeLocations x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeLocations x -> DescribeLocations
$cfrom :: forall x. DescribeLocations -> Rep DescribeLocations x
Prelude.Generic)

-- |
-- Create a value of 'DescribeLocations' 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.
newDescribeLocations ::
  DescribeLocations
newDescribeLocations :: DescribeLocations
newDescribeLocations = DescribeLocations
DescribeLocations'

instance Core.AWSRequest DescribeLocations where
  type
    AWSResponse DescribeLocations =
      DescribeLocationsResponse
  request :: DescribeLocations -> Request DescribeLocations
request = Service -> DescribeLocations -> Request DescribeLocations
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DescribeLocations
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DescribeLocations)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DescribeLocations))
-> Logger
-> Service
-> Proxy DescribeLocations
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DescribeLocations)))
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 [Location] -> Int -> DescribeLocationsResponse
DescribeLocationsResponse'
            (Maybe [Location] -> Int -> DescribeLocationsResponse)
-> Either String (Maybe [Location])
-> Either String (Int -> DescribeLocationsResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Key -> Either String (Maybe (Maybe [Location]))
forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Core..?> Key
"locations" Either String (Maybe (Maybe [Location]))
-> Maybe [Location] -> Either String (Maybe [Location])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [Location]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> DescribeLocationsResponse)
-> Either String Int -> Either String DescribeLocationsResponse
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 DescribeLocations

instance Prelude.NFData DescribeLocations

instance Core.ToHeaders DescribeLocations where
  toHeaders :: DescribeLocations -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DescribeLocations -> 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
"OvertureService.DescribeLocations" ::
                          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 DescribeLocations where
  toJSON :: DescribeLocations -> Value
toJSON = Value -> DescribeLocations -> Value
forall a b. a -> b -> a
Prelude.const (Object -> Value
Core.Object Object
forall a. Monoid a => a
Prelude.mempty)

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

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

-- | /See:/ 'newDescribeLocationsResponse' smart constructor.
data DescribeLocationsResponse = DescribeLocationsResponse'
  { -- | The locations.
    DescribeLocationsResponse -> Maybe [Location]
locations :: Prelude.Maybe [Location],
    -- | The response's http status code.
    DescribeLocationsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DescribeLocationsResponse -> DescribeLocationsResponse -> Bool
(DescribeLocationsResponse -> DescribeLocationsResponse -> Bool)
-> (DescribeLocationsResponse -> DescribeLocationsResponse -> Bool)
-> Eq DescribeLocationsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeLocationsResponse -> DescribeLocationsResponse -> Bool
$c/= :: DescribeLocationsResponse -> DescribeLocationsResponse -> Bool
== :: DescribeLocationsResponse -> DescribeLocationsResponse -> Bool
$c== :: DescribeLocationsResponse -> DescribeLocationsResponse -> Bool
Prelude.Eq, ReadPrec [DescribeLocationsResponse]
ReadPrec DescribeLocationsResponse
Int -> ReadS DescribeLocationsResponse
ReadS [DescribeLocationsResponse]
(Int -> ReadS DescribeLocationsResponse)
-> ReadS [DescribeLocationsResponse]
-> ReadPrec DescribeLocationsResponse
-> ReadPrec [DescribeLocationsResponse]
-> Read DescribeLocationsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeLocationsResponse]
$creadListPrec :: ReadPrec [DescribeLocationsResponse]
readPrec :: ReadPrec DescribeLocationsResponse
$creadPrec :: ReadPrec DescribeLocationsResponse
readList :: ReadS [DescribeLocationsResponse]
$creadList :: ReadS [DescribeLocationsResponse]
readsPrec :: Int -> ReadS DescribeLocationsResponse
$creadsPrec :: Int -> ReadS DescribeLocationsResponse
Prelude.Read, Int -> DescribeLocationsResponse -> ShowS
[DescribeLocationsResponse] -> ShowS
DescribeLocationsResponse -> String
(Int -> DescribeLocationsResponse -> ShowS)
-> (DescribeLocationsResponse -> String)
-> ([DescribeLocationsResponse] -> ShowS)
-> Show DescribeLocationsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeLocationsResponse] -> ShowS
$cshowList :: [DescribeLocationsResponse] -> ShowS
show :: DescribeLocationsResponse -> String
$cshow :: DescribeLocationsResponse -> String
showsPrec :: Int -> DescribeLocationsResponse -> ShowS
$cshowsPrec :: Int -> DescribeLocationsResponse -> ShowS
Prelude.Show, (forall x.
 DescribeLocationsResponse -> Rep DescribeLocationsResponse x)
-> (forall x.
    Rep DescribeLocationsResponse x -> DescribeLocationsResponse)
-> Generic DescribeLocationsResponse
forall x.
Rep DescribeLocationsResponse x -> DescribeLocationsResponse
forall x.
DescribeLocationsResponse -> Rep DescribeLocationsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DescribeLocationsResponse x -> DescribeLocationsResponse
$cfrom :: forall x.
DescribeLocationsResponse -> Rep DescribeLocationsResponse x
Prelude.Generic)

-- |
-- Create a value of 'DescribeLocationsResponse' 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:
--
-- 'locations', 'describeLocationsResponse_locations' - The locations.
--
-- 'httpStatus', 'describeLocationsResponse_httpStatus' - The response's http status code.
newDescribeLocationsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeLocationsResponse
newDescribeLocationsResponse :: Int -> DescribeLocationsResponse
newDescribeLocationsResponse Int
pHttpStatus_ =
  DescribeLocationsResponse' :: Maybe [Location] -> Int -> DescribeLocationsResponse
DescribeLocationsResponse'
    { $sel:locations:DescribeLocationsResponse' :: Maybe [Location]
locations =
        Maybe [Location]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeLocationsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The locations.
describeLocationsResponse_locations :: Lens.Lens' DescribeLocationsResponse (Prelude.Maybe [Location])
describeLocationsResponse_locations :: (Maybe [Location] -> f (Maybe [Location]))
-> DescribeLocationsResponse -> f DescribeLocationsResponse
describeLocationsResponse_locations = (DescribeLocationsResponse -> Maybe [Location])
-> (DescribeLocationsResponse
    -> Maybe [Location] -> DescribeLocationsResponse)
-> Lens
     DescribeLocationsResponse
     DescribeLocationsResponse
     (Maybe [Location])
     (Maybe [Location])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeLocationsResponse' {Maybe [Location]
locations :: Maybe [Location]
$sel:locations:DescribeLocationsResponse' :: DescribeLocationsResponse -> Maybe [Location]
locations} -> Maybe [Location]
locations) (\s :: DescribeLocationsResponse
s@DescribeLocationsResponse' {} Maybe [Location]
a -> DescribeLocationsResponse
s {$sel:locations:DescribeLocationsResponse' :: Maybe [Location]
locations = Maybe [Location]
a} :: DescribeLocationsResponse) ((Maybe [Location] -> f (Maybe [Location]))
 -> DescribeLocationsResponse -> f DescribeLocationsResponse)
-> ((Maybe [Location] -> f (Maybe [Location]))
    -> Maybe [Location] -> f (Maybe [Location]))
-> (Maybe [Location] -> f (Maybe [Location]))
-> DescribeLocationsResponse
-> f DescribeLocationsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Location] [Location] [Location] [Location]
-> Iso
     (Maybe [Location])
     (Maybe [Location])
     (Maybe [Location])
     (Maybe [Location])
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 [Location] [Location] [Location] [Location]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData DescribeLocationsResponse