{-# 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.CreateDistribution
-- 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)
--
-- Creates an Amazon Lightsail content delivery network (CDN) distribution.
--
-- A distribution is a globally distributed network of caching servers that
-- improve the performance of your website or web application hosted on a
-- Lightsail instance. For more information, see
-- <https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-content-delivery-network-distributions Content delivery networks in Amazon Lightsail>.
module Amazonka.Lightsail.CreateDistribution
  ( -- * Creating a Request
    CreateDistribution (..),
    newCreateDistribution,

    -- * Request Lenses
    createDistribution_cacheBehaviorSettings,
    createDistribution_ipAddressType,
    createDistribution_cacheBehaviors,
    createDistribution_tags,
    createDistribution_distributionName,
    createDistribution_origin,
    createDistribution_defaultCacheBehavior,
    createDistribution_bundleId,

    -- * Destructuring the Response
    CreateDistributionResponse (..),
    newCreateDistributionResponse,

    -- * Response Lenses
    createDistributionResponse_distribution,
    createDistributionResponse_operation,
    createDistributionResponse_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:/ 'newCreateDistribution' smart constructor.
data CreateDistribution = CreateDistribution'
  { -- | An object that describes the cache behavior settings for the
    -- distribution.
    CreateDistribution -> Maybe CacheSettings
cacheBehaviorSettings :: Prelude.Maybe CacheSettings,
    -- | The IP address type for the distribution.
    --
    -- The possible values are @ipv4@ for IPv4 only, and @dualstack@ for IPv4
    -- and IPv6.
    --
    -- The default value is @dualstack@.
    CreateDistribution -> Maybe IpAddressType
ipAddressType :: Prelude.Maybe IpAddressType,
    -- | An array of objects that describe the per-path cache behavior for the
    -- distribution.
    CreateDistribution -> Maybe [CacheBehaviorPerPath]
cacheBehaviors :: Prelude.Maybe [CacheBehaviorPerPath],
    -- | The tag keys and optional values to add to the distribution during
    -- create.
    --
    -- Use the @TagResource@ action to tag a resource after it\'s created.
    CreateDistribution -> Maybe [Tag]
tags :: Prelude.Maybe [Tag],
    -- | The name for the distribution.
    CreateDistribution -> Text
distributionName :: Prelude.Text,
    -- | An object that describes the origin resource for the distribution, such
    -- as a Lightsail instance or load balancer.
    --
    -- The distribution pulls, caches, and serves content from the origin.
    CreateDistribution -> InputOrigin
origin :: InputOrigin,
    -- | An object that describes the default cache behavior for the
    -- distribution.
    CreateDistribution -> CacheBehavior
defaultCacheBehavior :: CacheBehavior,
    -- | The bundle ID to use for the distribution.
    --
    -- A distribution bundle describes the specifications of your distribution,
    -- such as the monthly cost and monthly network transfer quota.
    --
    -- Use the @GetDistributionBundles@ action to get a list of distribution
    -- bundle IDs that you can specify.
    CreateDistribution -> Text
bundleId :: Prelude.Text
  }
  deriving (CreateDistribution -> CreateDistribution -> Bool
(CreateDistribution -> CreateDistribution -> Bool)
-> (CreateDistribution -> CreateDistribution -> Bool)
-> Eq CreateDistribution
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateDistribution -> CreateDistribution -> Bool
$c/= :: CreateDistribution -> CreateDistribution -> Bool
== :: CreateDistribution -> CreateDistribution -> Bool
$c== :: CreateDistribution -> CreateDistribution -> Bool
Prelude.Eq, ReadPrec [CreateDistribution]
ReadPrec CreateDistribution
Int -> ReadS CreateDistribution
ReadS [CreateDistribution]
(Int -> ReadS CreateDistribution)
-> ReadS [CreateDistribution]
-> ReadPrec CreateDistribution
-> ReadPrec [CreateDistribution]
-> Read CreateDistribution
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateDistribution]
$creadListPrec :: ReadPrec [CreateDistribution]
readPrec :: ReadPrec CreateDistribution
$creadPrec :: ReadPrec CreateDistribution
readList :: ReadS [CreateDistribution]
$creadList :: ReadS [CreateDistribution]
readsPrec :: Int -> ReadS CreateDistribution
$creadsPrec :: Int -> ReadS CreateDistribution
Prelude.Read, Int -> CreateDistribution -> ShowS
[CreateDistribution] -> ShowS
CreateDistribution -> String
(Int -> CreateDistribution -> ShowS)
-> (CreateDistribution -> String)
-> ([CreateDistribution] -> ShowS)
-> Show CreateDistribution
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateDistribution] -> ShowS
$cshowList :: [CreateDistribution] -> ShowS
show :: CreateDistribution -> String
$cshow :: CreateDistribution -> String
showsPrec :: Int -> CreateDistribution -> ShowS
$cshowsPrec :: Int -> CreateDistribution -> ShowS
Prelude.Show, (forall x. CreateDistribution -> Rep CreateDistribution x)
-> (forall x. Rep CreateDistribution x -> CreateDistribution)
-> Generic CreateDistribution
forall x. Rep CreateDistribution x -> CreateDistribution
forall x. CreateDistribution -> Rep CreateDistribution x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateDistribution x -> CreateDistribution
$cfrom :: forall x. CreateDistribution -> Rep CreateDistribution x
Prelude.Generic)

-- |
-- Create a value of 'CreateDistribution' 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:
--
-- 'cacheBehaviorSettings', 'createDistribution_cacheBehaviorSettings' - An object that describes the cache behavior settings for the
-- distribution.
--
-- 'ipAddressType', 'createDistribution_ipAddressType' - The IP address type for the distribution.
--
-- The possible values are @ipv4@ for IPv4 only, and @dualstack@ for IPv4
-- and IPv6.
--
-- The default value is @dualstack@.
--
-- 'cacheBehaviors', 'createDistribution_cacheBehaviors' - An array of objects that describe the per-path cache behavior for the
-- distribution.
--
-- 'tags', 'createDistribution_tags' - The tag keys and optional values to add to the distribution during
-- create.
--
-- Use the @TagResource@ action to tag a resource after it\'s created.
--
-- 'distributionName', 'createDistribution_distributionName' - The name for the distribution.
--
-- 'origin', 'createDistribution_origin' - An object that describes the origin resource for the distribution, such
-- as a Lightsail instance or load balancer.
--
-- The distribution pulls, caches, and serves content from the origin.
--
-- 'defaultCacheBehavior', 'createDistribution_defaultCacheBehavior' - An object that describes the default cache behavior for the
-- distribution.
--
-- 'bundleId', 'createDistribution_bundleId' - The bundle ID to use for the distribution.
--
-- A distribution bundle describes the specifications of your distribution,
-- such as the monthly cost and monthly network transfer quota.
--
-- Use the @GetDistributionBundles@ action to get a list of distribution
-- bundle IDs that you can specify.
newCreateDistribution ::
  -- | 'distributionName'
  Prelude.Text ->
  -- | 'origin'
  InputOrigin ->
  -- | 'defaultCacheBehavior'
  CacheBehavior ->
  -- | 'bundleId'
  Prelude.Text ->
  CreateDistribution
newCreateDistribution :: Text -> InputOrigin -> CacheBehavior -> Text -> CreateDistribution
newCreateDistribution
  Text
pDistributionName_
  InputOrigin
pOrigin_
  CacheBehavior
pDefaultCacheBehavior_
  Text
pBundleId_ =
    CreateDistribution' :: Maybe CacheSettings
-> Maybe IpAddressType
-> Maybe [CacheBehaviorPerPath]
-> Maybe [Tag]
-> Text
-> InputOrigin
-> CacheBehavior
-> Text
-> CreateDistribution
CreateDistribution'
      { $sel:cacheBehaviorSettings:CreateDistribution' :: Maybe CacheSettings
cacheBehaviorSettings =
          Maybe CacheSettings
forall a. Maybe a
Prelude.Nothing,
        $sel:ipAddressType:CreateDistribution' :: Maybe IpAddressType
ipAddressType = Maybe IpAddressType
forall a. Maybe a
Prelude.Nothing,
        $sel:cacheBehaviors:CreateDistribution' :: Maybe [CacheBehaviorPerPath]
cacheBehaviors = Maybe [CacheBehaviorPerPath]
forall a. Maybe a
Prelude.Nothing,
        $sel:tags:CreateDistribution' :: Maybe [Tag]
tags = Maybe [Tag]
forall a. Maybe a
Prelude.Nothing,
        $sel:distributionName:CreateDistribution' :: Text
distributionName = Text
pDistributionName_,
        $sel:origin:CreateDistribution' :: InputOrigin
origin = InputOrigin
pOrigin_,
        $sel:defaultCacheBehavior:CreateDistribution' :: CacheBehavior
defaultCacheBehavior = CacheBehavior
pDefaultCacheBehavior_,
        $sel:bundleId:CreateDistribution' :: Text
bundleId = Text
pBundleId_
      }

-- | An object that describes the cache behavior settings for the
-- distribution.
createDistribution_cacheBehaviorSettings :: Lens.Lens' CreateDistribution (Prelude.Maybe CacheSettings)
createDistribution_cacheBehaviorSettings :: (Maybe CacheSettings -> f (Maybe CacheSettings))
-> CreateDistribution -> f CreateDistribution
createDistribution_cacheBehaviorSettings = (CreateDistribution -> Maybe CacheSettings)
-> (CreateDistribution
    -> Maybe CacheSettings -> CreateDistribution)
-> Lens
     CreateDistribution
     CreateDistribution
     (Maybe CacheSettings)
     (Maybe CacheSettings)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDistribution' {Maybe CacheSettings
cacheBehaviorSettings :: Maybe CacheSettings
$sel:cacheBehaviorSettings:CreateDistribution' :: CreateDistribution -> Maybe CacheSettings
cacheBehaviorSettings} -> Maybe CacheSettings
cacheBehaviorSettings) (\s :: CreateDistribution
s@CreateDistribution' {} Maybe CacheSettings
a -> CreateDistribution
s {$sel:cacheBehaviorSettings:CreateDistribution' :: Maybe CacheSettings
cacheBehaviorSettings = Maybe CacheSettings
a} :: CreateDistribution)

-- | The IP address type for the distribution.
--
-- The possible values are @ipv4@ for IPv4 only, and @dualstack@ for IPv4
-- and IPv6.
--
-- The default value is @dualstack@.
createDistribution_ipAddressType :: Lens.Lens' CreateDistribution (Prelude.Maybe IpAddressType)
createDistribution_ipAddressType :: (Maybe IpAddressType -> f (Maybe IpAddressType))
-> CreateDistribution -> f CreateDistribution
createDistribution_ipAddressType = (CreateDistribution -> Maybe IpAddressType)
-> (CreateDistribution
    -> Maybe IpAddressType -> CreateDistribution)
-> Lens
     CreateDistribution
     CreateDistribution
     (Maybe IpAddressType)
     (Maybe IpAddressType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDistribution' {Maybe IpAddressType
ipAddressType :: Maybe IpAddressType
$sel:ipAddressType:CreateDistribution' :: CreateDistribution -> Maybe IpAddressType
ipAddressType} -> Maybe IpAddressType
ipAddressType) (\s :: CreateDistribution
s@CreateDistribution' {} Maybe IpAddressType
a -> CreateDistribution
s {$sel:ipAddressType:CreateDistribution' :: Maybe IpAddressType
ipAddressType = Maybe IpAddressType
a} :: CreateDistribution)

-- | An array of objects that describe the per-path cache behavior for the
-- distribution.
createDistribution_cacheBehaviors :: Lens.Lens' CreateDistribution (Prelude.Maybe [CacheBehaviorPerPath])
createDistribution_cacheBehaviors :: (Maybe [CacheBehaviorPerPath] -> f (Maybe [CacheBehaviorPerPath]))
-> CreateDistribution -> f CreateDistribution
createDistribution_cacheBehaviors = (CreateDistribution -> Maybe [CacheBehaviorPerPath])
-> (CreateDistribution
    -> Maybe [CacheBehaviorPerPath] -> CreateDistribution)
-> Lens
     CreateDistribution
     CreateDistribution
     (Maybe [CacheBehaviorPerPath])
     (Maybe [CacheBehaviorPerPath])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDistribution' {Maybe [CacheBehaviorPerPath]
cacheBehaviors :: Maybe [CacheBehaviorPerPath]
$sel:cacheBehaviors:CreateDistribution' :: CreateDistribution -> Maybe [CacheBehaviorPerPath]
cacheBehaviors} -> Maybe [CacheBehaviorPerPath]
cacheBehaviors) (\s :: CreateDistribution
s@CreateDistribution' {} Maybe [CacheBehaviorPerPath]
a -> CreateDistribution
s {$sel:cacheBehaviors:CreateDistribution' :: Maybe [CacheBehaviorPerPath]
cacheBehaviors = Maybe [CacheBehaviorPerPath]
a} :: CreateDistribution) ((Maybe [CacheBehaviorPerPath] -> f (Maybe [CacheBehaviorPerPath]))
 -> CreateDistribution -> f CreateDistribution)
-> ((Maybe [CacheBehaviorPerPath]
     -> f (Maybe [CacheBehaviorPerPath]))
    -> Maybe [CacheBehaviorPerPath]
    -> f (Maybe [CacheBehaviorPerPath]))
-> (Maybe [CacheBehaviorPerPath]
    -> f (Maybe [CacheBehaviorPerPath]))
-> CreateDistribution
-> f CreateDistribution
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [CacheBehaviorPerPath]
  [CacheBehaviorPerPath]
  [CacheBehaviorPerPath]
  [CacheBehaviorPerPath]
-> Iso
     (Maybe [CacheBehaviorPerPath])
     (Maybe [CacheBehaviorPerPath])
     (Maybe [CacheBehaviorPerPath])
     (Maybe [CacheBehaviorPerPath])
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
  [CacheBehaviorPerPath]
  [CacheBehaviorPerPath]
  [CacheBehaviorPerPath]
  [CacheBehaviorPerPath]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The tag keys and optional values to add to the distribution during
-- create.
--
-- Use the @TagResource@ action to tag a resource after it\'s created.
createDistribution_tags :: Lens.Lens' CreateDistribution (Prelude.Maybe [Tag])
createDistribution_tags :: (Maybe [Tag] -> f (Maybe [Tag]))
-> CreateDistribution -> f CreateDistribution
createDistribution_tags = (CreateDistribution -> Maybe [Tag])
-> (CreateDistribution -> Maybe [Tag] -> CreateDistribution)
-> Lens
     CreateDistribution CreateDistribution (Maybe [Tag]) (Maybe [Tag])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDistribution' {Maybe [Tag]
tags :: Maybe [Tag]
$sel:tags:CreateDistribution' :: CreateDistribution -> Maybe [Tag]
tags} -> Maybe [Tag]
tags) (\s :: CreateDistribution
s@CreateDistribution' {} Maybe [Tag]
a -> CreateDistribution
s {$sel:tags:CreateDistribution' :: Maybe [Tag]
tags = Maybe [Tag]
a} :: CreateDistribution) ((Maybe [Tag] -> f (Maybe [Tag]))
 -> CreateDistribution -> f CreateDistribution)
-> ((Maybe [Tag] -> f (Maybe [Tag]))
    -> Maybe [Tag] -> f (Maybe [Tag]))
-> (Maybe [Tag] -> f (Maybe [Tag]))
-> CreateDistribution
-> f CreateDistribution
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Tag] [Tag] [Tag] [Tag]
-> Iso (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag])
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 [Tag] [Tag] [Tag] [Tag]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name for the distribution.
createDistribution_distributionName :: Lens.Lens' CreateDistribution Prelude.Text
createDistribution_distributionName :: (Text -> f Text) -> CreateDistribution -> f CreateDistribution
createDistribution_distributionName = (CreateDistribution -> Text)
-> (CreateDistribution -> Text -> CreateDistribution)
-> Lens CreateDistribution CreateDistribution Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDistribution' {Text
distributionName :: Text
$sel:distributionName:CreateDistribution' :: CreateDistribution -> Text
distributionName} -> Text
distributionName) (\s :: CreateDistribution
s@CreateDistribution' {} Text
a -> CreateDistribution
s {$sel:distributionName:CreateDistribution' :: Text
distributionName = Text
a} :: CreateDistribution)

-- | An object that describes the origin resource for the distribution, such
-- as a Lightsail instance or load balancer.
--
-- The distribution pulls, caches, and serves content from the origin.
createDistribution_origin :: Lens.Lens' CreateDistribution InputOrigin
createDistribution_origin :: (InputOrigin -> f InputOrigin)
-> CreateDistribution -> f CreateDistribution
createDistribution_origin = (CreateDistribution -> InputOrigin)
-> (CreateDistribution -> InputOrigin -> CreateDistribution)
-> Lens
     CreateDistribution CreateDistribution InputOrigin InputOrigin
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDistribution' {InputOrigin
origin :: InputOrigin
$sel:origin:CreateDistribution' :: CreateDistribution -> InputOrigin
origin} -> InputOrigin
origin) (\s :: CreateDistribution
s@CreateDistribution' {} InputOrigin
a -> CreateDistribution
s {$sel:origin:CreateDistribution' :: InputOrigin
origin = InputOrigin
a} :: CreateDistribution)

-- | An object that describes the default cache behavior for the
-- distribution.
createDistribution_defaultCacheBehavior :: Lens.Lens' CreateDistribution CacheBehavior
createDistribution_defaultCacheBehavior :: (CacheBehavior -> f CacheBehavior)
-> CreateDistribution -> f CreateDistribution
createDistribution_defaultCacheBehavior = (CreateDistribution -> CacheBehavior)
-> (CreateDistribution -> CacheBehavior -> CreateDistribution)
-> Lens
     CreateDistribution CreateDistribution CacheBehavior CacheBehavior
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDistribution' {CacheBehavior
defaultCacheBehavior :: CacheBehavior
$sel:defaultCacheBehavior:CreateDistribution' :: CreateDistribution -> CacheBehavior
defaultCacheBehavior} -> CacheBehavior
defaultCacheBehavior) (\s :: CreateDistribution
s@CreateDistribution' {} CacheBehavior
a -> CreateDistribution
s {$sel:defaultCacheBehavior:CreateDistribution' :: CacheBehavior
defaultCacheBehavior = CacheBehavior
a} :: CreateDistribution)

-- | The bundle ID to use for the distribution.
--
-- A distribution bundle describes the specifications of your distribution,
-- such as the monthly cost and monthly network transfer quota.
--
-- Use the @GetDistributionBundles@ action to get a list of distribution
-- bundle IDs that you can specify.
createDistribution_bundleId :: Lens.Lens' CreateDistribution Prelude.Text
createDistribution_bundleId :: (Text -> f Text) -> CreateDistribution -> f CreateDistribution
createDistribution_bundleId = (CreateDistribution -> Text)
-> (CreateDistribution -> Text -> CreateDistribution)
-> Lens CreateDistribution CreateDistribution Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDistribution' {Text
bundleId :: Text
$sel:bundleId:CreateDistribution' :: CreateDistribution -> Text
bundleId} -> Text
bundleId) (\s :: CreateDistribution
s@CreateDistribution' {} Text
a -> CreateDistribution
s {$sel:bundleId:CreateDistribution' :: Text
bundleId = Text
a} :: CreateDistribution)

instance Core.AWSRequest CreateDistribution where
  type
    AWSResponse CreateDistribution =
      CreateDistributionResponse
  request :: CreateDistribution -> Request CreateDistribution
request = Service -> CreateDistribution -> Request CreateDistribution
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateDistribution
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateDistribution)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateDistribution))
-> Logger
-> Service
-> Proxy CreateDistribution
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateDistribution)))
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 LightsailDistribution
-> Maybe Operation -> Int -> CreateDistributionResponse
CreateDistributionResponse'
            (Maybe LightsailDistribution
 -> Maybe Operation -> Int -> CreateDistributionResponse)
-> Either String (Maybe LightsailDistribution)
-> Either
     String (Maybe Operation -> Int -> CreateDistributionResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe LightsailDistribution)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"distribution")
            Either
  String (Maybe Operation -> Int -> CreateDistributionResponse)
-> Either String (Maybe Operation)
-> Either String (Int -> CreateDistributionResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Operation)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"operation")
            Either String (Int -> CreateDistributionResponse)
-> Either String Int -> Either String CreateDistributionResponse
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 CreateDistribution

instance Prelude.NFData CreateDistribution

instance Core.ToHeaders CreateDistribution where
  toHeaders :: CreateDistribution -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateDistribution -> 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.CreateDistribution" ::
                          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 CreateDistribution where
  toJSON :: CreateDistribution -> Value
