{-# 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.GetDistributions
-- 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 information about one or more of your Amazon Lightsail content
-- delivery network (CDN) distributions.
module Amazonka.Lightsail.GetDistributions
  ( -- * Creating a Request
    GetDistributions (..),
    newGetDistributions,

    -- * Request Lenses
    getDistributions_distributionName,
    getDistributions_pageToken,

    -- * Destructuring the Response
    GetDistributionsResponse (..),
    newGetDistributionsResponse,

    -- * Response Lenses
    getDistributionsResponse_distributions,
    getDistributionsResponse_nextPageToken,
    getDistributionsResponse_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:/ 'newGetDistributions' smart constructor.
data GetDistributions = GetDistributions'
  { -- | The name of the distribution for which to return information.
    --
    -- When omitted, the response includes all of your distributions in the
    -- Amazon Web Services Region where the request is made.
    GetDistributions -> Maybe Text
distributionName :: Prelude.Maybe Prelude.Text,
    -- | The token to advance to the next page of results from your request.
    --
    -- To get a page token, perform an initial @GetDistributions@ request. If
    -- your results are paginated, the response will return a next page token
    -- that you can specify as the page token in a subsequent request.
    GetDistributions -> Maybe Text
pageToken :: Prelude.Maybe Prelude.Text
  }
  deriving (GetDistributions -> GetDistributions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetDistributions -> GetDistributions -> Bool
$c/= :: GetDistributions -> GetDistributions -> Bool
== :: GetDistributions -> GetDistributions -> Bool
$c== :: GetDistributions -> GetDistributions -> Bool
Prelude.Eq, ReadPrec [GetDistributions]
ReadPrec GetDistributions
Int -> ReadS GetDistributions
ReadS [GetDistributions]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetDistributions]
$creadListPrec :: ReadPrec [GetDistributions]
readPrec :: ReadPrec GetDistributions
$creadPrec :: ReadPrec GetDistributions
readList :: ReadS [GetDistributions]
$creadList :: ReadS [GetDistributions]
readsPrec :: Int -> ReadS GetDistributions
$creadsPrec :: Int -> ReadS GetDistributions
Prelude.Read, Int -> GetDistributions -> ShowS
[GetDistributions] -> ShowS
GetDistributions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetDistributions] -> ShowS
$cshowList :: [GetDistributions] -> ShowS
show :: GetDistributions -> String
$cshow :: GetDistributions -> String
showsPrec :: Int -> GetDistributions -> ShowS
$cshowsPrec :: Int -> GetDistributions -> ShowS
Prelude.Show, forall x. Rep GetDistributions x -> GetDistributions
forall x. GetDistributions -> Rep GetDistributions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetDistributions x -> GetDistributions
$cfrom :: forall x. GetDistributions -> Rep GetDistributions x
Prelude.Generic)

-- |
-- Create a value of 'GetDistributions' 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:
--
-- 'distributionName', 'getDistributions_distributionName' - The name of the distribution for which to return information.
--
-- When omitted, the response includes all of your distributions in the
-- Amazon Web Services Region where the request is made.
--
-- 'pageToken', 'getDistributions_pageToken' - The token to advance to the next page of results from your request.
--
-- To get a page token, perform an initial @GetDistributions@ request. If
-- your results are paginated, the response will return a next page token
-- that you can specify as the page token in a subsequent request.
newGetDistributions ::
  GetDistributions
newGetDistributions :: GetDistributions
newGetDistributions =
  GetDistributions'
    { $sel:distributionName:GetDistributions' :: Maybe Text
distributionName =
        forall a. Maybe a
Prelude.Nothing,
      $sel:pageToken:GetDistributions' :: Maybe Text
pageToken = forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the distribution for which to return information.
--
-- When omitted, the response includes all of your distributions in the
-- Amazon Web Services Region where the request is made.
getDistributions_distributionName :: Lens.Lens' GetDistributions (Prelude.Maybe Prelude.Text)
getDistributions_distributionName :: Lens' GetDistributions (Maybe Text)
getDistributions_distributionName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDistributions' {Maybe Text
distributionName :: Maybe Text
$sel:distributionName:GetDistributions' :: GetDistributions -> Maybe Text
distributionName} -> Maybe Text
distributionName) (\s :: GetDistributions
s@GetDistributions' {} Maybe Text
a -> GetDistributions
s {$sel:distributionName:GetDistributions' :: Maybe Text
distributionName = Maybe Text
a} :: GetDistributions)

-- | The token to advance to the next page of results from your request.
--
-- To get a page token, perform an initial @GetDistributions@ request. If
-- your results are paginated, the response will return a next page token
-- that you can specify as the page token in a subsequent request.
getDistributions_pageToken :: Lens.Lens' GetDistributions (Prelude.Maybe Prelude.Text)
getDistributions_pageToken :: Lens' GetDistributions (Maybe Text)
getDistributions_pageToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDistributions' {Maybe Text
pageToken :: Maybe Text
$sel:pageToken:GetDistributions' :: GetDistributions -> Maybe Text
pageToken} -> Maybe Text
pageToken) (\s :: GetDistributions
s@GetDistributions' {} Maybe Text
a -> GetDistributions
s {$sel:pageToken:GetDistributions' :: Maybe Text
pageToken = Maybe Text
a} :: GetDistributions)

instance Core.AWSRequest GetDistributions where
  type
    AWSResponse GetDistributions =
      GetDistributionsResponse
  request :: (Service -> Service)
-> GetDistributions -> Request GetDistributions
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 GetDistributions
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetDistributions)))
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 [LightsailDistribution]
-> Maybe Text -> Int -> GetDistributionsResponse
GetDistributionsResponse'
            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
"distributions" 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.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"nextPageToken")
            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 GetDistributions where
  hashWithSalt :: Int -> GetDistributions -> Int
hashWithSalt Int
_salt GetDistributions' {Maybe Text
pageToken :: Maybe Text
distributionName :: Maybe Text
$sel:pageToken:GetDistributions' :: GetDistributions -> Maybe Text
$sel:distributionName:GetDistributions' :: GetDistributions -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
distributionName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
pageToken

instance Prelude.NFData GetDistributions where
  rnf :: GetDistributions -> ()
rnf GetDistributions' {Maybe Text
pageToken :: Maybe Text
distributionName :: Maybe Text
$sel:pageToken:GetDistributions' :: GetDistributions -> Maybe Text
$sel:distributionName:GetDistributions' :: GetDistributions -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
distributionName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
pageToken

instance Data.ToHeaders GetDistributions where
  toHeaders :: GetDistributions -> 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.GetDistributions" ::
                          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 GetDistributions where
  toJSON :: GetDistributions -> Value
toJSON GetDistributions' {Maybe Text
pageToken :: Maybe Text
distributionName :: Maybe Text
$sel:pageToken:GetDistributions' :: GetDistributions -> Maybe Text
$sel:distributionName:GetDistributions' :: GetDistributions -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"distributionName" 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 Text
distributionName,
            (Key
"pageToken" 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 Text
pageToken
          ]
      )

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

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

