{-# 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.IoTEventsData.DescribeAlarm
-- 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 information about an alarm.
module Amazonka.IoTEventsData.DescribeAlarm
  ( -- * Creating a Request
    DescribeAlarm (..),
    newDescribeAlarm,

    -- * Request Lenses
    describeAlarm_keyValue,
    describeAlarm_alarmModelName,

    -- * Destructuring the Response
    DescribeAlarmResponse (..),
    newDescribeAlarmResponse,

    -- * Response Lenses
    describeAlarmResponse_alarm,
    describeAlarmResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IoTEventsData.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newDescribeAlarm' smart constructor.
data DescribeAlarm = DescribeAlarm'
  { -- | The value of the key used as a filter to select only the alarms
    -- associated with the
    -- <https://docs.aws.amazon.com/iotevents/latest/apireference/API_CreateAlarmModel.html#iotevents-CreateAlarmModel-request-key key>.
    DescribeAlarm -> Maybe Text
keyValue :: Prelude.Maybe Prelude.Text,
    -- | The name of the alarm model.
    DescribeAlarm -> Text
alarmModelName :: Prelude.Text
  }
  deriving (DescribeAlarm -> DescribeAlarm -> Bool
(DescribeAlarm -> DescribeAlarm -> Bool)
-> (DescribeAlarm -> DescribeAlarm -> Bool) -> Eq DescribeAlarm
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeAlarm -> DescribeAlarm -> Bool
$c/= :: DescribeAlarm -> DescribeAlarm -> Bool
== :: DescribeAlarm -> DescribeAlarm -> Bool
$c== :: DescribeAlarm -> DescribeAlarm -> Bool
Prelude.Eq, ReadPrec [DescribeAlarm]
ReadPrec DescribeAlarm
Int -> ReadS DescribeAlarm
ReadS [DescribeAlarm]
(Int -> ReadS DescribeAlarm)
-> ReadS [DescribeAlarm]
-> ReadPrec DescribeAlarm
-> ReadPrec [DescribeAlarm]
-> Read DescribeAlarm
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeAlarm]
$creadListPrec :: ReadPrec [DescribeAlarm]
readPrec :: ReadPrec DescribeAlarm
$creadPrec :: ReadPrec DescribeAlarm
readList :: ReadS [DescribeAlarm]
$creadList :: ReadS [DescribeAlarm]
readsPrec :: Int -> ReadS DescribeAlarm
$creadsPrec :: Int -> ReadS DescribeAlarm
Prelude.Read, Int -> DescribeAlarm -> ShowS
[DescribeAlarm] -> ShowS
DescribeAlarm -> String
(Int -> DescribeAlarm -> ShowS)
-> (DescribeAlarm -> String)
-> ([DescribeAlarm] -> ShowS)
-> Show DescribeAlarm
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeAlarm] -> ShowS
$cshowList :: [DescribeAlarm] -> ShowS
show :: DescribeAlarm -> String
$cshow :: DescribeAlarm -> String
showsPrec :: Int -> DescribeAlarm -> ShowS
$cshowsPrec :: Int -> DescribeAlarm -> ShowS
Prelude.Show, (forall x. DescribeAlarm -> Rep DescribeAlarm x)
-> (forall x. Rep DescribeAlarm x -> DescribeAlarm)
-> Generic DescribeAlarm
forall x. Rep DescribeAlarm x -> DescribeAlarm
forall x. DescribeAlarm -> Rep DescribeAlarm x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeAlarm x -> DescribeAlarm
$cfrom :: forall x. DescribeAlarm -> Rep DescribeAlarm x
Prelude.Generic)

-- |
-- Create a value of 'DescribeAlarm' 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:
--
-- 'keyValue', 'describeAlarm_keyValue' - The value of the key used as a filter to select only the alarms
-- associated with the
-- <https://docs.aws.amazon.com/iotevents/latest/apireference/API_CreateAlarmModel.html#iotevents-CreateAlarmModel-request-key key>.
--
-- 'alarmModelName', 'describeAlarm_alarmModelName' - The name of the alarm model.
newDescribeAlarm ::
  -- | 'alarmModelName'
  Prelude.Text ->
  DescribeAlarm
newDescribeAlarm :: Text -> DescribeAlarm
newDescribeAlarm Text
pAlarmModelName_ =
  DescribeAlarm' :: Maybe Text -> Text -> DescribeAlarm
DescribeAlarm'
    { $sel:keyValue:DescribeAlarm' :: Maybe Text
keyValue = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:alarmModelName:DescribeAlarm' :: Text
alarmModelName = Text
pAlarmModelName_
    }

-- | The value of the key used as a filter to select only the alarms
-- associated with the
-- <https://docs.aws.amazon.com/iotevents/latest/apireference/API_CreateAlarmModel.html#iotevents-CreateAlarmModel-request-key key>.
describeAlarm_keyValue :: Lens.Lens' DescribeAlarm (Prelude.Maybe Prelude.Text)
describeAlarm_keyValue :: (Maybe Text -> f (Maybe Text)) -> DescribeAlarm -> f DescribeAlarm
describeAlarm_keyValue = (DescribeAlarm -> Maybe Text)
-> (DescribeAlarm -> Maybe Text -> DescribeAlarm)
-> Lens DescribeAlarm DescribeAlarm (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeAlarm' {Maybe Text
keyValue :: Maybe Text
$sel:keyValue:DescribeAlarm' :: DescribeAlarm -> Maybe Text
keyValue} -> Maybe Text
keyValue) (\s :: DescribeAlarm
s@DescribeAlarm' {} Maybe Text
a -> DescribeAlarm
s {$sel:keyValue:DescribeAlarm' :: Maybe Text
keyValue = Maybe Text
a} :: DescribeAlarm)

-- | The name of the alarm model.
describeAlarm_alarmModelName :: Lens.Lens' DescribeAlarm Prelude.Text
describeAlarm_alarmModelName :: (Text -> f Text) -> DescribeAlarm -> f DescribeAlarm
describeAlarm_alarmModelName = (DescribeAlarm -> Text)
-> (DescribeAlarm -> Text -> DescribeAlarm)
-> Lens DescribeAlarm DescribeAlarm Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeAlarm' {Text
alarmModelName :: Text
$sel:alarmModelName:DescribeAlarm' :: DescribeAlarm -> Text
alarmModelName} -> Text
alarmModelName) (\s :: DescribeAlarm
s@DescribeAlarm' {} Text
a -> DescribeAlarm
s {$sel:alarmModelName:DescribeAlarm' :: Text
alarmModelName = Text
a} :: DescribeAlarm)

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

instance Prelude.NFData DescribeAlarm

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

instance Core.ToPath DescribeAlarm where
  toPath :: DescribeAlarm -> ByteString
toPath DescribeAlarm' {Maybe Text
Text
alarmModelName :: Text
keyValue :: Maybe Text
$sel:alarmModelName:DescribeAlarm' :: DescribeAlarm -> Text
$sel:keyValue:DescribeAlarm' :: DescribeAlarm -> Maybe Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/alarms/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
alarmModelName, ByteString
"/keyValues/"]

instance Core.ToQuery DescribeAlarm where
  toQuery :: DescribeAlarm -> QueryString
toQuery DescribeAlarm' {Maybe Text
Text
alarmModelName :: Text
keyValue :: Maybe Text
$sel:alarmModelName:DescribeAlarm' :: DescribeAlarm -> Text
$sel:keyValue:DescribeAlarm' :: DescribeAlarm -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"keyValue" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
keyValue]

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

-- |
-- Create a value of 'DescribeAlarmResponse' 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:
--
-- 'alarm', 'describeAlarmResponse_alarm' - Contains information about an alarm.
--
-- 'httpStatus', 'describeAlarmResponse_httpStatus' - The response's http status code.
newDescribeAlarmResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeAlarmResponse
newDescribeAlarmResponse :: Int -> DescribeAlarmResponse
newDescribeAlarmResponse Int
pHttpStatus_ =
  DescribeAlarmResponse' :: Maybe Alarm -> Int -> DescribeAlarmResponse
DescribeAlarmResponse'
    { $sel:alarm:DescribeAlarmResponse' :: Maybe Alarm
alarm = Maybe Alarm
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeAlarmResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Contains information about an alarm.
describeAlarmResponse_alarm :: Lens.Lens' DescribeAlarmResponse (Prelude.Maybe Alarm)
describeAlarmResponse_alarm :: (Maybe Alarm -> f (Maybe Alarm))
-> DescribeAlarmResponse -> f DescribeAlarmResponse
describeAlarmResponse_alarm = (DescribeAlarmResponse -> Maybe Alarm)
-> (DescribeAlarmResponse -> Maybe Alarm -> DescribeAlarmResponse)
-> Lens
     DescribeAlarmResponse
     DescribeAlarmResponse
     (Maybe Alarm)
     (Maybe Alarm)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeAlarmResponse' {Maybe Alarm
alarm :: Maybe Alarm
$sel:alarm:DescribeAlarmResponse' :: DescribeAlarmResponse -> Maybe Alarm
alarm} -> Maybe Alarm
alarm) (\s :: DescribeAlarmResponse
s@DescribeAlarmResponse' {} Maybe Alarm
a -> DescribeAlarmResponse
s {$sel:alarm:DescribeAlarmResponse' :: Maybe Alarm
alarm = Maybe Alarm
a} :: DescribeAlarmResponse)

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

instance Prelude.NFData DescribeAlarmResponse