{-# 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.Lightsail.GetRegions
-- 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)
--
-- Returns a list of all valid regions for Amazon Lightsail. Use the
-- @include availability zones@ parameter to also return the Availability
-- Zones in a region.
module Amazonka.Lightsail.GetRegions
  ( -- * Creating a Request
    GetRegions (..),
    newGetRegions,

    -- * Request Lenses
    getRegions_includeRelationalDatabaseAvailabilityZones,
    getRegions_includeAvailabilityZones,

    -- * Destructuring the Response
    GetRegionsResponse (..),
    newGetRegionsResponse,

    -- * Response Lenses
    getRegionsResponse_regions,
    getRegionsResponse_httpStatus,
  )
where

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

-- | /See:/ 'newGetRegions' smart constructor.
data GetRegions = GetRegions'
  { -- | A Boolean value indicating whether to also include Availability Zones
    -- for databases in your get regions request. Availability Zones are
    -- indicated with a letter (e.g., @us-east-2a@).
    GetRegions -> Maybe Bool
includeRelationalDatabaseAvailabilityZones :: Prelude.Maybe Prelude.Bool,
    -- | A Boolean value indicating whether to also include Availability Zones in
    -- your get regions request. Availability Zones are indicated with a
    -- letter: e.g., @us-east-2a@.
    GetRegions -> Maybe Bool
includeAvailabilityZones :: Prelude.Maybe Prelude.Bool
  }
  deriving (GetRegions -> GetRegions -> Bool
(GetRegions -> GetRegions -> Bool)
-> (GetRegions -> GetRegions -> Bool) -> Eq GetRegions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetRegions -> GetRegions -> Bool
$c/= :: GetRegions -> GetRegions -> Bool
== :: GetRegions -> GetRegions -> Bool
$c== :: GetRegions -> GetRegions -> Bool
Prelude.Eq, ReadPrec [GetRegions]
ReadPrec GetRegions
Int -> ReadS GetRegions
ReadS [GetRegions]
(Int -> ReadS GetRegions)
-> ReadS [GetRegions]
-> ReadPrec GetRegions
-> ReadPrec [GetRegions]
-> Read GetRegions
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetRegions]
$creadListPrec :: ReadPrec [GetRegions]
readPrec :: ReadPrec GetRegions
$creadPrec :: ReadPrec GetRegions
readList :: ReadS [GetRegions]
$creadList :: ReadS [GetRegions]
readsPrec :: Int -> ReadS GetRegions
$creadsPrec :: Int -> ReadS GetRegions
Prelude.Read, Int -> GetRegions -> ShowS
[GetRegions] -> ShowS
GetRegions -> String
(Int -> GetRegions -> ShowS)
-> (GetRegions -> String)
-> ([GetRegions] -> ShowS)
-> Show GetRegions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetRegions] -> ShowS
$cshowList :: [GetRegions] -> ShowS
show :: GetRegions -> String
$cshow :: GetRegions -> String
showsPrec :: Int -> GetRegions -> ShowS
$cshowsPrec :: Int -> GetRegions -> ShowS
Prelude.Show, (forall x. GetRegions -> Rep GetRegions x)
-> (forall x. Rep GetRegions x -> GetRegions) -> Generic GetRegions
forall x. Rep GetRegions x -> GetRegions
forall x. GetRegions -> Rep GetRegions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetRegions x -> GetRegions
$cfrom :: forall x. GetRegions -> Rep GetRegions x
Prelude.Generic)

-- |
-- Create a value of 'GetRegions' 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:
--
-- 'includeRelationalDatabaseAvailabilityZones', 'getRegions_includeRelationalDatabaseAvailabilityZones' - A Boolean value indicating whether to also include Availability Zones
-- for databases in your get regions request. Availability Zones are
-- indicated with a letter (e.g., @us-east-2a@).
--
-- 'includeAvailabilityZones', 'getRegions_includeAvailabilityZones' - A Boolean value indicating whether to also include Availability Zones in
-- your get regions request. Availability Zones are indicated with a
-- letter: e.g., @us-east-2a@.
newGetRegions ::
  GetRegions
newGetRegions :: GetRegions
newGetRegions =
  GetRegions' :: Maybe Bool -> Maybe Bool -> GetRegions
GetRegions'
    { $sel:includeRelationalDatabaseAvailabilityZones:GetRegions' :: Maybe Bool
includeRelationalDatabaseAvailabilityZones =
        Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:includeAvailabilityZones:GetRegions' :: Maybe Bool
includeAvailabilityZones = Maybe Bool
forall a. Maybe a
Prelude.Nothing
    }

-- | A Boolean value indicating whether to also include Availability Zones
-- for databases in your get regions request. Availability Zones are
-- indicated with a letter (e.g., @us-east-2a@).
getRegions_includeRelationalDatabaseAvailabilityZones :: Lens.Lens' GetRegions (Prelude.Maybe Prelude.Bool)
getRegions_includeRelationalDatabaseAvailabilityZones :: (Maybe Bool -> f (Maybe Bool)) -> GetRegions -> f GetRegions
getRegions_includeRelationalDatabaseAvailabilityZones = (GetRegions -> Maybe Bool)
-> (GetRegions -> Maybe Bool -> GetRegions)
-> Lens GetRegions GetRegions (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRegions' {Maybe Bool
includeRelationalDatabaseAvailabilityZones :: Maybe Bool
$sel:includeRelationalDatabaseAvailabilityZones:GetRegions' :: GetRegions -> Maybe Bool
includeRelationalDatabaseAvailabilityZones} -> Maybe Bool
includeRelationalDatabaseAvailabilityZones) (\s :: GetRegions
s@GetRegions' {} Maybe Bool
a -> GetRegions
s {$sel:includeRelationalDatabaseAvailabilityZones:GetRegions' :: Maybe Bool
includeRelationalDatabaseAvailabilityZones = Maybe Bool
a} :: GetRegions)

-- | A Boolean value indicating whether to also include Availability Zones in
-- your get regions request. Availability Zones are indicated with a
-- letter: e.g., @us-east-2a@.
getRegions_includeAvailabilityZones :: Lens.Lens' GetRegions (Prelude.Maybe Prelude.Bool)
getRegions_includeAvailabilityZones :: (Maybe Bool -> f (Maybe Bool)) -> GetRegions -> f GetRegions
getRegions_includeAvailabilityZones = (GetRegions -> Maybe Bool)
-> (GetRegions -> Maybe Bool -> GetRegions)
-> Lens GetRegions GetRegions (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRegions' {Maybe Bool
includeAvailabilityZones :: Maybe Bool
$sel:includeAvailabilityZones:GetRegions' :: GetRegions -> Maybe Bool
includeAvailabilityZones} -> Maybe Bool
includeAvailabilityZones) (\s :: GetRegions
s@GetRegions' {} Maybe Bool
a -> GetRegions
s {$sel:includeAvailabilityZones:GetRegions' :: Maybe Bool
includeAvailabilityZones = Maybe Bool
a} :: GetRegions)

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

instance Prelude.NFData GetRegions

instance Core.ToHeaders GetRegions where
  toHeaders :: GetRegions -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetRegions -> 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
"Lightsail_20161128.GetRegions" ::
                          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 GetRegions where
  toJSON :: GetRegions -> Value
toJSON GetRegions' {Maybe Bool
includeAvailabilityZones :: Maybe Bool
includeRelationalDatabaseAvailabilityZones :: Maybe Bool
$sel:includeAvailabilityZones:GetRegions' :: GetRegions -> Maybe Bool
$sel:includeRelationalDatabaseAvailabilityZones:GetRegions' :: GetRegions -> Maybe Bool
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ ( Key
"includeRelationalDatabaseAvailabilityZones"
                Key -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Core..=
            )
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
includeRelationalDatabaseAvailabilityZones,
            (Key
"includeAvailabilityZones" Key -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
includeAvailabilityZones
          ]
      )

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

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

-- | /See:/ 'newGetRegionsResponse' smart constructor.
data GetRegionsResponse = GetRegionsResponse'
  { -- | An array of key-value pairs containing information about your get
    -- regions request.
    GetRegionsResponse -> Maybe [RegionInfo]
regions :: Prelude.Maybe [RegionInfo],
    -- | The response's http status code.
    GetRegionsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetRegionsResponse -> GetRegionsResponse -> Bool
(GetRegionsResponse -> GetRegionsResponse -> Bool)
-> (GetRegionsResponse -> GetRegionsResponse -> Bool)
-> Eq GetRegionsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetRegionsResponse -> GetRegionsResponse -> Bool
$c/= :: GetRegionsResponse -> GetRegionsResponse -> Bool
== :: GetRegionsResponse -> GetRegionsResponse -> Bool
$c== :: GetRegionsResponse -> GetRegionsResponse -> Bool
Prelude.Eq, ReadPrec [GetRegionsResponse]
ReadPrec GetRegionsResponse
Int -> ReadS GetRegionsResponse
ReadS [GetRegionsResponse]
(Int -> ReadS GetRegionsResponse)
-> ReadS [GetRegionsResponse]
-> ReadPrec GetRegionsResponse
-> ReadPrec [GetRegionsResponse]
-> Read GetRegionsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetRegionsResponse]
$creadListPrec :: ReadPrec [GetRegionsResponse]
readPrec :: ReadPrec GetRegionsResponse
$creadPrec :: ReadPrec GetRegionsResponse
readList :: ReadS [GetRegionsResponse]
$creadList :: ReadS [GetRegionsResponse]
readsPrec :: Int -> ReadS GetRegionsResponse
$creadsPrec :: Int -> ReadS GetRegionsResponse
Prelude.Read, Int -> GetRegionsResponse -> ShowS
[GetRegionsResponse] -> ShowS
GetRegionsResponse -> String
(Int -> GetRegionsResponse -> ShowS)
-> (GetRegionsResponse -> String)
-> ([GetRegionsResponse] -> ShowS)
-> Show GetRegionsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetRegionsResponse] -> ShowS
$cshowList :: [GetRegionsResponse] -> ShowS
show :: GetRegionsResponse -> String
$cshow :: GetRegionsResponse -> String
showsPrec :: Int -> GetRegionsResponse -> ShowS
$cshowsPrec :: Int -> GetRegionsResponse -> ShowS
Prelude.Show, (forall x. GetRegionsResponse -> Rep GetRegionsResponse x)
-> (forall x. Rep GetRegionsResponse x -> GetRegionsResponse)
-> Generic GetRegionsResponse
forall x. Rep GetRegionsResponse x -> GetRegionsResponse
forall x. GetRegionsResponse -> Rep GetRegionsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetRegionsResponse x -> GetRegionsResponse
$cfrom :: forall x. GetRegionsResponse -> Rep GetRegionsResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetRegionsResponse' 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:
--
-- 'regions', 'getRegionsResponse_regions' - An array of key-value pairs containing information about your get
-- regions request.
--
-- 'httpStatus', 'getRegionsResponse_httpStatus' - The response's http status code.
newGetRegionsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetRegionsResponse
newGetRegionsResponse :: Int -> GetRegionsResponse
newGetRegionsResponse Int
pHttpStatus_ =
  GetRegionsResponse' :: Maybe [RegionInfo] -> Int -> GetRegionsResponse
GetRegionsResponse'
    { $sel:regions:GetRegionsResponse' :: Maybe [RegionInfo]
regions = Maybe [RegionInfo]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetRegionsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array of key-value pairs containing information about your get
-- regions request.
getRegionsResponse_regions :: Lens.Lens' GetRegionsResponse (Prelude.Maybe [RegionInfo])
getRegionsResponse_regions :: (Maybe [RegionInfo] -> f (Maybe [RegionInfo]))
-> GetRegionsResponse -> f GetRegionsResponse
getRegionsResponse_regions = (GetRegionsResponse -> Maybe [RegionInfo])
-> (GetRegionsResponse -> Maybe [RegionInfo] -> GetRegionsResponse)
-> Lens
     GetRegionsResponse
     GetRegionsResponse
     (Maybe [RegionInfo])
     (Maybe [RegionInfo])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRegionsResponse' {Maybe [RegionInfo]
regions :: Maybe [RegionInfo]
$sel:regions:GetRegionsResponse' :: GetRegionsResponse -> Maybe [RegionInfo]
regions} -> Maybe [RegionInfo]
regions) (\s :: GetRegionsResponse
s@GetRegionsResponse' {} Maybe [RegionInfo]
a -> GetRegionsResponse
s {$sel:regions:GetRegionsResponse' :: Maybe [RegionInfo]
regions = Maybe [RegionInfo]
a} :: GetRegionsResponse) ((Maybe [RegionInfo] -> f (Maybe [RegionInfo]))
 -> GetRegionsResponse -> f GetRegionsResponse)
-> ((Maybe [RegionInfo] -> f (Maybe [RegionInfo]))
    -> Maybe [RegionInfo] -> f (Maybe [RegionInfo]))
-> (Maybe [RegionInfo] -> f (Maybe [RegionInfo]))
-> GetRegionsResponse
-> f GetRegionsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [RegionInfo] [RegionInfo] [RegionInfo] [RegionInfo]
-> Iso
     (Maybe [RegionInfo])
     (Maybe [RegionInfo])
     (Maybe [RegionInfo])
     (Maybe [RegionInfo])
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 [RegionInfo] [RegionInfo] [RegionInfo] [RegionInfo]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData GetRegionsResponse