toJSON CreateDistribution' {Maybe [CacheBehaviorPerPath]
Maybe [Tag]
Maybe IpAddressType
Maybe CacheSettings
Text
CacheBehavior
InputOrigin
bundleId :: Text
defaultCacheBehavior :: CacheBehavior
origin :: InputOrigin
distributionName :: Text
tags :: Maybe [Tag]
cacheBehaviors :: Maybe [CacheBehaviorPerPath]
ipAddressType :: Maybe IpAddressType
cacheBehaviorSettings :: Maybe CacheSettings
$sel:bundleId:CreateDistribution' :: CreateDistribution -> Text
$sel:defaultCacheBehavior:CreateDistribution' :: CreateDistribution -> CacheBehavior
$sel:origin:CreateDistribution' :: CreateDistribution -> InputOrigin
$sel:distributionName:CreateDistribution' :: CreateDistribution -> Text
$sel:tags:CreateDistribution' :: CreateDistribution -> Maybe [Tag]
$sel:cacheBehaviors:CreateDistribution' :: CreateDistribution -> Maybe [CacheBehaviorPerPath]
$sel:ipAddressType:CreateDistribution' :: CreateDistribution -> Maybe IpAddressType
$sel:cacheBehaviorSettings:CreateDistribution' :: CreateDistribution -> Maybe CacheSettings
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"cacheBehaviorSettings" Text -> CacheSettings -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (CacheSettings -> Pair) -> Maybe CacheSettings -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe CacheSettings
cacheBehaviorSettings,
            (Text
"ipAddressType" Text -> IpAddressType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (IpAddressType -> Pair) -> Maybe IpAddressType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe IpAddressType
ipAddressType,
            (Text
"cacheBehaviors" Text -> [CacheBehaviorPerPath] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([CacheBehaviorPerPath] -> Pair)
-> Maybe [CacheBehaviorPerPath] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [CacheBehaviorPerPath]
cacheBehaviors,
            (Text
"tags" Text -> [Tag] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Tag] -> Pair) -> Maybe [Tag] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Tag]
tags,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"distributionName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
distributionName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"origin" Text -> InputOrigin -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= InputOrigin
origin),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"defaultCacheBehavior"
                  Text -> CacheBehavior -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= CacheBehavior
defaultCacheBehavior
              ),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"bundleId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
bundleId)
          ]
      )

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

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

-- | /See:/ 'newCreateDistributionResponse' smart constructor.
data CreateDistributionResponse = CreateDistributionResponse'
  { -- | An object that describes the distribution created.
    CreateDistributionResponse -> Maybe LightsailDistribution
distribution :: Prelude.Maybe LightsailDistribution,
    -- | An array of objects that describe the result of the action, such as the
    -- status of the request, the timestamp of the request, and the resources
    -- affected by the request.
    CreateDistributionResponse -> Maybe Operation
operation :: Prelude.Maybe Operation,
    -- | The response's http status code.
    CreateDistributionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateDistributionResponse -> CreateDistributionResponse -> Bool
(CreateDistributionResponse -> CreateDistributionResponse -> Bool)
-> (CreateDistributionResponse
    -> CreateDistributionResponse -> Bool)
-> Eq CreateDistributionResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateDistributionResponse -> CreateDistributionResponse -> Bool
$c/= :: CreateDistributionResponse -> CreateDistributionResponse -> Bool
== :: CreateDistributionResponse -> CreateDistributionResponse -> Bool
$c== :: CreateDistributionResponse -> CreateDistributionResponse -> Bool
Prelude.Eq, ReadPrec [CreateDistributionResponse]
ReadPrec CreateDistributionResponse
Int -> ReadS CreateDistributionResponse
ReadS [CreateDistributionResponse]
(Int -> ReadS CreateDistributionResponse)
-> ReadS [CreateDistributionResponse]
-> ReadPrec CreateDistributionResponse
-> ReadPrec [CreateDistributionResponse]
-> Read CreateDistributionResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateDistributionResponse]
$creadListPrec :: ReadPrec [CreateDistributionResponse]
readPrec :: ReadPrec CreateDistributionResponse
$creadPrec :: ReadPrec CreateDistributionResponse
readList :: ReadS [CreateDistributionResponse]
$creadList :: ReadS [CreateDistributionResponse]
readsPrec :: Int -> ReadS CreateDistributionResponse
$creadsPrec :: Int -> ReadS CreateDistributionResponse
Prelude.Read, Int -> CreateDistributionResponse -> ShowS
[CreateDistributionResponse] -> ShowS
CreateDistributionResponse -> String
(Int -> CreateDistributionResponse -> ShowS)
-> (CreateDistributionResponse -> String)
-> ([CreateDistributionResponse] -> ShowS)
-> Show CreateDistributionResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateDistributionResponse] -> ShowS
$cshowList :: [CreateDistributionResponse] -> ShowS
show :: CreateDistributionResponse -> String
$cshow :: CreateDistributionResponse -> String
showsPrec :: Int -> CreateDistributionResponse -> ShowS
$cshowsPrec :: Int -> CreateDistributionResponse -> ShowS
Prelude.Show, (forall x.
 CreateDistributionResponse -> Rep CreateDistributionResponse x)
-> (forall x.
    Rep CreateDistributionResponse x -> CreateDistributionResponse)
-> Generic CreateDistributionResponse
forall x.
Rep CreateDistributionResponse x -> CreateDistributionResponse
forall x.
CreateDistributionResponse -> Rep CreateDistributionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateDistributionResponse x -> CreateDistributionResponse
$cfrom :: forall x.
CreateDistributionResponse -> Rep CreateDistributionResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateDistributionResponse' 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:
--
-- 'distribution', 'createDistributionResponse_distribution' - An object that describes the distribution created.
--
-- 'operation', 'createDistributionResponse_operation' - An array of objects that describe the result of the action, such as the
-- status of the request, the timestamp of the request, and the resources
-- affected by the request.
--
-- 'httpStatus', 'createDistributionResponse_httpStatus' - The response's http status code.
newCreateDistributionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateDistributionResponse
newCreateDistributionResponse :: Int -> CreateDistributionResponse
newCreateDistributionResponse Int
pHttpStatus_ =
  CreateDistributionResponse' :: Maybe LightsailDistribution
-> Maybe Operation -> Int -> CreateDistributionResponse
CreateDistributionResponse'
    { $sel:distribution:CreateDistributionResponse' :: Maybe LightsailDistribution
distribution =
        Maybe LightsailDistribution
forall a. Maybe a
Prelude.Nothing,
      $sel:operation:CreateDistributionResponse' :: Maybe Operation
operation = Maybe Operation
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateDistributionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An object that describes the distribution created.
createDistributionResponse_distribution :: Lens.Lens' CreateDistributionResponse (Prelude.Maybe LightsailDistribution)
createDistributionResponse_distribution :: (Maybe LightsailDistribution -> f (Maybe LightsailDistribution))
-> CreateDistributionResponse -> f CreateDistributionResponse
createDistributionResponse_distribution = (CreateDistributionResponse -> Maybe LightsailDistribution)
-> (CreateDistributionResponse
    -> Maybe LightsailDistribution -> CreateDistributionResponse)
-> Lens
     CreateDistributionResponse
     CreateDistributionResponse
     (Maybe LightsailDistribution)
     (Maybe LightsailDistribution)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDistributionResponse' {Maybe LightsailDistribution
distribution :: Maybe LightsailDistribution
$sel:distribution:CreateDistributionResponse' :: CreateDistributionResponse -> Maybe LightsailDistribution
distribution} -> Maybe LightsailDistribution
distribution) (\s :: CreateDistributionResponse
s@CreateDistributionResponse' {} Maybe LightsailDistribution
a -> CreateDistributionResponse
s {$sel:distribution:CreateDistributionResponse' :: Maybe LightsailDistribution
distribution = Maybe LightsailDistribution
a} :: CreateDistributionResponse)

-- | An array of objects that describe the result of the action, such as the
-- status of the request, the timestamp of the request, and the resources
-- affected by the request.
createDistributionResponse_operation :: Lens.Lens' CreateDistributionResponse (Prelude.Maybe Operation)
createDistributionResponse_operation :: (Maybe Operation -> f (Maybe Operation))
-> CreateDistributionResponse -> f CreateDistributionResponse
createDistributionResponse_operation = (CreateDistributionResponse -> Maybe Operation)
-> (CreateDistributionResponse
    -> Maybe Operation -> CreateDistributionResponse)
-> Lens
     CreateDistributionResponse
     CreateDistributionResponse
     (Maybe Operation)
     (Maybe Operation)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDistributionResponse' {Maybe Operation
operation :: Maybe Operation
$sel:operation:CreateDistributionResponse' :: CreateDistributionResponse -> Maybe Operation
operation} -> Maybe Operation
operation) (\s :: CreateDistributionResponse
s@CreateDistributionResponse' {} Maybe Operation
a -> CreateDistributionResponse
s {$sel:operation:CreateDistributionResponse' :: Maybe Operation
operation = Maybe Operation
a} :: CreateDistributionResponse)

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

instance Prelude.NFData CreateDistributionResponse