{-# 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.Synthetics.GetCanary
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Retrieves complete information about one canary. You must specify the
-- name of the canary that you want. To get a list of canaries and their
-- names, use
-- <https://docs.aws.amazon.com/AmazonSynthetics/latest/APIReference/API_DescribeCanaries.html DescribeCanaries>.
module Amazonka.Synthetics.GetCanary
  ( -- * Creating a Request
    GetCanary (..),
    newGetCanary,

    -- * Request Lenses
    getCanary_name,

    -- * Destructuring the Response
    GetCanaryResponse (..),
    newGetCanaryResponse,

    -- * Response Lenses
    getCanaryResponse_canary,
    getCanaryResponse_httpStatus,
  )
where

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

-- | /See:/ 'newGetCanary' smart constructor.
data GetCanary = GetCanary'
  { -- | The name of the canary that you want details for.
    GetCanary -> Text
name :: Prelude.Text
  }
  deriving (GetCanary -> GetCanary -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetCanary -> GetCanary -> Bool
$c/= :: GetCanary -> GetCanary -> Bool
== :: GetCanary -> GetCanary -> Bool
$c== :: GetCanary -> GetCanary -> Bool
Prelude.Eq, ReadPrec [GetCanary]
ReadPrec GetCanary
Int -> ReadS GetCanary
ReadS [GetCanary]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetCanary]
$creadListPrec :: ReadPrec [GetCanary]
readPrec :: ReadPrec GetCanary
$creadPrec :: ReadPrec GetCanary
readList :: ReadS [GetCanary]
$creadList :: ReadS [GetCanary]
readsPrec :: Int -> ReadS GetCanary
$creadsPrec :: Int -> ReadS GetCanary
Prelude.Read, Int -> GetCanary -> ShowS
[GetCanary] -> ShowS
GetCanary -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetCanary] -> ShowS
$cshowList :: [GetCanary] -> ShowS
show :: GetCanary -> String
$cshow :: GetCanary -> String
showsPrec :: Int -> GetCanary -> ShowS
$cshowsPrec :: Int -> GetCanary -> ShowS
Prelude.Show, forall x. Rep GetCanary x -> GetCanary
forall x. GetCanary -> Rep GetCanary x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetCanary x -> GetCanary
$cfrom :: forall x. GetCanary -> Rep GetCanary x
Prelude.Generic)

-- |
-- Create a value of 'GetCanary' 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:
--
-- 'name', 'getCanary_name' - The name of the canary that you want details for.
newGetCanary ::
  -- | 'name'
  Prelude.Text ->
  GetCanary
newGetCanary :: Text -> GetCanary
newGetCanary Text
pName_ = GetCanary' {$sel:name:GetCanary' :: Text
name = Text
pName_}

-- | The name of the canary that you want details for.
getCanary_name :: Lens.Lens' GetCanary Prelude.Text
getCanary_name :: Lens' GetCanary Text
getCanary_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCanary' {Text
name :: Text
$sel:name:GetCanary' :: GetCanary -> Text
name} -> Text
name) (\s :: GetCanary
s@GetCanary' {} Text
a -> GetCanary
s {$sel:name:GetCanary' :: Text
name = Text
a} :: GetCanary)

instance Core.AWSRequest GetCanary where
  type AWSResponse GetCanary = GetCanaryResponse
  request :: (Service -> Service) -> GetCanary -> Request GetCanary
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetCanary
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetCanary)))
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 Canary -> Int -> GetCanaryResponse
GetCanaryResponse'
            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
"Canary")
            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 GetCanary where
  hashWithSalt :: Int -> GetCanary -> Int
hashWithSalt Int
_salt GetCanary' {Text
name :: Text
$sel:name:GetCanary' :: GetCanary -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name

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

instance Data.ToHeaders GetCanary where
  toHeaders :: GetCanary -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToPath GetCanary where
  toPath :: GetCanary -> ByteString
toPath GetCanary' {Text
name :: Text
$sel:name:GetCanary' :: GetCanary -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"/canary/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
name]

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

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

-- |
-- Create a value of 'GetCanaryResponse' 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:
--
-- 'canary', 'getCanaryResponse_canary' - A structure that contains the full information about the canary.
--
-- 'httpStatus', 'getCanaryResponse_httpStatus' - The response's http status code.
newGetCanaryResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetCanaryResponse
newGetCanaryResponse :: Int -> GetCanaryResponse
newGetCanaryResponse Int
pHttpStatus_ =
  GetCanaryResponse'
    { $sel:canary:GetCanaryResponse' :: Maybe Canary
canary = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetCanaryResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A structure that contains the full information about the canary.
getCanaryResponse_canary :: Lens.Lens' GetCanaryResponse (Prelude.Maybe Canary)
getCanaryResponse_canary :: Lens' GetCanaryResponse (Maybe Canary)
getCanaryResponse_canary = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCanaryResponse' {Maybe Canary
canary :: Maybe Canary
$sel:canary:GetCanaryResponse' :: GetCanaryResponse -> Maybe Canary
canary} -> Maybe Canary
canary) (\s :: GetCanaryResponse
s@GetCanaryResponse' {} Maybe Canary
a -> GetCanaryResponse
s {$sel:canary:GetCanaryResponse' :: Maybe Canary
canary = Maybe Canary
a} :: GetCanaryResponse)

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

instance Prelude.NFData GetCanaryResponse where
  rnf :: GetCanaryResponse -> ()
rnf GetCanaryResponse' {Int
Maybe Canary
httpStatus :: Int
canary :: Maybe Canary
$sel:httpStatus:GetCanaryResponse' :: GetCanaryResponse -> Int
$sel:canary:GetCanaryResponse' :: GetCanaryResponse -> Maybe Canary
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Canary
canary
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus