{-# 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.Route53AutoNaming.GetInstance
-- 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 information about a specified instance.
module Amazonka.Route53AutoNaming.GetInstance
  ( -- * Creating a Request
    GetInstance (..),
    newGetInstance,

    -- * Request Lenses
    getInstance_serviceId,
    getInstance_instanceId,

    -- * Destructuring the Response
    GetInstanceResponse (..),
    newGetInstanceResponse,

    -- * Response Lenses
    getInstanceResponse_instance,
    getInstanceResponse_httpStatus,
  )
where

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
import Amazonka.Route53AutoNaming.Types

-- | /See:/ 'newGetInstance' smart constructor.
data GetInstance = GetInstance'
  { -- | The ID of the service that the instance is associated with.
    GetInstance -> Text
serviceId :: Prelude.Text,
    -- | The ID of the instance that you want to get information about.
    GetInstance -> Text
instanceId :: Prelude.Text
  }
  deriving (GetInstance -> GetInstance -> Bool
(GetInstance -> GetInstance -> Bool)
-> (GetInstance -> GetInstance -> Bool) -> Eq GetInstance
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetInstance -> GetInstance -> Bool
$c/= :: GetInstance -> GetInstance -> Bool
== :: GetInstance -> GetInstance -> Bool
$c== :: GetInstance -> GetInstance -> Bool
Prelude.Eq, ReadPrec [GetInstance]
ReadPrec GetInstance
Int -> ReadS GetInstance
ReadS [GetInstance]
(Int -> ReadS GetInstance)
-> ReadS [GetInstance]
-> ReadPrec GetInstance
-> ReadPrec [GetInstance]
-> Read GetInstance
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetInstance]
$creadListPrec :: ReadPrec [GetInstance]
readPrec :: ReadPrec GetInstance
$creadPrec :: ReadPrec GetInstance
readList :: ReadS [GetInstance]
$creadList :: ReadS [GetInstance]
readsPrec :: Int -> ReadS GetInstance
$creadsPrec :: Int -> ReadS GetInstance
Prelude.Read, Int -> GetInstance -> ShowS
[GetInstance] -> ShowS
GetInstance -> String
(Int -> GetInstance -> ShowS)
-> (GetInstance -> String)
-> ([GetInstance] -> ShowS)
-> Show GetInstance
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetInstance] -> ShowS
$cshowList :: [GetInstance] -> ShowS
show :: GetInstance -> String
$cshow :: GetInstance -> String
showsPrec :: Int -> GetInstance -> ShowS
$cshowsPrec :: Int -> GetInstance -> ShowS
Prelude.Show, (forall x. GetInstance -> Rep GetInstance x)
-> (forall x. Rep GetInstance x -> GetInstance)
-> Generic GetInstance
forall x. Rep GetInstance x -> GetInstance
forall x. GetInstance -> Rep GetInstance x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetInstance x -> GetInstance
$cfrom :: forall x. GetInstance -> Rep GetInstance x
Prelude.Generic)

-- |
-- Create a value of 'GetInstance' 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:
--
-- 'serviceId', 'getInstance_serviceId' - The ID of the service that the instance is associated with.
--
-- 'instanceId', 'getInstance_instanceId' - The ID of the instance that you want to get information about.
newGetInstance ::
  -- | 'serviceId'
  Prelude.Text ->
  -- | 'instanceId'
  Prelude.Text ->
  GetInstance
newGetInstance :: Text -> Text -> GetInstance
newGetInstance Text
pServiceId_ Text
pInstanceId_ =
  GetInstance' :: Text -> Text -> GetInstance
GetInstance'
    { $sel:serviceId:GetInstance' :: Text
serviceId = Text
pServiceId_,
      $sel:instanceId:GetInstance' :: Text
instanceId = Text
pInstanceId_
    }

-- | The ID of the service that the instance is associated with.
getInstance_serviceId :: Lens.Lens' GetInstance Prelude.Text
getInstance_serviceId :: (Text -> f Text) -> GetInstance -> f GetInstance
getInstance_serviceId = (GetInstance -> Text)
-> (GetInstance -> Text -> GetInstance)
-> Lens GetInstance GetInstance Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetInstance' {Text
serviceId :: Text
$sel:serviceId:GetInstance' :: GetInstance -> Text
serviceId} -> Text
serviceId) (\s :: GetInstance
s@GetInstance' {} Text
a -> GetInstance
s {$sel:serviceId:GetInstance' :: Text
serviceId = Text
a} :: GetInstance)

-- | The ID of the instance that you want to get information about.
getInstance_instanceId :: Lens.Lens' GetInstance Prelude.Text
getInstance_instanceId :: (Text -> f Text) -> GetInstance -> f GetInstance
getInstance_instanceId = (GetInstance -> Text)
-> (GetInstance -> Text -> GetInstance)
-> Lens GetInstance GetInstance Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetInstance' {Text
instanceId :: Text
$sel:instanceId:GetInstance' :: GetInstance -> Text
instanceId} -> Text
instanceId) (\s :: GetInstance
s@GetInstance' {} Text
a -> GetInstance
s {$sel:instanceId:GetInstance' :: Text
instanceId = Text
a} :: GetInstance)

instance Core.AWSRequest GetInstance where
  type AWSResponse GetInstance = GetInstanceResponse
  request :: GetInstance -> Request GetInstance
request = Service -> GetInstance -> Request GetInstance
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetInstance
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetInstance)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetInstance))
-> Logger
-> Service
-> Proxy GetInstance
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetInstance)))
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 Instance -> Int -> GetInstanceResponse
GetInstanceResponse'
            (Maybe Instance -> Int -> GetInstanceResponse)
-> Either String (Maybe Instance)
-> Either String (Int -> GetInstanceResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Instance)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Instance")
            Either String (Int -> GetInstanceResponse)
-> Either String Int -> Either String GetInstanceResponse
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 GetInstance

instance Prelude.NFData GetInstance

instance Core.ToHeaders GetInstance where
  toHeaders :: GetInstance -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetInstance -> 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
"Route53AutoNaming_v20170314.GetInstance" ::
                          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 GetInstance where
  toJSON :: GetInstance -> Value
toJSON GetInstance' {Text
instanceId :: Text
serviceId :: Text
$sel:instanceId:GetInstance' :: GetInstance -> Text
$sel:serviceId:GetInstance' :: GetInstance -> 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
"ServiceId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
serviceId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"InstanceId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
instanceId)
          ]
      )

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

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

-- | /See:/ 'newGetInstanceResponse' smart constructor.
data GetInstanceResponse = GetInstanceResponse'
  { -- | A complex type that contains information about a specified instance.
    GetInstanceResponse -> Maybe Instance
instance' :: Prelude.Maybe Instance,
    -- | The response's http status code.
    GetInstanceResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetInstanceResponse -> GetInstanceResponse -> Bool
(GetInstanceResponse -> GetInstanceResponse -> Bool)
-> (GetInstanceResponse -> GetInstanceResponse -> Bool)
-> Eq GetInstanceResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetInstanceResponse -> GetInstanceResponse -> Bool
$c/= :: GetInstanceResponse -> GetInstanceResponse -> Bool
== :: GetInstanceResponse -> GetInstanceResponse -> Bool
$c== :: GetInstanceResponse -> GetInstanceResponse -> Bool
Prelude.Eq, ReadPrec [GetInstanceResponse]
ReadPrec GetInstanceResponse
Int -> ReadS GetInstanceResponse
ReadS [GetInstanceResponse]
(Int -> ReadS GetInstanceResponse)
-> ReadS [GetInstanceResponse]
-> ReadPrec GetInstanceResponse
-> ReadPrec [GetInstanceResponse]
-> Read GetInstanceResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetInstanceResponse]
$creadListPrec :: ReadPrec [GetInstanceResponse]
readPrec :: ReadPrec GetInstanceResponse
$creadPrec :: ReadPrec GetInstanceResponse
readList :: ReadS [GetInstanceResponse]
$creadList :: ReadS [GetInstanceResponse]
readsPrec :: Int -> ReadS GetInstanceResponse
$creadsPrec :: Int -> ReadS GetInstanceResponse
Prelude.Read, Int -> GetInstanceResponse -> ShowS
[GetInstanceResponse] -> ShowS
GetInstanceResponse -> String
(Int -> GetInstanceResponse -> ShowS)
-> (GetInstanceResponse -> String)
-> ([GetInstanceResponse] -> ShowS)
-> Show GetInstanceResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetInstanceResponse] -> ShowS
$cshowList :: [GetInstanceResponse] -> ShowS
show :: GetInstanceResponse -> String
$cshow :: GetInstanceResponse -> String
showsPrec :: Int -> GetInstanceResponse -> ShowS
$cshowsPrec :: Int -> GetInstanceResponse -> ShowS
Prelude.Show, (forall x. GetInstanceResponse -> Rep GetInstanceResponse x)
-> (forall x. Rep GetInstanceResponse x -> GetInstanceResponse)
-> Generic GetInstanceResponse
forall x. Rep GetInstanceResponse x -> GetInstanceResponse
forall x. GetInstanceResponse -> Rep GetInstanceResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetInstanceResponse x -> GetInstanceResponse
$cfrom :: forall x. GetInstanceResponse -> Rep GetInstanceResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetInstanceResponse' 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:
--
-- 'instance'', 'getInstanceResponse_instance' - A complex type that contains information about a specified instance.
--
-- 'httpStatus', 'getInstanceResponse_httpStatus' - The response's http status code.
newGetInstanceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetInstanceResponse
newGetInstanceResponse :: Int -> GetInstanceResponse
newGetInstanceResponse Int
pHttpStatus_ =
  GetInstanceResponse' :: Maybe Instance -> Int -> GetInstanceResponse
GetInstanceResponse'
    { $sel:instance':GetInstanceResponse' :: Maybe Instance
instance' = Maybe Instance
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetInstanceResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A complex type that contains information about a specified instance.
getInstanceResponse_instance :: Lens.Lens' GetInstanceResponse (Prelude.Maybe Instance)
getInstanceResponse_instance :: (Maybe Instance -> f (Maybe Instance))
-> GetInstanceResponse -> f GetInstanceResponse
getInstanceResponse_instance = (GetInstanceResponse -> Maybe Instance)
-> (GetInstanceResponse -> Maybe Instance -> GetInstanceResponse)
-> Lens
     GetInstanceResponse
     GetInstanceResponse
     (Maybe Instance)
     (Maybe Instance)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetInstanceResponse' {Maybe Instance
instance' :: Maybe Instance
$sel:instance':GetInstanceResponse' :: GetInstanceResponse -> Maybe Instance
instance'} -> Maybe Instance
instance') (\s :: GetInstanceResponse
s@GetInstanceResponse' {} Maybe Instance
a -> GetInstanceResponse
s {$sel:instance':GetInstanceResponse' :: Maybe Instance
instance' = Maybe Instance
a} :: GetInstanceResponse)

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

instance Prelude.NFData GetInstanceResponse