{-# 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-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)
--
-- 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.Lens as Lens
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
(GetHostnameSuggestion -> GetHostnameSuggestion -> Bool)
-> (GetHostnameSuggestion -> GetHostnameSuggestion -> Bool)
-> Eq GetHostnameSuggestion
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]
(Int -> ReadS GetHostnameSuggestion)
-> ReadS [GetHostnameSuggestion]
-> ReadPrec GetHostnameSuggestion
-> ReadPrec [GetHostnameSuggestion]
-> Read 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
(Int -> GetHostnameSuggestion -> ShowS)
-> (GetHostnameSuggestion -> String)
-> ([GetHostnameSuggestion] -> ShowS)
-> Show GetHostnameSuggestion
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. GetHostnameSuggestion -> Rep GetHostnameSuggestion x)
-> (forall x. Rep GetHostnameSuggestion x -> GetHostnameSuggestion)
-> Generic GetHostnameSuggestion
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' :: Text -> GetHostnameSuggestion
GetHostnameSuggestion' {$sel:layerId:GetHostnameSuggestion' :: Text
layerId = Text
pLayerId_}

-- | The layer ID.
getHostnameSuggestion_layerId :: Lens.Lens' GetHostnameSuggestion Prelude.Text
getHostnameSuggestion_layerId :: (Text -> f Text)
-> GetHostnameSuggestion -> f GetHostnameSuggestion
getHostnameSuggestion_layerId = (GetHostnameSuggestion -> Text)
-> (GetHostnameSuggestion -> Text -> GetHostnameSuggestion)
-> Lens GetHostnameSuggestion GetHostnameSuggestion Text Text
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 :: GetHostnameSuggestion -> Request GetHostnameSuggestion
request = Service -> GetHostnameSuggestion -> Request GetHostnameSuggestion
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetHostnameSuggestion
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetHostnameSuggestion)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetHostnameSuggestion))
-> Logger
-> Service
-> Proxy GetHostnameSuggestion
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetHostnameSuggestion)))
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 Text -> Maybe Text -> Int -> GetHostnameSuggestionResponse
GetHostnameSuggestionResponse'
            (Maybe Text -> Maybe Text -> Int -> GetHostnameSuggestionResponse)
-> Either String (Maybe Text)
-> Either
     String (Maybe Text -> Int -> GetHostnameSuggestionResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Hostname")
            Either String (Maybe Text -> Int -> GetHostnameSuggestionResponse)
-> Either String (Maybe Text)
-> Either String (Int -> GetHostnameSuggestionResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"LayerId")
            Either String (Int -> GetHostnameSuggestionResponse)
-> Either String Int -> Either String GetHostnameSuggestionResponse
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 GetHostnameSuggestion

instance Prelude.NFData GetHostnameSuggestion

instance Core.ToHeaders GetHostnameSuggestion where
  toHeaders :: GetHostnameSuggestion -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetHostnameSuggestion -> 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
"OpsWorks_20130218.GetHostnameSuggestion" ::
                          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 GetHostnameSuggestion where
  toJSON :: GetHostnameSuggestion -> Value
toJSON GetHostnameSuggestion' {Text
layerId :: Text
$sel:layerId:GetHostnameSuggestion' :: GetHostnameSuggestion -> 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
"LayerId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
layerId)]
      )

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

instance Core.ToQuery GetHostnameSuggestion where
  toQuery :: GetHostnameSuggestion -> QueryString
toQuery = QueryString -> GetHostnameSuggestion -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(GetHostnameSuggestionResponse
 -> GetHostnameSuggestionResponse -> Bool)
-> (GetHostnameSuggestionResponse
    -> GetHostnameSuggestionResponse -> Bool)
-> Eq GetHostnameSuggestionResponse
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]
(Int -> ReadS GetHostnameSuggestionResponse)
-> ReadS [GetHostnameSuggestionResponse]
-> ReadPrec GetHostnameSuggestionResponse
-> ReadPrec [GetHostnameSuggestionResponse]
-> Read 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
(Int -> GetHostnameSuggestionResponse -> ShowS)
-> (GetHostnameSuggestionResponse -> String)
-> ([GetHostnameSuggestionResponse] -> ShowS)
-> Show GetHostnameSuggestionResponse
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.
 GetHostnameSuggestionResponse
 -> Rep GetHostnameSuggestionResponse x)
-> (forall x.
    Rep GetHostnameSuggestionResponse x
    -> GetHostnameSuggestionResponse)
-> Generic GetHostnameSuggestionResponse
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' :: Maybe Text -> Maybe Text -> Int -> GetHostnameSuggestionResponse
GetHostnameSuggestionResponse'
    { $sel:hostname:GetHostnameSuggestionResponse' :: Maybe Text
hostname =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:layerId:GetHostnameSuggestionResponse' :: Maybe Text
layerId = Maybe Text
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 :: (Maybe Text -> f (Maybe Text))
-> GetHostnameSuggestionResponse -> f GetHostnameSuggestionResponse
getHostnameSuggestionResponse_hostname = (GetHostnameSuggestionResponse -> Maybe Text)
-> (GetHostnameSuggestionResponse
    -> Maybe Text -> GetHostnameSuggestionResponse)
-> Lens
     GetHostnameSuggestionResponse
     GetHostnameSuggestionResponse
     (Maybe Text)
     (Maybe Text)
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 :: (Maybe Text -> f (Maybe Text))
-> GetHostnameSuggestionResponse -> f GetHostnameSuggestionResponse
getHostnameSuggestionResponse_layerId = (GetHostnameSuggestionResponse -> Maybe Text)
-> (GetHostnameSuggestionResponse
    -> Maybe Text -> GetHostnameSuggestionResponse)
-> Lens
     GetHostnameSuggestionResponse
     GetHostnameSuggestionResponse
     (Maybe Text)
     (Maybe Text)
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 :: (Int -> f Int)
-> GetHostnameSuggestionResponse -> f GetHostnameSuggestionResponse
getHostnameSuggestionResponse_httpStatus = (GetHostnameSuggestionResponse -> Int)
-> (GetHostnameSuggestionResponse
    -> Int -> GetHostnameSuggestionResponse)
-> Lens
     GetHostnameSuggestionResponse GetHostnameSuggestionResponse Int Int
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