{-# 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.CreateDomainEntry
-- 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 one of the following domain name system (DNS) records in a
-- domain DNS zone: Address (A), canonical name (CNAME), mail exchanger
-- (MX), name server (NS), start of authority (SOA), service locator (SRV),
-- or text (TXT).
--
-- The @create domain entry@ operation supports tag-based access control
-- via resource tags applied to the resource identified by @domain name@.
-- For more information, see the
-- <https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-controlling-access-using-tags Amazon Lightsail Developer Guide>.
module Amazonka.Lightsail.CreateDomainEntry
  ( -- * Creating a Request
    CreateDomainEntry (..),
    newCreateDomainEntry,

    -- * Request Lenses
    createDomainEntry_domainName,
    createDomainEntry_domainEntry,

    -- * Destructuring the Response
    CreateDomainEntryResponse (..),
    newCreateDomainEntryResponse,

    -- * Response Lenses
    createDomainEntryResponse_operation,
    createDomainEntryResponse_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:/ 'newCreateDomainEntry' smart constructor.
data CreateDomainEntry = CreateDomainEntry'
  { -- | The domain name (e.g., @example.com@) for which you want to create the
    -- domain entry.
    CreateDomainEntry -> Text
domainName :: Prelude.Text,
    -- | An array of key-value pairs containing information about the domain
    -- entry request.
    CreateDomainEntry -> DomainEntry
domainEntry :: DomainEntry
  }
  deriving (CreateDomainEntry -> CreateDomainEntry -> Bool
(CreateDomainEntry -> CreateDomainEntry -> Bool)
-> (CreateDomainEntry -> CreateDomainEntry -> Bool)
-> Eq CreateDomainEntry
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateDomainEntry -> CreateDomainEntry -> Bool
$c/= :: CreateDomainEntry -> CreateDomainEntry -> Bool
== :: CreateDomainEntry -> CreateDomainEntry -> Bool
$c== :: CreateDomainEntry -> CreateDomainEntry -> Bool
Prelude.Eq, ReadPrec [CreateDomainEntry]
ReadPrec CreateDomainEntry
Int -> ReadS CreateDomainEntry
ReadS [CreateDomainEntry]
(Int -> ReadS CreateDomainEntry)
-> ReadS [CreateDomainEntry]
-> ReadPrec CreateDomainEntry
-> ReadPrec [CreateDomainEntry]
-> Read CreateDomainEntry
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateDomainEntry]
$creadListPrec :: ReadPrec [CreateDomainEntry]
readPrec :: ReadPrec CreateDomainEntry
$creadPrec :: ReadPrec CreateDomainEntry
readList :: ReadS [CreateDomainEntry]
$creadList :: ReadS [CreateDomainEntry]
readsPrec :: Int -> ReadS CreateDomainEntry
$creadsPrec :: Int -> ReadS CreateDomainEntry
Prelude.Read, Int -> CreateDomainEntry -> ShowS
[CreateDomainEntry] -> ShowS
CreateDomainEntry -> String
(Int -> CreateDomainEntry -> ShowS)
-> (CreateDomainEntry -> String)
-> ([CreateDomainEntry] -> ShowS)
-> Show CreateDomainEntry
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateDomainEntry] -> ShowS
$cshowList :: [CreateDomainEntry] -> ShowS
show :: CreateDomainEntry -> String
$cshow :: CreateDomainEntry -> String
showsPrec :: Int -> CreateDomainEntry -> ShowS
$cshowsPrec :: Int -> CreateDomainEntry -> ShowS
Prelude.Show, (forall x. CreateDomainEntry -> Rep CreateDomainEntry x)
-> (forall x. Rep CreateDomainEntry x -> CreateDomainEntry)
-> Generic CreateDomainEntry
forall x. Rep CreateDomainEntry x -> CreateDomainEntry
forall x. CreateDomainEntry -> Rep CreateDomainEntry x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateDomainEntry x -> CreateDomainEntry
$cfrom :: forall x. CreateDomainEntry -> Rep CreateDomainEntry x
Prelude.Generic)

-- |
-- Create a value of 'CreateDomainEntry' 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:
--
-- 'domainName', 'createDomainEntry_domainName' - The domain name (e.g., @example.com@) for which you want to create the
-- domain entry.
--
-- 'domainEntry', 'createDomainEntry_domainEntry' - An array of key-value pairs containing information about the domain
-- entry request.
newCreateDomainEntry ::
  -- | 'domainName'
  Prelude.Text ->
  -- | 'domainEntry'
  DomainEntry ->
  CreateDomainEntry
newCreateDomainEntry :: Text -> DomainEntry -> CreateDomainEntry
newCreateDomainEntry Text
pDomainName_ DomainEntry
pDomainEntry_ =
  CreateDomainEntry' :: Text -> DomainEntry -> CreateDomainEntry
CreateDomainEntry'
    { $sel:domainName:CreateDomainEntry' :: Text
domainName = Text
pDomainName_,
      $sel:domainEntry:CreateDomainEntry' :: DomainEntry
domainEntry = DomainEntry
pDomainEntry_
    }

-- | The domain name (e.g., @example.com@) for which you want to create the
-- domain entry.
createDomainEntry_domainName :: Lens.Lens' CreateDomainEntry Prelude.Text
createDomainEntry_domainName :: (Text -> f Text) -> CreateDomainEntry -> f CreateDomainEntry
createDomainEntry_domainName = (CreateDomainEntry -> Text)
-> (CreateDomainEntry -> Text -> CreateDomainEntry)
-> Lens CreateDomainEntry CreateDomainEntry Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDomainEntry' {Text
domainName :: Text
$sel:domainName:CreateDomainEntry' :: CreateDomainEntry -> Text
domainName} -> Text
domainName) (\s :: CreateDomainEntry
s@CreateDomainEntry' {} Text
a -> CreateDomainEntry
s {$sel:domainName:CreateDomainEntry' :: Text
domainName = Text
a} :: CreateDomainEntry)

-- | An array of key-value pairs containing information about the domain
-- entry request.
createDomainEntry_domainEntry :: Lens.Lens' CreateDomainEntry DomainEntry
createDomainEntry_domainEntry :: (DomainEntry -> f DomainEntry)
-> CreateDomainEntry -> f CreateDomainEntry
createDomainEntry_domainEntry = (CreateDomainEntry -> DomainEntry)
-> (CreateDomainEntry -> DomainEntry -> CreateDomainEntry)
-> Lens CreateDomainEntry CreateDomainEntry DomainEntry DomainEntry
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDomainEntry' {DomainEntry
domainEntry :: DomainEntry
$sel:domainEntry:CreateDomainEntry' :: CreateDomainEntry -> DomainEntry
domainEntry} -> DomainEntry
domainEntry) (\s :: CreateDomainEntry
s@CreateDomainEntry' {} DomainEntry
a -> CreateDomainEntry
s {$sel:domainEntry:CreateDomainEntry' :: DomainEntry
domainEntry = DomainEntry
a} :: CreateDomainEntry)

instance Core.AWSRequest CreateDomainEntry where
  type
    AWSResponse CreateDomainEntry =
      CreateDomainEntryResponse
  request :: CreateDomainEntry -> Request CreateDomainEntry
request = Service -> CreateDomainEntry -> Request CreateDomainEntry
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateDomainEntry
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateDomainEntry)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateDomainEntry))
-> Logger
-> Service
-> Proxy CreateDomainEntry
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateDomainEntry)))
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 Operation -> Int -> CreateDomainEntryResponse
CreateDomainEntryResponse'
            (Maybe Operation -> Int -> CreateDomainEntryResponse)
-> Either String (Maybe Operation)
-> Either String (Int -> CreateDomainEntryResponse)
forall (f :: * -> *) a b. Functor 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 -> CreateDomainEntryResponse)
-> Either String Int -> Either String CreateDomainEntryResponse
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 CreateDomainEntry

instance Prelude.NFData CreateDomainEntry

instance Core.ToHeaders CreateDomainEntry where
  toHeaders :: CreateDomainEntry -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateDomainEntry -> 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.CreateDomainEntry" ::
                          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 CreateDomainEntry where
  toJSON :: CreateDomainEntry -> Value
toJSON CreateDomainEntry' {Text
DomainEntry
domainEntry :: DomainEntry
domainName :: Text
$sel:domainEntry:CreateDomainEntry' :: CreateDomainEntry -> DomainEntry
$sel:domainName:CreateDomainEntry' :: CreateDomainEntry -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"domainName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
domainName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"domainEntry" Text -> DomainEntry -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= DomainEntry
domainEntry)
          ]
      )

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

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

-- | /See:/ 'newCreateDomainEntryResponse' smart constructor.
data CreateDomainEntryResponse = CreateDomainEntryResponse'
  { -- | 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.
    CreateDomainEntryResponse -> Maybe Operation
operation :: Prelude.Maybe Operation,
    -- | The response's http status code.
    CreateDomainEntryResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateDomainEntryResponse -> CreateDomainEntryResponse -> Bool
(CreateDomainEntryResponse -> CreateDomainEntryResponse -> Bool)
-> (CreateDomainEntryResponse -> CreateDomainEntryResponse -> Bool)
-> Eq CreateDomainEntryResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateDomainEntryResponse -> CreateDomainEntryResponse -> Bool
$c/= :: CreateDomainEntryResponse -> CreateDomainEntryResponse -> Bool
== :: CreateDomainEntryResponse -> CreateDomainEntryResponse -> Bool
$c== :: CreateDomainEntryResponse -> CreateDomainEntryResponse -> Bool
Prelude.Eq, ReadPrec [CreateDomainEntryResponse]
ReadPrec CreateDomainEntryResponse
Int -> ReadS CreateDomainEntryResponse
ReadS [CreateDomainEntryResponse]
(Int -> ReadS CreateDomainEntryResponse)
-> ReadS [CreateDomainEntryResponse]
-> ReadPrec CreateDomainEntryResponse
-> ReadPrec [CreateDomainEntryResponse]
-> Read CreateDomainEntryResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateDomainEntryResponse]
$creadListPrec :: ReadPrec [CreateDomainEntryResponse]
readPrec :: ReadPrec CreateDomainEntryResponse
$creadPrec :: ReadPrec CreateDomainEntryResponse
readList :: ReadS [CreateDomainEntryResponse]
$creadList :: ReadS [CreateDomainEntryResponse]
readsPrec :: Int -> ReadS CreateDomainEntryResponse
$creadsPrec :: Int -> ReadS CreateDomainEntryResponse
Prelude.Read, Int -> CreateDomainEntryResponse -> ShowS
[CreateDomainEntryResponse] -> ShowS
CreateDomainEntryResponse -> String
(Int -> CreateDomainEntryResponse -> ShowS)
-> (CreateDomainEntryResponse -> String)
-> ([CreateDomainEntryResponse] -> ShowS)
-> Show CreateDomainEntryResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateDomainEntryResponse] -> ShowS
$cshowList :: [CreateDomainEntryResponse] -> ShowS
show :: CreateDomainEntryResponse -> String
$cshow :: CreateDomainEntryResponse -> String
showsPrec :: Int -> CreateDomainEntryResponse -> ShowS
$cshowsPrec :: Int -> CreateDomainEntryResponse -> ShowS
Prelude.Show, (forall x.
 CreateDomainEntryResponse -> Rep CreateDomainEntryResponse x)
-> (forall x.
    Rep CreateDomainEntryResponse x -> CreateDomainEntryResponse)
-> Generic CreateDomainEntryResponse
forall x.
Rep CreateDomainEntryResponse x -> CreateDomainEntryResponse
forall x.
CreateDomainEntryResponse -> Rep CreateDomainEntryResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateDomainEntryResponse x -> CreateDomainEntryResponse
$cfrom :: forall x.
CreateDomainEntryResponse -> Rep CreateDomainEntryResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateDomainEntryResponse' 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:
--
-- 'operation', 'createDomainEntryResponse_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', 'createDomainEntryResponse_httpStatus' - The response's http status code.
newCreateDomainEntryResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateDomainEntryResponse
newCreateDomainEntryResponse :: Int -> CreateDomainEntryResponse
newCreateDomainEntryResponse Int
pHttpStatus_ =
  CreateDomainEntryResponse' :: Maybe Operation -> Int -> CreateDomainEntryResponse
CreateDomainEntryResponse'
    { $sel:operation:CreateDomainEntryResponse' :: Maybe Operation
operation =
        Maybe Operation
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateDomainEntryResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | 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.
createDomainEntryResponse_operation :: Lens.Lens' CreateDomainEntryResponse (Prelude.Maybe Operation)
createDomainEntryResponse_operation :: (Maybe Operation -> f (Maybe Operation))
-> CreateDomainEntryResponse -> f CreateDomainEntryResponse
createDomainEntryResponse_operation = (CreateDomainEntryResponse -> Maybe Operation)
-> (CreateDomainEntryResponse
    -> Maybe Operation -> CreateDomainEntryResponse)
-> Lens
     CreateDomainEntryResponse
     CreateDomainEntryResponse
     (Maybe Operation)
     (Maybe Operation)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDomainEntryResponse' {Maybe Operation
operation :: Maybe Operation
$sel:operation:CreateDomainEntryResponse' :: CreateDomainEntryResponse -> Maybe Operation
operation} -> Maybe Operation
operation) (\s :: CreateDomainEntryResponse
s@CreateDomainEntryResponse' {} Maybe Operation
a -> CreateDomainEntryResponse
s {$sel:operation:CreateDomainEntryResponse' :: Maybe Operation
operation = Maybe Operation
a} :: CreateDomainEntryResponse)

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

instance Prelude.NFData CreateDomainEntryResponse