{-# 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.LookoutVision.DetectAnomalies
-- 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)
--
-- Detects anomalies in an image that you supply.
--
-- The response from @DetectAnomalies@ includes a boolean prediction that
-- the image contains one or more anomalies and a confidence value for the
-- prediction.
--
-- Before calling @DetectAnomalies@, you must first start your model with
-- the StartModel operation. You are charged for the amount of time, in
-- minutes, that a model runs and for the number of anomaly detection units
-- that your model uses. If you are not using a model, use the StopModel
-- operation to stop your model.
--
-- This operation requires permissions to perform the
-- @lookoutvision:DetectAnomalies@ operation.
module Amazonka.LookoutVision.DetectAnomalies
  ( -- * Creating a Request
    DetectAnomalies (..),
    newDetectAnomalies,

    -- * Request Lenses
    detectAnomalies_projectName,
    detectAnomalies_modelVersion,
    detectAnomalies_contentType,
    detectAnomalies_body,

    -- * Destructuring the Response
    DetectAnomaliesResponse (..),
    newDetectAnomaliesResponse,

    -- * Response Lenses
    detectAnomaliesResponse_detectAnomalyResult,
    detectAnomaliesResponse_httpStatus,
  )
where

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

-- | /See:/ 'newDetectAnomalies' smart constructor.
data DetectAnomalies = DetectAnomalies'
  { -- | The name of the project that contains the model version that you want to
    -- use.
    DetectAnomalies -> Text
projectName :: Prelude.Text,
    -- | The version of the model that you want to use.
    DetectAnomalies -> Text
modelVersion :: Prelude.Text,
    -- | The type of the image passed in @Body@. Valid values are @image\/png@
    -- (PNG format images) and @image\/jpeg@ (JPG format images).
    DetectAnomalies -> Text
contentType :: Prelude.Text,
    -- | The unencrypted image bytes that you want to analyze.
    DetectAnomalies -> HashedBody
body :: Core.HashedBody
  }
  deriving (Int -> DetectAnomalies -> ShowS
[DetectAnomalies] -> ShowS
DetectAnomalies -> String
(Int -> DetectAnomalies -> ShowS)
-> (DetectAnomalies -> String)
-> ([DetectAnomalies] -> ShowS)
-> Show DetectAnomalies
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetectAnomalies] -> ShowS
$cshowList :: [DetectAnomalies] -> ShowS
show :: DetectAnomalies -> String
$cshow :: DetectAnomalies -> String
showsPrec :: Int -> DetectAnomalies -> ShowS
$cshowsPrec :: Int -> DetectAnomalies -> ShowS
Prelude.Show, (forall x. DetectAnomalies -> Rep DetectAnomalies x)
-> (forall x. Rep DetectAnomalies x -> DetectAnomalies)
-> Generic DetectAnomalies
forall x. Rep DetectAnomalies x -> DetectAnomalies
forall x. DetectAnomalies -> Rep DetectAnomalies x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DetectAnomalies x -> DetectAnomalies
$cfrom :: forall x. DetectAnomalies -> Rep DetectAnomalies x
Prelude.Generic)

-- |
-- Create a value of 'DetectAnomalies' 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:
--
-- 'projectName', 'detectAnomalies_projectName' - The name of the project that contains the model version that you want to
-- use.
--
-- 'modelVersion', 'detectAnomalies_modelVersion' - The version of the model that you want to use.
--
-- 'contentType', 'detectAnomalies_contentType' - The type of the image passed in @Body@. Valid values are @image\/png@
-- (PNG format images) and @image\/jpeg@ (JPG format images).
--
-- 'body', 'detectAnomalies_body' - The unencrypted image bytes that you want to analyze.
newDetectAnomalies ::
  -- | 'projectName'
  Prelude.Text ->
  -- | 'modelVersion'
  Prelude.Text ->
  -- | 'contentType'
  Prelude.Text ->
  -- | 'body'
  Core.HashedBody ->
  DetectAnomalies
newDetectAnomalies :: Text -> Text -> Text -> HashedBody -> DetectAnomalies
newDetectAnomalies
  Text
pProjectName_
  Text
pModelVersion_
  Text
pContentType_
  HashedBody
pBody_ =
    DetectAnomalies' :: Text -> Text -> Text -> HashedBody -> DetectAnomalies
DetectAnomalies'
      { $sel:projectName:DetectAnomalies' :: Text
projectName = Text
pProjectName_,
        $sel:modelVersion:DetectAnomalies' :: Text
modelVersion = Text
pModelVersion_,
        $sel:contentType:DetectAnomalies' :: Text
contentType = Text
pContentType_,
        $sel:body:DetectAnomalies' :: HashedBody
body = HashedBody
pBody_
      }

-- | The name of the project that contains the model version that you want to
-- use.
detectAnomalies_projectName :: Lens.Lens' DetectAnomalies Prelude.Text
detectAnomalies_projectName :: (Text -> f Text) -> DetectAnomalies -> f DetectAnomalies
detectAnomalies_projectName = (DetectAnomalies -> Text)
-> (DetectAnomalies -> Text -> DetectAnomalies)
-> Lens DetectAnomalies DetectAnomalies Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectAnomalies' {Text
projectName :: Text
$sel:projectName:DetectAnomalies' :: DetectAnomalies -> Text
projectName} -> Text
projectName) (\s :: DetectAnomalies
s@DetectAnomalies' {} Text
a -> DetectAnomalies
s {$sel:projectName:DetectAnomalies' :: Text
projectName = Text
a} :: DetectAnomalies)

-- | The version of the model that you want to use.
detectAnomalies_modelVersion :: Lens.Lens' DetectAnomalies Prelude.Text
detectAnomalies_modelVersion :: (Text -> f Text) -> DetectAnomalies -> f DetectAnomalies
detectAnomalies_modelVersion = (DetectAnomalies -> Text)
-> (DetectAnomalies -> Text -> DetectAnomalies)
-> Lens DetectAnomalies DetectAnomalies Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectAnomalies' {Text
modelVersion :: Text
$sel:modelVersion:DetectAnomalies' :: DetectAnomalies -> Text
modelVersion} -> Text
modelVersion) (\s :: DetectAnomalies
s@DetectAnomalies' {} Text
a -> DetectAnomalies
s {$sel:modelVersion:DetectAnomalies' :: Text
modelVersion = Text
a} :: DetectAnomalies)

-- | The type of the image passed in @Body@. Valid values are @image\/png@
-- (PNG format images) and @image\/jpeg@ (JPG format images).
detectAnomalies_contentType :: Lens.Lens' DetectAnomalies Prelude.Text
detectAnomalies_contentType :: (Text -> f Text) -> DetectAnomalies -> f DetectAnomalies
detectAnomalies_contentType = (DetectAnomalies -> Text)
-> (DetectAnomalies -> Text -> DetectAnomalies)
-> Lens DetectAnomalies DetectAnomalies Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectAnomalies' {Text
contentType :: Text
$sel:contentType:DetectAnomalies' :: DetectAnomalies -> Text
contentType} -> Text
contentType) (\s :: DetectAnomalies
s@DetectAnomalies' {} Text
a -> DetectAnomalies
s {$sel:contentType:DetectAnomalies' :: Text
contentType = Text
a} :: DetectAnomalies)

-- | The unencrypted image bytes that you want to analyze.
detectAnomalies_body :: Lens.Lens' DetectAnomalies Core.HashedBody
detectAnomalies_body :: (HashedBody -> f HashedBody)
-> DetectAnomalies -> f DetectAnomalies
detectAnomalies_body = (DetectAnomalies -> HashedBody)
-> (DetectAnomalies -> HashedBody -> DetectAnomalies)
-> Lens DetectAnomalies DetectAnomalies HashedBody HashedBody
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectAnomalies' {HashedBody
body :: HashedBody
$sel:body:DetectAnomalies' :: DetectAnomalies -> HashedBody
body} -> HashedBody
body) (\s :: DetectAnomalies
s@DetectAnomalies' {} HashedBody
a -> DetectAnomalies
s {$sel:body:DetectAnomalies' :: HashedBody
body = HashedBody
a} :: DetectAnomalies)

instance Core.AWSRequest DetectAnomalies where
  type
    AWSResponse DetectAnomalies =
      DetectAnomaliesResponse
  request :: DetectAnomalies -> Request DetectAnomalies
request = Service -> DetectAnomalies -> Request DetectAnomalies
forall a. (ToRequest a, ToBody a) => Service -> a -> Request a
Request.postBody Service
defaultService
  response :: Logger
-> Service
-> Proxy DetectAnomalies
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DetectAnomalies)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DetectAnomalies))
-> Logger
-> Service
-> Proxy DetectAnomalies
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DetectAnomalies)))
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 DetectAnomalyResult -> Int -> DetectAnomaliesResponse
DetectAnomaliesResponse'
            (Maybe DetectAnomalyResult -> Int -> DetectAnomaliesResponse)
-> Either String (Maybe DetectAnomalyResult)
-> Either String (Int -> DetectAnomaliesResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe DetectAnomalyResult)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"DetectAnomalyResult")
            Either String (Int -> DetectAnomaliesResponse)
-> Either String Int -> Either String DetectAnomaliesResponse
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 Core.ToBody DetectAnomalies where
  toBody :: DetectAnomalies -> RequestBody
toBody DetectAnomalies' {Text
HashedBody
body :: HashedBody
contentType :: Text
modelVersion :: Text
projectName :: Text
$sel:body:DetectAnomalies' :: DetectAnomalies -> HashedBody
$sel:contentType:DetectAnomalies' :: DetectAnomalies -> Text
$sel:modelVersion:DetectAnomalies' :: DetectAnomalies -> Text
$sel:projectName:DetectAnomalies' :: DetectAnomalies -> Text
..} = HashedBody -> RequestBody
forall a. ToBody a => a -> RequestBody
Core.toBody HashedBody
body

instance Core.ToHeaders DetectAnomalies where
  toHeaders :: DetectAnomalies -> ResponseHeaders
toHeaders DetectAnomalies' {Text
HashedBody
body :: HashedBody
contentType :: Text
modelVersion :: Text
projectName :: Text
$sel:body:DetectAnomalies' :: DetectAnomalies -> HashedBody
$sel:contentType:DetectAnomalies' :: DetectAnomalies -> Text
$sel:modelVersion:DetectAnomalies' :: DetectAnomalies -> Text
$sel:projectName:DetectAnomalies' :: DetectAnomalies -> Text
..} =
    [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [HeaderName
"Content-Type" HeaderName -> Text -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# Text
contentType]

instance Core.ToPath DetectAnomalies where
  toPath :: DetectAnomalies -> ByteString
toPath DetectAnomalies' {Text
HashedBody
body :: HashedBody
contentType :: Text
modelVersion :: Text
projectName :: Text
$sel:body:DetectAnomalies' :: DetectAnomalies -> HashedBody
$sel:contentType:DetectAnomalies' :: DetectAnomalies -> Text
$sel:modelVersion:DetectAnomalies' :: DetectAnomalies -> Text
$sel:projectName:DetectAnomalies' :: DetectAnomalies -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/2020-11-20/projects/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
projectName,
        ByteString
"/models/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
modelVersion,
        ByteString
"/detect"
      ]

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

-- | /See:/ 'newDetectAnomaliesResponse' smart constructor.
data DetectAnomaliesResponse = DetectAnomaliesResponse'
  { -- | The results of the @DetectAnomalies@ operation.
    DetectAnomaliesResponse -> Maybe DetectAnomalyResult
detectAnomalyResult :: Prelude.Maybe DetectAnomalyResult,
    -- | The response's http status code.
    DetectAnomaliesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DetectAnomaliesResponse -> DetectAnomaliesResponse -> Bool
(DetectAnomaliesResponse -> DetectAnomaliesResponse -> Bool)
-> (DetectAnomaliesResponse -> DetectAnomaliesResponse -> Bool)
-> Eq DetectAnomaliesResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DetectAnomaliesResponse -> DetectAnomaliesResponse -> Bool
$c/= :: DetectAnomaliesResponse -> DetectAnomaliesResponse -> Bool
== :: DetectAnomaliesResponse -> DetectAnomaliesResponse -> Bool
$c== :: DetectAnomaliesResponse -> DetectAnomaliesResponse -> Bool
Prelude.Eq, ReadPrec [DetectAnomaliesResponse]
ReadPrec DetectAnomaliesResponse
Int -> ReadS DetectAnomaliesResponse
ReadS [DetectAnomaliesResponse]
(Int -> ReadS DetectAnomaliesResponse)
-> ReadS [DetectAnomaliesResponse]
-> ReadPrec DetectAnomaliesResponse
-> ReadPrec [DetectAnomaliesResponse]
-> Read DetectAnomaliesResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DetectAnomaliesResponse]
$creadListPrec :: ReadPrec [DetectAnomaliesResponse]
readPrec :: ReadPrec DetectAnomaliesResponse
$creadPrec :: ReadPrec DetectAnomaliesResponse
readList :: ReadS [DetectAnomaliesResponse]
$creadList :: ReadS [DetectAnomaliesResponse]
readsPrec :: Int -> ReadS DetectAnomaliesResponse
$creadsPrec :: Int -> ReadS DetectAnomaliesResponse
Prelude.Read, Int -> DetectAnomaliesResponse -> ShowS
[DetectAnomaliesResponse] -> ShowS
DetectAnomaliesResponse -> String
(Int -> DetectAnomaliesResponse -> ShowS)
-> (DetectAnomaliesResponse -> String)
-> ([DetectAnomaliesResponse] -> ShowS)
-> Show DetectAnomaliesResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetectAnomaliesResponse] -> ShowS
$cshowList :: [DetectAnomaliesResponse] -> ShowS
show :: DetectAnomaliesResponse -> String
$cshow :: DetectAnomaliesResponse -> String
showsPrec :: Int -> DetectAnomaliesResponse -> ShowS
$cshowsPrec :: Int -> DetectAnomaliesResponse -> ShowS
Prelude.Show, (forall x.
 DetectAnomaliesResponse -> Rep DetectAnomaliesResponse x)
-> (forall x.
    Rep DetectAnomaliesResponse x -> DetectAnomaliesResponse)
-> Generic DetectAnomaliesResponse
forall x. Rep DetectAnomaliesResponse x -> DetectAnomaliesResponse
forall x. DetectAnomaliesResponse -> Rep DetectAnomaliesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DetectAnomaliesResponse x -> DetectAnomaliesResponse
$cfrom :: forall x. DetectAnomaliesResponse -> Rep DetectAnomaliesResponse x
Prelude.Generic)

-- |
-- Create a value of 'DetectAnomaliesResponse' 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:
--
-- 'detectAnomalyResult', 'detectAnomaliesResponse_detectAnomalyResult' - The results of the @DetectAnomalies@ operation.
--
-- 'httpStatus', 'detectAnomaliesResponse_httpStatus' - The response's http status code.
newDetectAnomaliesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DetectAnomaliesResponse
newDetectAnomaliesResponse :: Int -> DetectAnomaliesResponse
newDetectAnomaliesResponse Int
pHttpStatus_ =
  DetectAnomaliesResponse' :: Maybe DetectAnomalyResult -> Int -> DetectAnomaliesResponse
DetectAnomaliesResponse'
    { $sel:detectAnomalyResult:DetectAnomaliesResponse' :: Maybe DetectAnomalyResult
detectAnomalyResult =
        Maybe DetectAnomalyResult
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DetectAnomaliesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The results of the @DetectAnomalies@ operation.
detectAnomaliesResponse_detectAnomalyResult :: Lens.Lens' DetectAnomaliesResponse (Prelude.Maybe DetectAnomalyResult)
detectAnomaliesResponse_detectAnomalyResult :: (Maybe DetectAnomalyResult -> f (Maybe DetectAnomalyResult))
-> DetectAnomaliesResponse -> f DetectAnomaliesResponse
detectAnomaliesResponse_detectAnomalyResult = (DetectAnomaliesResponse -> Maybe DetectAnomalyResult)
-> (DetectAnomaliesResponse
    -> Maybe DetectAnomalyResult -> DetectAnomaliesResponse)
-> Lens
     DetectAnomaliesResponse
     DetectAnomaliesResponse
     (Maybe DetectAnomalyResult)
     (Maybe DetectAnomalyResult)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectAnomaliesResponse' {Maybe DetectAnomalyResult
detectAnomalyResult :: Maybe DetectAnomalyResult
$sel:detectAnomalyResult:DetectAnomaliesResponse' :: DetectAnomaliesResponse -> Maybe DetectAnomalyResult
detectAnomalyResult} -> Maybe DetectAnomalyResult
detectAnomalyResult) (\s :: DetectAnomaliesResponse
s@DetectAnomaliesResponse' {} Maybe DetectAnomalyResult
a -> DetectAnomaliesResponse
s {$sel:detectAnomalyResult:DetectAnomaliesResponse' :: Maybe DetectAnomalyResult
detectAnomalyResult = Maybe DetectAnomalyResult
a} :: DetectAnomaliesResponse)

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

instance Prelude.NFData DetectAnomaliesResponse