{-# 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.CloudFront.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 a new web distribution. You create a CloudFront distribution to
-- tell CloudFront where you want content to be delivered from, and the
-- details about how to track and manage content delivery. Send a @POST@
-- request to the
-- @\/CloudFront API version\/distribution@\/@distribution ID@ resource.
--
-- When you update a distribution, there are more required fields than when
-- you create a distribution. When you update your distribution by using
-- <https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_UpdateDistribution.html UpdateDistribution>,
-- follow the steps included in the documentation to get the current
-- configuration and then make your updates. This helps to make sure that
-- you include all of the required fields. To view a summary, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-overview-required-fields.html Required Fields for Create Distribution and Update Distribution>
-- in the /Amazon CloudFront Developer Guide/.
module Amazonka.CloudFront.CreateDistribution
  ( -- * Creating a Request
    CreateDistribution (..),
    newCreateDistribution,

    -- * Request Lenses
    createDistribution_distributionConfig,

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

    -- * Response Lenses
    createDistributionResponse_eTag,
    createDistributionResponse_distribution,
    createDistributionResponse_location,
    createDistributionResponse_httpStatus,
  )
where

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

-- | The request to create a new distribution.
--
-- /See:/ 'newCreateDistribution' smart constructor.
data CreateDistribution = CreateDistribution'
  { -- | The distribution\'s configuration information.
    CreateDistribution -> DistributionConfig
distributionConfig :: DistributionConfig
  }
  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, 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:
--
-- 'distributionConfig', 'createDistribution_distributionConfig' - The distribution\'s configuration information.
newCreateDistribution ::
  -- | 'distributionConfig'
  DistributionConfig ->
  CreateDistribution
newCreateDistribution :: DistributionConfig -> CreateDistribution
newCreateDistribution DistributionConfig
pDistributionConfig_ =
  CreateDistribution' :: DistributionConfig -> CreateDistribution
CreateDistribution'
    { $sel:distributionConfig:CreateDistribution' :: DistributionConfig
distributionConfig =
        DistributionConfig
pDistributionConfig_
    }

-- | The distribution\'s configuration information.
createDistribution_distributionConfig :: Lens.Lens' CreateDistribution DistributionConfig
createDistribution_distributionConfig :: (DistributionConfig -> f DistributionConfig)
-> CreateDistribution -> f CreateDistribution
createDistribution_distributionConfig = (CreateDistribution -> DistributionConfig)
-> (CreateDistribution -> DistributionConfig -> CreateDistribution)
-> Lens
     CreateDistribution
     CreateDistribution
     DistributionConfig
     DistributionConfig
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDistribution' {DistributionConfig
distributionConfig :: DistributionConfig
$sel:distributionConfig:CreateDistribution' :: CreateDistribution -> DistributionConfig
distributionConfig} -> DistributionConfig
distributionConfig) (\s :: CreateDistribution
s@CreateDistribution' {} DistributionConfig
a -> CreateDistribution
s {$sel:distributionConfig:CreateDistribution' :: DistributionConfig
distributionConfig = DistributionConfig
a} :: CreateDistribution)

instance Core.AWSRequest CreateDistribution where
  type
    AWSResponse CreateDistribution =
      CreateDistributionResponse
  request :: CreateDistribution -> Request CreateDistribution
request = Service -> CreateDistribution -> Request CreateDistribution
forall a. (ToRequest a, ToElement a) => Service -> a -> Request a
Request.postXML Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateDistribution
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateDistribution)))
response =
    (Int
 -> ResponseHeaders
 -> [Node]
 -> Either String (AWSResponse CreateDistribution))
-> Logger
-> Service
-> Proxy CreateDistribution
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateDistribution)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXML
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe Text
-> Maybe Distribution
-> Maybe Text
-> Int
-> CreateDistributionResponse
CreateDistributionResponse'
            (Maybe Text
 -> Maybe Distribution
 -> Maybe Text
 -> Int
 -> CreateDistributionResponse)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Distribution
      -> Maybe Text -> Int -> CreateDistributionResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (ResponseHeaders
h ResponseHeaders -> HeaderName -> Either String (Maybe Text)
forall a.
FromText a =>
ResponseHeaders -> HeaderName -> Either String (Maybe a)
Core..#? HeaderName
"ETag")
            Either
  String
  (Maybe Distribution
   -> Maybe Text -> Int -> CreateDistributionResponse)
-> Either String (Maybe Distribution)
-> Either String (Maybe Text -> Int -> CreateDistributionResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node] -> Either String (Maybe Distribution)
forall a. FromXML a => [Node] -> Either String a
Core.parseXML [Node]
x)
            Either String (Maybe Text -> Int -> CreateDistributionResponse)
-> Either String (Maybe Text)
-> Either String (Int -> CreateDistributionResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (ResponseHeaders
h ResponseHeaders -> HeaderName -> Either String (Maybe Text)
forall a.
FromText a =>
ResponseHeaders -> HeaderName -> Either String (Maybe a)
Core..#? HeaderName
"Location")
            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.ToElement CreateDistribution where
  toElement :: CreateDistribution -> Element
toElement CreateDistribution' {DistributionConfig
distributionConfig :: DistributionConfig
$sel:distributionConfig:CreateDistribution' :: CreateDistribution -> DistributionConfig
..} =
    Name -> DistributionConfig -> Element
forall a. ToXML a => Name -> a -> Element
Core.mkElement
      Name
"{http://cloudfront.amazonaws.com/doc/2020-05-31/}DistributionConfig"
      DistributionConfig
distributionConfig

instance Core.ToHeaders CreateDistribution where
  toHeaders :: CreateDistribution -> ResponseHeaders
toHeaders = ResponseHeaders -> CreateDistribution -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

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

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

-- | The returned result of the corresponding request.
--
-- /See:/ 'newCreateDistributionResponse' smart constructor.
data CreateDistributionResponse = CreateDistributionResponse'
  { -- | The current version of the distribution created.
    CreateDistributionResponse -> Maybe Text
eTag :: Prelude.Maybe Prelude.Text,
    -- | The distribution\'s information.
    CreateDistributionResponse -> Maybe Distribution
distribution :: Prelude.Maybe Distribution,
    -- | The fully qualified URI of the new distribution resource just created.
    CreateDistributionResponse -> Maybe Text
location :: Prelude.Maybe Prelude.Text,
    -- | 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, 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:
--
-- 'eTag', 'createDistributionResponse_eTag' - The current version of the distribution created.
--
-- 'distribution', 'createDistributionResponse_distribution' - The distribution\'s information.
--
-- 'location', 'createDistributionResponse_location' - The fully qualified URI of the new distribution resource just created.
--
-- 'httpStatus', 'createDistributionResponse_httpStatus' - The response's http status code.
newCreateDistributionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateDistributionResponse
newCreateDistributionResponse :: Int -> CreateDistributionResponse
newCreateDistributionResponse Int
pHttpStatus_ =
  CreateDistributionResponse' :: Maybe Text
-> Maybe Distribution
-> Maybe Text
-> Int
-> CreateDistributionResponse
CreateDistributionResponse'
    { $sel:eTag:CreateDistributionResponse' :: Maybe Text
eTag = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:distribution:CreateDistributionResponse' :: Maybe Distribution
distribution = Maybe Distribution
forall a. Maybe a
Prelude.Nothing,
      $sel:location:CreateDistributionResponse' :: Maybe Text
location = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateDistributionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The current version of the distribution created.
createDistributionResponse_eTag :: Lens.Lens' CreateDistributionResponse (Prelude.Maybe Prelude.Text)
createDistributionResponse_eTag :: (Maybe Text -> f (Maybe Text))
-> CreateDistributionResponse -> f CreateDistributionResponse
createDistributionResponse_eTag = (CreateDistributionResponse -> Maybe Text)
-> (CreateDistributionResponse
    -> Maybe Text -> CreateDistributionResponse)
-> Lens
     CreateDistributionResponse
     CreateDistributionResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDistributionResponse' {Maybe Text
eTag :: Maybe Text
$sel:eTag:CreateDistributionResponse' :: CreateDistributionResponse -> Maybe Text
eTag} -> Maybe Text
eTag) (\s :: CreateDistributionResponse
s@CreateDistributionResponse' {} Maybe Text
a -> CreateDistributionResponse
s {$sel:eTag:CreateDistributionResponse' :: Maybe Text
eTag = Maybe Text
a} :: CreateDistributionResponse)

-- | The distribution\'s information.
createDistributionResponse_distribution :: Lens.Lens' CreateDistributionResponse (Prelude.Maybe Distribution)
createDistributionResponse_distribution :: (Maybe Distribution -> f (Maybe Distribution))
-> CreateDistributionResponse -> f CreateDistributionResponse
createDistributionResponse_distribution = (CreateDistributionResponse -> Maybe Distribution)
-> (CreateDistributionResponse
    -> Maybe Distribution -> CreateDistributionResponse)
-> Lens
     CreateDistributionResponse
     CreateDistributionResponse
     (Maybe Distribution)
     (Maybe Distribution)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDistributionResponse' {Maybe Distribution
distribution :: Maybe Distribution
$sel:distribution:CreateDistributionResponse' :: CreateDistributionResponse -> Maybe Distribution
distribution} -> Maybe Distribution
distribution) (\s :: CreateDistributionResponse
s@CreateDistributionResponse' {} Maybe Distribution
a -> CreateDistributionResponse
s {$sel:distribution:CreateDistributionResponse' :: Maybe Distribution
distribution = Maybe Distribution
a} :: CreateDistributionResponse)

-- | The fully qualified URI of the new distribution resource just created.
createDistributionResponse_location :: Lens.Lens' CreateDistributionResponse (Prelude.Maybe Prelude.Text)
createDistributionResponse_location :: (Maybe Text -> f (Maybe Text))
-> CreateDistributionResponse -> f CreateDistributionResponse
createDistributionResponse_location = (CreateDistributionResponse -> Maybe Text)
-> (CreateDistributionResponse
    -> Maybe Text -> CreateDistributionResponse)
-> Lens
     CreateDistributionResponse
     CreateDistributionResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDistributionResponse' {Maybe Text
location :: Maybe Text
$sel:location:CreateDistributionResponse' :: CreateDistributionResponse -> Maybe Text
location} -> Maybe Text
location) (\s :: CreateDistributionResponse
s@CreateDistributionResponse' {} Maybe Text
a -> CreateDistributionResponse
s {$sel:location:CreateDistributionResponse' :: Maybe Text
location = Maybe Text
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