{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.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:/ '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
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]
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
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. 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'
    { $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 :: Lens' CreateDomainEntry Text
createDomainEntry_domainName = 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 :: Lens' CreateDomainEntry DomainEntry
createDomainEntry_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 :: (Service -> Service)
-> CreateDomainEntry -> Request CreateDomainEntry
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 CreateDomainEntry
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateDomainEntry)))
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 Operation -> Int -> CreateDomainEntryResponse
CreateDomainEntryResponse'
            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
"operation")
            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 CreateDomainEntry where
  hashWithSalt :: Int -> CreateDomainEntry -> Int
hashWithSalt Int
_salt CreateDomainEntry' {Text
DomainEntry
domainEntry :: DomainEntry
domainName :: Text
$sel:domainEntry:CreateDomainEntry' :: CreateDomainEntry -> DomainEntry
$sel:domainName:CreateDomainEntry' :: CreateDomainEntry -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
domainName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` DomainEntry
domainEntry

instance Prelude.NFData CreateDomainEntry where
  rnf :: CreateDomainEntry -> ()
rnf CreateDomainEntry' {Text
DomainEntry
domainEntry :: DomainEntry
domainName :: Text
$sel:domainEntry:CreateDomainEntry' :: CreateDomainEntry -> DomainEntry
$sel:domainName:CreateDomainEntry' :: CreateDomainEntry -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
domainName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf DomainEntry
domainEntry

instance Data.ToHeaders CreateDomainEntry where
  toHeaders :: CreateDomainEntry -> 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.CreateDomainEntry" ::
                          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 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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"domainName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
domainName),
            forall a. a -> Maybe a
Prelude.Just (Key
"domainEntry" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= DomainEntry
domainEntry)
          ]
      )

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

instance Data.ToQuery CreateDomainEntry where
  toQuery :: CreateDomainEntry -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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.
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'
    { $sel:operation:CreateDomainEntryResponse' :: Maybe Operation
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 :: Lens' CreateDomainEntryResponse (Maybe Operation)
createDomainEntryResponse_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 :: Lens' CreateDomainEntryResponse Int
createDomainEntryResponse_httpStatus = 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 where
  rnf :: CreateDomainEntryResponse -> ()
rnf CreateDomainEntryResponse' {Int
Maybe Operation
httpStatus :: Int
operation :: Maybe Operation
$sel:httpStatus:CreateDomainEntryResponse' :: CreateDomainEntryResponse -> Int
$sel:operation:CreateDomainEntryResponse' :: CreateDomainEntryResponse -> Maybe Operation
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Operation
operation
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus