{-# 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.IoTEvents.StartDetectorModelAnalysis
-- 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)
--
-- Performs an analysis of your detector model. For more information, see
-- <https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-analyze-api.html Troubleshooting a detector model>
-- in the /AWS IoT Events Developer Guide/.
module Amazonka.IoTEvents.StartDetectorModelAnalysis
  ( -- * Creating a Request
    StartDetectorModelAnalysis (..),
    newStartDetectorModelAnalysis,

    -- * Request Lenses
    startDetectorModelAnalysis_detectorModelDefinition,

    -- * Destructuring the Response
    StartDetectorModelAnalysisResponse (..),
    newStartDetectorModelAnalysisResponse,

    -- * Response Lenses
    startDetectorModelAnalysisResponse_analysisId,
    startDetectorModelAnalysisResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IoTEvents.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:/ 'newStartDetectorModelAnalysis' smart constructor.
data StartDetectorModelAnalysis = StartDetectorModelAnalysis'
  { StartDetectorModelAnalysis -> DetectorModelDefinition
detectorModelDefinition :: DetectorModelDefinition
  }
  deriving (StartDetectorModelAnalysis -> StartDetectorModelAnalysis -> Bool
(StartDetectorModelAnalysis -> StartDetectorModelAnalysis -> Bool)
-> (StartDetectorModelAnalysis
    -> StartDetectorModelAnalysis -> Bool)
-> Eq StartDetectorModelAnalysis
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartDetectorModelAnalysis -> StartDetectorModelAnalysis -> Bool
$c/= :: StartDetectorModelAnalysis -> StartDetectorModelAnalysis -> Bool
== :: StartDetectorModelAnalysis -> StartDetectorModelAnalysis -> Bool
$c== :: StartDetectorModelAnalysis -> StartDetectorModelAnalysis -> Bool
Prelude.Eq, ReadPrec [StartDetectorModelAnalysis]
ReadPrec StartDetectorModelAnalysis
Int -> ReadS StartDetectorModelAnalysis
ReadS [StartDetectorModelAnalysis]
(Int -> ReadS StartDetectorModelAnalysis)
-> ReadS [StartDetectorModelAnalysis]
-> ReadPrec StartDetectorModelAnalysis
-> ReadPrec [StartDetectorModelAnalysis]
-> Read StartDetectorModelAnalysis
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartDetectorModelAnalysis]
$creadListPrec :: ReadPrec [StartDetectorModelAnalysis]
readPrec :: ReadPrec StartDetectorModelAnalysis
$creadPrec :: ReadPrec StartDetectorModelAnalysis
readList :: ReadS [StartDetectorModelAnalysis]
$creadList :: ReadS [StartDetectorModelAnalysis]
readsPrec :: Int -> ReadS StartDetectorModelAnalysis
$creadsPrec :: Int -> ReadS StartDetectorModelAnalysis
Prelude.Read, Int -> StartDetectorModelAnalysis -> ShowS
[StartDetectorModelAnalysis] -> ShowS
StartDetectorModelAnalysis -> String
(Int -> StartDetectorModelAnalysis -> ShowS)
-> (StartDetectorModelAnalysis -> String)
-> ([StartDetectorModelAnalysis] -> ShowS)
-> Show StartDetectorModelAnalysis
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartDetectorModelAnalysis] -> ShowS
$cshowList :: [StartDetectorModelAnalysis] -> ShowS
show :: StartDetectorModelAnalysis -> String
$cshow :: StartDetectorModelAnalysis -> String
showsPrec :: Int -> StartDetectorModelAnalysis -> ShowS
$cshowsPrec :: Int -> StartDetectorModelAnalysis -> ShowS
Prelude.Show, (forall x.
 StartDetectorModelAnalysis -> Rep StartDetectorModelAnalysis x)
-> (forall x.
    Rep StartDetectorModelAnalysis x -> StartDetectorModelAnalysis)
-> Generic StartDetectorModelAnalysis
forall x.
Rep StartDetectorModelAnalysis x -> StartDetectorModelAnalysis
forall x.
StartDetectorModelAnalysis -> Rep StartDetectorModelAnalysis x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep StartDetectorModelAnalysis x -> StartDetectorModelAnalysis
$cfrom :: forall x.
StartDetectorModelAnalysis -> Rep StartDetectorModelAnalysis x
Prelude.Generic)

-- |
-- Create a value of 'StartDetectorModelAnalysis' 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:
--
-- 'detectorModelDefinition', 'startDetectorModelAnalysis_detectorModelDefinition' - Undocumented member.
newStartDetectorModelAnalysis ::
  -- | 'detectorModelDefinition'
  DetectorModelDefinition ->
  StartDetectorModelAnalysis
newStartDetectorModelAnalysis :: DetectorModelDefinition -> StartDetectorModelAnalysis
newStartDetectorModelAnalysis
  DetectorModelDefinition
pDetectorModelDefinition_ =
    StartDetectorModelAnalysis' :: DetectorModelDefinition -> StartDetectorModelAnalysis
StartDetectorModelAnalysis'
      { $sel:detectorModelDefinition:StartDetectorModelAnalysis' :: DetectorModelDefinition
detectorModelDefinition =
          DetectorModelDefinition
pDetectorModelDefinition_
      }

-- | Undocumented member.
startDetectorModelAnalysis_detectorModelDefinition :: Lens.Lens' StartDetectorModelAnalysis DetectorModelDefinition
startDetectorModelAnalysis_detectorModelDefinition :: (DetectorModelDefinition -> f DetectorModelDefinition)
-> StartDetectorModelAnalysis -> f StartDetectorModelAnalysis
startDetectorModelAnalysis_detectorModelDefinition = (StartDetectorModelAnalysis -> DetectorModelDefinition)
-> (StartDetectorModelAnalysis
    -> DetectorModelDefinition -> StartDetectorModelAnalysis)
-> Lens
     StartDetectorModelAnalysis
     StartDetectorModelAnalysis
     DetectorModelDefinition
     DetectorModelDefinition
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartDetectorModelAnalysis' {DetectorModelDefinition
detectorModelDefinition :: DetectorModelDefinition
$sel:detectorModelDefinition:StartDetectorModelAnalysis' :: StartDetectorModelAnalysis -> DetectorModelDefinition
detectorModelDefinition} -> DetectorModelDefinition
detectorModelDefinition) (\s :: StartDetectorModelAnalysis
s@StartDetectorModelAnalysis' {} DetectorModelDefinition
a -> StartDetectorModelAnalysis
s {$sel:detectorModelDefinition:StartDetectorModelAnalysis' :: DetectorModelDefinition
detectorModelDefinition = DetectorModelDefinition
a} :: StartDetectorModelAnalysis)

instance Core.AWSRequest StartDetectorModelAnalysis where
  type
    AWSResponse StartDetectorModelAnalysis =
      StartDetectorModelAnalysisResponse
  request :: StartDetectorModelAnalysis -> Request StartDetectorModelAnalysis
request = Service
-> StartDetectorModelAnalysis -> Request StartDetectorModelAnalysis
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy StartDetectorModelAnalysis
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse StartDetectorModelAnalysis)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse StartDetectorModelAnalysis))
-> Logger
-> Service
-> Proxy StartDetectorModelAnalysis
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse StartDetectorModelAnalysis)))
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 -> Int -> StartDetectorModelAnalysisResponse
StartDetectorModelAnalysisResponse'
            (Maybe Text -> Int -> StartDetectorModelAnalysisResponse)
-> Either String (Maybe Text)
-> Either String (Int -> StartDetectorModelAnalysisResponse)
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
"analysisId")
            Either String (Int -> StartDetectorModelAnalysisResponse)
-> Either String Int
-> Either String StartDetectorModelAnalysisResponse
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 StartDetectorModelAnalysis

instance Prelude.NFData StartDetectorModelAnalysis

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

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

instance Core.ToPath StartDetectorModelAnalysis where
  toPath :: StartDetectorModelAnalysis -> ByteString
toPath = ByteString -> StartDetectorModelAnalysis -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/analysis/detector-models/"

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

-- | /See:/ 'newStartDetectorModelAnalysisResponse' smart constructor.
data StartDetectorModelAnalysisResponse = StartDetectorModelAnalysisResponse'
  { -- | The ID that you can use to retrieve the analysis result.
    StartDetectorModelAnalysisResponse -> Maybe Text
analysisId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    StartDetectorModelAnalysisResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StartDetectorModelAnalysisResponse
-> StartDetectorModelAnalysisResponse -> Bool
(StartDetectorModelAnalysisResponse
 -> StartDetectorModelAnalysisResponse -> Bool)
-> (StartDetectorModelAnalysisResponse
    -> StartDetectorModelAnalysisResponse -> Bool)
-> Eq StartDetectorModelAnalysisResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartDetectorModelAnalysisResponse
-> StartDetectorModelAnalysisResponse -> Bool
$c/= :: StartDetectorModelAnalysisResponse
-> StartDetectorModelAnalysisResponse -> Bool
== :: StartDetectorModelAnalysisResponse
-> StartDetectorModelAnalysisResponse -> Bool
$c== :: StartDetectorModelAnalysisResponse
-> StartDetectorModelAnalysisResponse -> Bool
Prelude.Eq, ReadPrec [StartDetectorModelAnalysisResponse]
ReadPrec StartDetectorModelAnalysisResponse
Int -> ReadS StartDetectorModelAnalysisResponse
ReadS [StartDetectorModelAnalysisResponse]
(Int -> ReadS StartDetectorModelAnalysisResponse)
-> ReadS [StartDetectorModelAnalysisResponse]
-> ReadPrec StartDetectorModelAnalysisResponse
-> ReadPrec [StartDetectorModelAnalysisResponse]
-> Read StartDetectorModelAnalysisResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartDetectorModelAnalysisResponse]
$creadListPrec :: ReadPrec [StartDetectorModelAnalysisResponse]
readPrec :: ReadPrec StartDetectorModelAnalysisResponse
$creadPrec :: ReadPrec StartDetectorModelAnalysisResponse
readList :: ReadS [StartDetectorModelAnalysisResponse]
$creadList :: ReadS [StartDetectorModelAnalysisResponse]
readsPrec :: Int -> ReadS StartDetectorModelAnalysisResponse
$creadsPrec :: Int -> ReadS StartDetectorModelAnalysisResponse
Prelude.Read, Int -> StartDetectorModelAnalysisResponse -> ShowS
[StartDetectorModelAnalysisResponse] -> ShowS
StartDetectorModelAnalysisResponse -> String
(Int -> StartDetectorModelAnalysisResponse -> ShowS)
-> (StartDetectorModelAnalysisResponse -> String)
-> ([StartDetectorModelAnalysisResponse] -> ShowS)
-> Show StartDetectorModelAnalysisResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartDetectorModelAnalysisResponse] -> ShowS
$cshowList :: [StartDetectorModelAnalysisResponse] -> ShowS
show :: StartDetectorModelAnalysisResponse -> String
$cshow :: StartDetectorModelAnalysisResponse -> String
showsPrec :: Int -> StartDetectorModelAnalysisResponse -> ShowS
$cshowsPrec :: Int -> StartDetectorModelAnalysisResponse -> ShowS
Prelude.Show, (forall x.
 StartDetectorModelAnalysisResponse
 -> Rep StartDetectorModelAnalysisResponse x)
-> (forall x.
    Rep StartDetectorModelAnalysisResponse x
    -> StartDetectorModelAnalysisResponse)
-> Generic StartDetectorModelAnalysisResponse
forall x.
Rep StartDetectorModelAnalysisResponse x
-> StartDetectorModelAnalysisResponse
forall x.
StartDetectorModelAnalysisResponse
-> Rep StartDetectorModelAnalysisResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep StartDetectorModelAnalysisResponse x
-> StartDetectorModelAnalysisResponse
$cfrom :: forall x.
StartDetectorModelAnalysisResponse
-> Rep StartDetectorModelAnalysisResponse x
Prelude.Generic)

-- |
-- Create a value of 'StartDetectorModelAnalysisResponse' 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:
--
-- 'analysisId', 'startDetectorModelAnalysisResponse_analysisId' - The ID that you can use to retrieve the analysis result.
--
-- 'httpStatus', 'startDetectorModelAnalysisResponse_httpStatus' - The response's http status code.
newStartDetectorModelAnalysisResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StartDetectorModelAnalysisResponse
newStartDetectorModelAnalysisResponse :: Int -> StartDetectorModelAnalysisResponse
newStartDetectorModelAnalysisResponse Int
pHttpStatus_ =
  StartDetectorModelAnalysisResponse' :: Maybe Text -> Int -> StartDetectorModelAnalysisResponse
StartDetectorModelAnalysisResponse'
    { $sel:analysisId:StartDetectorModelAnalysisResponse' :: Maybe Text
analysisId =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StartDetectorModelAnalysisResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The ID that you can use to retrieve the analysis result.
startDetectorModelAnalysisResponse_analysisId :: Lens.Lens' StartDetectorModelAnalysisResponse (Prelude.Maybe Prelude.Text)
startDetectorModelAnalysisResponse_analysisId :: (Maybe Text -> f (Maybe Text))
-> StartDetectorModelAnalysisResponse
-> f StartDetectorModelAnalysisResponse
startDetectorModelAnalysisResponse_analysisId = (StartDetectorModelAnalysisResponse -> Maybe Text)
-> (StartDetectorModelAnalysisResponse
    -> Maybe Text -> StartDetectorModelAnalysisResponse)
-> Lens
     StartDetectorModelAnalysisResponse
     StartDetectorModelAnalysisResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartDetectorModelAnalysisResponse' {Maybe Text
analysisId :: Maybe Text
$sel:analysisId:StartDetectorModelAnalysisResponse' :: StartDetectorModelAnalysisResponse -> Maybe Text
analysisId} -> Maybe Text
analysisId) (\s :: StartDetectorModelAnalysisResponse
s@StartDetectorModelAnalysisResponse' {} Maybe Text
a -> StartDetectorModelAnalysisResponse
s {$sel:analysisId:StartDetectorModelAnalysisResponse' :: Maybe Text
analysisId = Maybe Text
a} :: StartDetectorModelAnalysisResponse)

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

instance
  Prelude.NFData
    StartDetectorModelAnalysisResponse