{-# 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.OpsWorks.GetHostnameSuggestion
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Gets a generated host name for the specified layer, based on the current
-- host name theme.
--
-- __Required Permissions__: To use this action, an IAM user must have a
-- Manage permissions level for the stack, or an attached policy that
-- explicitly grants permissions. For more information on user permissions,
-- see
-- <https://docs.aws.amazon.com/opsworks/latest/userguide/opsworks-security-users.html Managing User Permissions>.
module Amazonka.OpsWorks.GetHostnameSuggestion
  ( -- * Creating a Request
    GetHostnameSuggestion (..),
    newGetHostnameSuggestion,

    -- * Request Lenses
    getHostnameSuggestion_layerId,

    -- * Destructuring the Response
    GetHostnameSuggestionResponse (..),
    newGetHostnameSuggestionResponse,

    -- * Response Lenses
    getHostnameSuggestionResponse_hostname,
    getHostnameSuggestionResponse_layerId,
    getHostnameSuggestionResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.OpsWorks.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newGetHostnameSuggestion' smart constructor.
data GetHostnameSuggestion = GetHostnameSuggestion'
  { -- | The layer ID.
    GetHostnameSuggestion -> Text
layerId :: Prelude.Text
  }
  deriving (GetHostnameSuggestion -> GetHostnameSuggestion -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetHostnameSuggestion -> GetHostnameSuggestion -> Bool
$c/= :: GetHostnameSuggestion -> GetHostnameSuggestion -> Bool
== :: GetHostnameSuggestion -> GetHostnameSuggestion -> Bool
$c== :: GetHostnameSuggestion -> GetHostnameSuggestion -> Bool
Prelude.Eq, ReadPrec [GetHostnameSuggestion]
ReadPrec GetHostnameSuggestion
Int -> ReadS GetHostnameSuggestion
ReadS [GetHostnameSuggestion]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetHostnameSuggestion]
$creadListPrec :: ReadPrec [GetHostnameSuggestion]
readPrec :: ReadPrec GetHostnameSuggestion
$creadPrec :: ReadPrec GetHostnameSuggestion
readList :: ReadS [GetHostnameSuggestion]
$creadList :: ReadS [GetHostnameSuggestion]
readsPrec :: Int -> ReadS GetHostnameSuggestion
$creadsPrec :: Int -> ReadS GetHostnameSuggestion
Prelude.Read, Int -> GetHostnameSuggestion -> ShowS
[GetHostnameSuggestion] -> ShowS
GetHostnameSuggestion -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetHostnameSuggestion] -> ShowS
$cshowList :: [GetHostnameSuggestion] -> ShowS
show :: GetHostnameSuggestion -> String
$cshow :: GetHostnameSuggestion -> String
showsPrec :: Int -> GetHostnameSuggestion -> ShowS
$cshowsPrec :: Int -> GetHostnameSuggestion -> ShowS
Prelude.Show, forall x. Rep GetHostnameSuggestion x -> GetHostnameSuggestion
forall x. GetHostnameSuggestion -> Rep GetHostnameSuggestion x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetHostnameSuggestion x -> GetHostnameSuggestion
$cfrom :: forall x. GetHostnameSuggestion -> Rep GetHostnameSuggestion x
Prelude.Generic)

-- |
-- Create a value of 'GetHostnameSuggestion' 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:
--
-- 'layerId', 'getHostnameSuggestion_layerId' - The layer ID.
newGetHostnameSuggestion ::
  -- | 'layerId'
  Prelude.Text ->
  GetHostnameSuggestion
newGetHostnameSuggestion :: Text -> GetHostnameSuggestion
newGetHostnameSuggestion Text
pLayerId_ =
  GetHostnameSuggestion' {$sel:layerId:GetHostnameSuggestion' :: Text
layerId = Text
pLayerId_}

-- | The layer ID.
getHostnameSuggestion_layerId :: Lens.Lens' GetHostnameSuggestion Prelude.Text
getHostnameSuggestion_layerId :: Lens' GetHostnameSuggestion Text
getHostnameSuggestion_layerId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetHostnameSuggestion' {Text
layerId :: Text
$sel:layerId:GetHostnameSuggestion' :: GetHostnameSuggestion -> Text
layerId} -> Text
layerId) (\s :: GetHostnameSuggestion
s@GetHostnameSuggestion' {} Text
a -> GetHostnameSuggestion
s {$sel:layerId:GetHostnameSuggestion' :: Text
layerId = Text
a} :: GetHostnameSuggestion)

instance Core.AWSRequest GetHostnameSuggestion where
  type
    AWSResponse GetHostnameSuggestion =
      GetHostnameSuggestionResponse
  request :: (Service -> Service)
-> GetHostnameSuggestion -> Request GetHostnameSuggestion
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 GetHostnameSuggestion
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetHostnameSuggestion)))
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 Text -> Maybe Text -> Int -> GetHostnameSuggestionResponse
GetHostnameSuggestionResponse'
            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
"Hostname")
            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
"LayerId")
            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 GetHostnameSuggestion where
  hashWithSalt :: Int -> GetHostnameSuggestion -> Int
hashWithSalt Int
_salt GetHostnameSuggestion' {Text
layerId :: Text
$sel:layerId:GetHostnameSuggestion' :: GetHostnameSuggestion -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
layerId

instance Prelude.NFData GetHostnameSuggestion where
  rnf :: GetHostnameSuggestion -> ()
rnf GetHostnameSuggestion' {Text
layerId :: Text
$sel:layerId:GetHostnameSuggestion' :: GetHostnameSuggestion -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
layerId

instance Data.ToHeaders GetHostnameSuggestion where
  toHeaders :: GetHostnameSuggestion -> 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
"OpsWorks_20130218.GetHostnameSuggestion" ::
                          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 GetHostnameSuggestion where
  toJSON :: GetHostnameSuggestion -> Value
toJSON GetHostnameSuggestion' {Text
layerId :: Text
$sel:layerId:GetHostnameSuggestion' :: GetHostnameSuggestion -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"LayerId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
layerId)]
      )

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

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

-- | Contains the response to a @GetHostnameSuggestion@ request.
--
-- /See:/ 'newGetHostnameSuggestionResponse' smart constructor.
data GetHostnameSuggestionResponse = GetHostnameSuggestionResponse'
  { -- | The generated host name.
    GetHostnameSuggestionResponse -> Maybe Text
hostname :: Prelude.Maybe Prelude.Text,
    -- | The layer ID.
    GetHostnameSuggestionResponse -> Maybe Text
layerId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetHostnameSuggestionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetHostnameSuggestionResponse
-> GetHostnameSuggestionResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetHostnameSuggestionResponse
-> GetHostnameSuggestionResponse -> Bool
$c/= :: GetHostnameSuggestionResponse
-> GetHostnameSuggestionResponse -> Bool
== :: GetHostnameSuggestionResponse
-> GetHostnameSuggestionResponse -> Bool
$c== :: GetHostnameSuggestionResponse
-> GetHostnameSuggestionResponse -> Bool
Prelude.Eq, ReadPrec [GetHostnameSuggestionResponse]
ReadPrec GetHostnameSuggestionResponse
Int -> ReadS GetHostnameSuggestionResponse
ReadS [GetHostnameSuggestionResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetHostnameSuggestionResponse]
$creadListPrec :: ReadPrec [GetHostnameSuggestionResponse]
readPrec :: ReadPrec GetHostnameSuggestionResponse
$creadPrec :: ReadPrec GetHostnameSuggestionResponse
readList :: ReadS [GetHostnameSuggestionResponse]
$creadList :: ReadS [GetHostnameSuggestionResponse]
readsPrec :: Int -> ReadS GetHostnameSuggestionResponse
$creadsPrec :: Int -> ReadS GetHostnameSuggestionResponse
Prelude.Read, Int -> GetHostnameSuggestionResponse -> ShowS
[GetHostnameSuggestionResponse] -> ShowS
GetHostnameSuggestionResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetHostnameSuggestionResponse] -> ShowS
$cshowList :: [GetHostnameSuggestionResponse] -> ShowS
show :: GetHostnameSuggestionResponse -> String
$cshow :: GetHostnameSuggestionResponse -> String
showsPrec :: Int -> GetHostnameSuggestionResponse -> ShowS
$cshowsPrec :: Int -> GetHostnameSuggestionResponse -> ShowS
Prelude.Show, forall x.
Rep GetHostnameSuggestionResponse x
-> GetHostnameSuggestionResponse
forall x.
GetHostnameSuggestionResponse
-> Rep GetHostnameSuggestionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetHostnameSuggestionResponse x
-> GetHostnameSuggestionResponse
$cfrom :: forall x.
GetHostnameSuggestionResponse
-> Rep GetHostnameSuggestionResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetHostnameSuggestionResponse' 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:
--
-- 'hostname', 'getHostnameSuggestionResponse_hostname' - The generated host name.
--
-- 'layerId', 'getHostnameSuggestionResponse_layerId' - The layer ID.
--
-- 'httpStatus', 'getHostnameSuggestionResponse_httpStatus' - The response's http status code.
newGetHostnameSuggestionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetHostnameSuggestionResponse
newGetHostnameSuggestionResponse :: Int -> GetHostnameSuggestionResponse
newGetHostnameSuggestionResponse Int
pHttpStatus_ =
  GetHostnameSuggestionResponse'
    { $sel:hostname:GetHostnameSuggestionResponse' :: Maybe Text
hostname =
        forall a. Maybe a
Prelude.Nothing,
      $sel:layerId:GetHostnameSuggestionResponse' :: Maybe Text
layerId = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetHostnameSuggestionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The generated host name.
getHostnameSuggestionResponse_hostname :: Lens.Lens' GetHostnameSuggestionResponse (Prelude.Maybe Prelude.Text)
getHostnameSuggestionResponse_hostname :: Lens' GetHostnameSuggestionResponse (Maybe Text)
getHostnameSuggestionResponse_hostname = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetHostnameSuggestionResponse' {Maybe Text
hostname :: Maybe Text
$sel:hostname:GetHostnameSuggestionResponse' :: GetHostnameSuggestionResponse -> Maybe Text
hostname} -> Maybe Text
hostname) (\s :: GetHostnameSuggestionResponse
s@GetHostnameSuggestionResponse' {} Maybe Text
a -> GetHostnameSuggestionResponse
s {$sel:hostname:GetHostnameSuggestionResponse' :: Maybe Text
hostname = Maybe Text
a} :: GetHostnameSuggestionResponse)

-- | The layer ID.
getHostnameSuggestionResponse_layerId :: Lens.Lens' GetHostnameSuggestionResponse (Prelude.Maybe Prelude.Text)
getHostnameSuggestionResponse_layerId :: Lens' GetHostnameSuggestionResponse (Maybe Text)
getHostnameSuggestionResponse_layerId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetHostnameSuggestionResponse' {Maybe Text
layerId :: Maybe Text
$sel:layerId:GetHostnameSuggestionResponse' :: GetHostnameSuggestionResponse -> Maybe Text
layerId} -> Maybe Text
layerId) (\s :: GetHostnameSuggestionResponse
s@GetHostnameSuggestionResponse' {} Maybe Text
a -> GetHostnameSuggestionResponse
s {$sel:layerId:GetHostnameSuggestionResponse' :: Maybe Text
layerId = Maybe Text
a} :: GetHostnameSuggestionResponse)

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

instance Prelude.NFData GetHostnameSuggestionResponse where
  rnf :: GetHostnameSuggestionResponse -> ()
rnf GetHostnameSuggestionResponse' {Int
Maybe Text
httpStatus :: Int
layerId :: Maybe Text
hostname :: Maybe Text
$sel:httpStatus:GetHostnameSuggestionResponse' :: GetHostnameSuggestionResponse -> Int
$sel:layerId:GetHostnameSuggestionResponse' :: GetHostnameSuggestionResponse -> Maybe Text
$sel:hostname:GetHostnameSuggestionResponse' :: GetHostnameSuggestionResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
hostname
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
layerId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus