{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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_includeAvailabilityZones,
    getRegions_includeRelationalDatabaseAvailabilityZones,

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

    -- * Response Lenses
    getRegionsResponse_regions,
    getRegionsResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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 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,
    -- | 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
  }
  deriving (GetRegions -> GetRegions -> Bool
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]
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
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. 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:
--
-- '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@.
--
-- '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@).
newGetRegions ::
  GetRegions
newGetRegions :: GetRegions
newGetRegions =
  GetRegions'
    { $sel:includeAvailabilityZones:GetRegions' :: Maybe Bool
includeAvailabilityZones =
        forall a. Maybe a
Prelude.Nothing,
      $sel:includeRelationalDatabaseAvailabilityZones:GetRegions' :: Maybe Bool
includeRelationalDatabaseAvailabilityZones =
        forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: Lens' GetRegions (Maybe Bool)
getRegions_includeAvailabilityZones = 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)

-- | 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 :: Lens' GetRegions (Maybe Bool)
getRegions_includeRelationalDatabaseAvailabilityZones = 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)

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

instance Prelude.Hashable GetRegions where
  hashWithSalt :: Int -> GetRegions -> Int
hashWithSalt Int
_salt GetRegions' {Maybe Bool
includeRelationalDatabaseAvailabilityZones :: Maybe Bool
includeAvailabilityZones :: Maybe Bool
$sel:includeRelationalDatabaseAvailabilityZones:GetRegions' :: GetRegions -> Maybe Bool
$sel:includeAvailabilityZones:GetRegions' :: GetRegions -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
includeAvailabilityZones
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
includeRelationalDatabaseAvailabilityZones

instance Prelude.NFData GetRegions where
  rnf :: GetRegions -> ()
rnf GetRegions' {Maybe Bool
includeRelationalDatabaseAvailabilityZones :: Maybe Bool
includeAvailabilityZones :: Maybe Bool
$sel:includeRelationalDatabaseAvailabilityZones:GetRegions' :: GetRegions -> Maybe Bool
$sel:includeAvailabilityZones:GetRegions' :: GetRegions -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
includeAvailabilityZones
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf
        Maybe Bool
includeRelationalDatabaseAvailabilityZones

instance Data.ToHeaders GetRegions where
  toHeaders :: GetRegions -> 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
"Lightsail_20161128.GetRegions" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON GetRegions where
  toJSON :: GetRegions -> Value
toJSON GetRegions' {Maybe Bool
includeRelationalDatabaseAvailabilityZones :: Maybe Bool
includeAvailabilityZones :: Maybe Bool
$sel:includeRelationalDatabaseAvailabilityZones:GetRegions' :: GetRegions -> Maybe Bool
$sel:includeAvailabilityZones:GetRegions' :: GetRegions -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"includeAvailabilityZones" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
includeAvailabilityZones,
            ( Key
"includeRelationalDatabaseAvailabilityZones"
                forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=
            )
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
includeRelationalDatabaseAvailabilityZones
          ]
      )

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

instance Data.ToQuery GetRegions where
  toQuery :: GetRegions -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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. 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'
    { $sel:regions:GetRegionsResponse' :: Maybe [RegionInfo]
regions = 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 :: Lens' GetRegionsResponse (Maybe [RegionInfo])
getRegionsResponse_regions = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 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 :: Lens' GetRegionsResponse Int
getRegionsResponse_httpStatus = 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 where
  rnf :: GetRegionsResponse -> ()
rnf GetRegionsResponse' {Int
Maybe [RegionInfo]
httpStatus :: Int
regions :: Maybe [RegionInfo]
$sel:httpStatus:GetRegionsResponse' :: GetRegionsResponse -> Int
$sel:regions:GetRegionsResponse' :: GetRegionsResponse -> Maybe [RegionInfo]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [RegionInfo]
regions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus