{-# 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.XRay.GetInsight
-- 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)
--
-- Retrieves the summary information of an insight. This includes impact to
-- clients and root cause services, the top anomalous services, the
-- category, the state of the insight, and the start and end time of the
-- insight.
module Amazonka.XRay.GetInsight
  ( -- * Creating a Request
    GetInsight (..),
    newGetInsight,

    -- * Request Lenses
    getInsight_insightId,

    -- * Destructuring the Response
    GetInsightResponse (..),
    newGetInsightResponse,

    -- * Response Lenses
    getInsightResponse_insight,
    getInsightResponse_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.XRay.Types

-- | /See:/ 'newGetInsight' smart constructor.
data GetInsight = GetInsight'
  { -- | The insight\'s unique identifier. Use the GetInsightSummaries action to
    -- retrieve an InsightId.
    GetInsight -> Text
insightId :: Prelude.Text
  }
  deriving (GetInsight -> GetInsight -> Bool
(GetInsight -> GetInsight -> Bool)
-> (GetInsight -> GetInsight -> Bool) -> Eq GetInsight
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetInsight -> GetInsight -> Bool
$c/= :: GetInsight -> GetInsight -> Bool
== :: GetInsight -> GetInsight -> Bool
$c== :: GetInsight -> GetInsight -> Bool
Prelude.Eq, ReadPrec [GetInsight]
ReadPrec GetInsight
Int -> ReadS GetInsight
ReadS [GetInsight]
(Int -> ReadS GetInsight)
-> ReadS [GetInsight]
-> ReadPrec GetInsight
-> ReadPrec [GetInsight]
-> Read GetInsight
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetInsight]
$creadListPrec :: ReadPrec [GetInsight]
readPrec :: ReadPrec GetInsight
$creadPrec :: ReadPrec GetInsight
readList :: ReadS [GetInsight]
$creadList :: ReadS [GetInsight]
readsPrec :: Int -> ReadS GetInsight
$creadsPrec :: Int -> ReadS GetInsight
Prelude.Read, Int -> GetInsight -> ShowS
[GetInsight] -> ShowS
GetInsight -> String
(Int -> GetInsight -> ShowS)
-> (GetInsight -> String)
-> ([GetInsight] -> ShowS)
-> Show GetInsight
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetInsight] -> ShowS
$cshowList :: [GetInsight] -> ShowS
show :: GetInsight -> String
$cshow :: GetInsight -> String
showsPrec :: Int -> GetInsight -> ShowS
$cshowsPrec :: Int -> GetInsight -> ShowS
Prelude.Show, (forall x. GetInsight -> Rep GetInsight x)
-> (forall x. Rep GetInsight x -> GetInsight) -> Generic GetInsight
forall x. Rep GetInsight x -> GetInsight
forall x. GetInsight -> Rep GetInsight x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetInsight x -> GetInsight
$cfrom :: forall x. GetInsight -> Rep GetInsight x
Prelude.Generic)

-- |
-- Create a value of 'GetInsight' 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:
--
-- 'insightId', 'getInsight_insightId' - The insight\'s unique identifier. Use the GetInsightSummaries action to
-- retrieve an InsightId.
newGetInsight ::
  -- | 'insightId'
  Prelude.Text ->
  GetInsight
newGetInsight :: Text -> GetInsight
newGetInsight Text
pInsightId_ =
  GetInsight' :: Text -> GetInsight
GetInsight' {$sel:insightId:GetInsight' :: Text
insightId = Text
pInsightId_}

-- | The insight\'s unique identifier. Use the GetInsightSummaries action to
-- retrieve an InsightId.
getInsight_insightId :: Lens.Lens' GetInsight Prelude.Text
getInsight_insightId :: (Text -> f Text) -> GetInsight -> f GetInsight
getInsight_insightId = (GetInsight -> Text)
-> (GetInsight -> Text -> GetInsight)
-> Lens GetInsight GetInsight Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetInsight' {Text
insightId :: Text
$sel:insightId:GetInsight' :: GetInsight -> Text
insightId} -> Text
insightId) (\s :: GetInsight
s@GetInsight' {} Text
a -> GetInsight
s {$sel:insightId:GetInsight' :: Text
insightId = Text
a} :: GetInsight)

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

instance Prelude.NFData GetInsight

instance Core.ToHeaders GetInsight where
  toHeaders :: GetInsight -> ResponseHeaders
toHeaders = ResponseHeaders -> GetInsight -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToJSON GetInsight where
  toJSON :: GetInsight -> Value
toJSON GetInsight' {Text
insightId :: Text
$sel:insightId:GetInsight' :: GetInsight -> 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
"InsightId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
insightId)]
      )

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

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

-- | /See:/ 'newGetInsightResponse' smart constructor.
data GetInsightResponse = GetInsightResponse'
  { -- | The summary information of an insight.
    GetInsightResponse -> Maybe Insight
insight :: Prelude.Maybe Insight,
    -- | The response's http status code.
    GetInsightResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetInsightResponse -> GetInsightResponse -> Bool
(GetInsightResponse -> GetInsightResponse -> Bool)
-> (GetInsightResponse -> GetInsightResponse -> Bool)
-> Eq GetInsightResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetInsightResponse -> GetInsightResponse -> Bool
$c/= :: GetInsightResponse -> GetInsightResponse -> Bool
== :: GetInsightResponse -> GetInsightResponse -> Bool
$c== :: GetInsightResponse -> GetInsightResponse -> Bool
Prelude.Eq, ReadPrec [GetInsightResponse]
ReadPrec GetInsightResponse
Int -> ReadS GetInsightResponse
ReadS [GetInsightResponse]
(Int -> ReadS GetInsightResponse)
-> ReadS [GetInsightResponse]
-> ReadPrec GetInsightResponse
-> ReadPrec [GetInsightResponse]
-> Read GetInsightResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetInsightResponse]
$creadListPrec :: ReadPrec [GetInsightResponse]
readPrec :: ReadPrec GetInsightResponse
$creadPrec :: ReadPrec GetInsightResponse
readList :: ReadS [GetInsightResponse]
$creadList :: ReadS [GetInsightResponse]
readsPrec :: Int -> ReadS GetInsightResponse
$creadsPrec :: Int -> ReadS GetInsightResponse
Prelude.Read, Int -> GetInsightResponse -> ShowS
[GetInsightResponse] -> ShowS
GetInsightResponse -> String
(Int -> GetInsightResponse -> ShowS)
-> (GetInsightResponse -> String)
-> ([GetInsightResponse] -> ShowS)
-> Show GetInsightResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetInsightResponse] -> ShowS
$cshowList :: [GetInsightResponse] -> ShowS
show :: GetInsightResponse -> String
$cshow :: GetInsightResponse -> String
showsPrec :: Int -> GetInsightResponse -> ShowS
$cshowsPrec :: Int -> GetInsightResponse -> ShowS
Prelude.Show, (forall x. GetInsightResponse -> Rep GetInsightResponse x)
-> (forall x. Rep GetInsightResponse x -> GetInsightResponse)
-> Generic GetInsightResponse
forall x. Rep GetInsightResponse x -> GetInsightResponse
forall x. GetInsightResponse -> Rep GetInsightResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetInsightResponse x -> GetInsightResponse
$cfrom :: forall x. GetInsightResponse -> Rep GetInsightResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetInsightResponse' 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:
--
-- 'insight', 'getInsightResponse_insight' - The summary information of an insight.
--
-- 'httpStatus', 'getInsightResponse_httpStatus' - The response's http status code.
newGetInsightResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetInsightResponse
newGetInsightResponse :: Int -> GetInsightResponse
newGetInsightResponse Int
pHttpStatus_ =
  GetInsightResponse' :: Maybe Insight -> Int -> GetInsightResponse
GetInsightResponse'
    { $sel:insight:GetInsightResponse' :: Maybe Insight
insight = Maybe Insight
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetInsightResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The summary information of an insight.
getInsightResponse_insight :: Lens.Lens' GetInsightResponse (Prelude.Maybe Insight)
getInsightResponse_insight :: (Maybe Insight -> f (Maybe Insight))
-> GetInsightResponse -> f GetInsightResponse
getInsightResponse_insight = (GetInsightResponse -> Maybe Insight)
-> (GetInsightResponse -> Maybe Insight -> GetInsightResponse)
-> Lens
     GetInsightResponse
     GetInsightResponse
     (Maybe Insight)
     (Maybe Insight)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetInsightResponse' {Maybe Insight
insight :: Maybe Insight
$sel:insight:GetInsightResponse' :: GetInsightResponse -> Maybe Insight
insight} -> Maybe Insight
insight) (\s :: GetInsightResponse
s@GetInsightResponse' {} Maybe Insight
a -> GetInsightResponse
s {$sel:insight:GetInsightResponse' :: Maybe Insight
insight = Maybe Insight
a} :: GetInsightResponse)

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

instance Prelude.NFData GetInsightResponse