-- | /See:/ 'newGetDistributionsResponse' smart constructor.
data GetDistributionsResponse = GetDistributionsResponse'
  { -- | An array of objects that describe your distributions.
    GetDistributionsResponse -> Maybe [LightsailDistribution]
distributions :: Prelude.Maybe [LightsailDistribution],
    -- | The token to advance to the next page of results from your request.
    --
    -- A next page token is not returned if there are no more results to
    -- display.
    --
    -- To get the next page of results, perform another @GetDistributions@
    -- request and specify the next page token using the @pageToken@ parameter.
    GetDistributionsResponse -> Maybe Text
nextPageToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetDistributionsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetDistributionsResponse -> GetDistributionsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetDistributionsResponse -> GetDistributionsResponse -> Bool
$c/= :: GetDistributionsResponse -> GetDistributionsResponse -> Bool
== :: GetDistributionsResponse -> GetDistributionsResponse -> Bool
$c== :: GetDistributionsResponse -> GetDistributionsResponse -> Bool
Prelude.Eq, ReadPrec [GetDistributionsResponse]
ReadPrec GetDistributionsResponse
Int -> ReadS GetDistributionsResponse
ReadS [GetDistributionsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetDistributionsResponse]
$creadListPrec :: ReadPrec [GetDistributionsResponse]
readPrec :: ReadPrec GetDistributionsResponse
$creadPrec :: ReadPrec GetDistributionsResponse
readList :: ReadS [GetDistributionsResponse]
$creadList :: ReadS [GetDistributionsResponse]
readsPrec :: Int -> ReadS GetDistributionsResponse
$creadsPrec :: Int -> ReadS GetDistributionsResponse
Prelude.Read, Int -> GetDistributionsResponse -> ShowS
[GetDistributionsResponse] -> ShowS
GetDistributionsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetDistributionsResponse] -> ShowS
$cshowList :: [GetDistributionsResponse] -> ShowS
show :: GetDistributionsResponse -> String
$cshow :: GetDistributionsResponse -> String
showsPrec :: Int -> GetDistributionsResponse -> ShowS
$cshowsPrec :: Int -> GetDistributionsResponse -> ShowS
Prelude.Show, forall x.
Rep GetDistributionsResponse x -> GetDistributionsResponse
forall x.
GetDistributionsResponse -> Rep GetDistributionsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetDistributionsResponse x -> GetDistributionsResponse
$cfrom :: forall x.
GetDistributionsResponse -> Rep GetDistributionsResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetDistributionsResponse' 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:
--
-- 'distributions', 'getDistributionsResponse_distributions' - An array of objects that describe your distributions.
--
-- 'nextPageToken', 'getDistributionsResponse_nextPageToken' - The token to advance to the next page of results from your request.
--
-- A next page token is not returned if there are no more results to
-- display.
--
-- To get the next page of results, perform another @GetDistributions@
-- request and specify the next page token using the @pageToken@ parameter.
--
-- 'httpStatus', 'getDistributionsResponse_httpStatus' - The response's http status code.
newGetDistributionsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetDistributionsResponse
newGetDistributionsResponse :: Int -> GetDistributionsResponse
newGetDistributionsResponse Int
pHttpStatus_ =
  GetDistributionsResponse'
    { $sel:distributions:GetDistributionsResponse' :: Maybe [LightsailDistribution]
distributions =
        forall a. Maybe a
Prelude.Nothing,
      $sel:nextPageToken:GetDistributionsResponse' :: Maybe Text
nextPageToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetDistributionsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array of objects that describe your distributions.
getDistributionsResponse_distributions :: Lens.Lens' GetDistributionsResponse (Prelude.Maybe [LightsailDistribution])
getDistributionsResponse_distributions :: Lens' GetDistributionsResponse (Maybe [LightsailDistribution])
getDistributionsResponse_distributions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDistributionsResponse' {Maybe [LightsailDistribution]
distributions :: Maybe [LightsailDistribution]
$sel:distributions:GetDistributionsResponse' :: GetDistributionsResponse -> Maybe [LightsailDistribution]
distributions} -> Maybe [LightsailDistribution]
distributions) (\s :: GetDistributionsResponse
s@GetDistributionsResponse' {} Maybe [LightsailDistribution]
a -> GetDistributionsResponse
s {$sel:distributions:GetDistributionsResponse' :: Maybe [LightsailDistribution]
distributions = Maybe [LightsailDistribution]
a} :: GetDistributionsResponse) 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 token to advance to the next page of results from your request.
--
-- A next page token is not returned if there are no more results to
-- display.
--
-- To get the next page of results, perform another @GetDistributions@
-- request and specify the next page token using the @pageToken@ parameter.
getDistributionsResponse_nextPageToken :: Lens.Lens' GetDistributionsResponse (Prelude.Maybe Prelude.Text)
getDistributionsResponse_nextPageToken :: Lens' GetDistributionsResponse (Maybe Text)
getDistributionsResponse_nextPageToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDistributionsResponse' {Maybe Text
nextPageToken :: Maybe Text
$sel:nextPageToken:GetDistributionsResponse' :: GetDistributionsResponse -> Maybe Text
nextPageToken} -> Maybe Text
nextPageToken) (\s :: GetDistributionsResponse
s@GetDistributionsResponse' {} Maybe Text
a -> GetDistributionsResponse
s {$sel:nextPageToken:GetDistributionsResponse' :: Maybe Text
nextPageToken = Maybe Text
a} :: GetDistributionsResponse)

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

instance Prelude.NFData GetDistributionsResponse where
  rnf :: GetDistributionsResponse -> ()
rnf GetDistributionsResponse' {Int
Maybe [LightsailDistribution]
Maybe Text
httpStatus :: Int
nextPageToken :: Maybe Text
distributions :: Maybe [LightsailDistribution]
$sel:httpStatus:GetDistributionsResponse' :: GetDistributionsResponse -> Int
$sel:nextPageToken:GetDistributionsResponse' :: GetDistributionsResponse -> Maybe Text
$sel:distributions:GetDistributionsResponse' :: GetDistributionsResponse -> Maybe [LightsailDistribution]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [LightsailDistribution]
distributions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextPageToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus