{-# 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.MachineLearning.Predict
-- 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)
--
-- Generates a prediction for the observation using the specified
-- @ML Model@.
--
-- __Note:__ Not all response parameters will be populated. Whether a
-- response parameter is populated depends on the type of model requested.
module Amazonka.MachineLearning.Predict
  ( -- * Creating a Request
    Predict (..),
    newPredict,

    -- * Request Lenses
    predict_mLModelId,
    predict_record,
    predict_predictEndpoint,

    -- * Destructuring the Response
    PredictResponse (..),
    newPredictResponse,

    -- * Response Lenses
    predictResponse_prediction,
    predictResponse_httpStatus,
  )
where

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

-- | /See:/ 'newPredict' smart constructor.
data Predict = Predict'
  { -- | A unique identifier of the @MLModel@.
    Predict -> Text
mLModelId :: Prelude.Text,
    Predict -> HashMap Text Text
record :: Prelude.HashMap Prelude.Text Prelude.Text,
    Predict -> Text
predictEndpoint :: Prelude.Text
  }
  deriving (Predict -> Predict -> Bool
(Predict -> Predict -> Bool)
-> (Predict -> Predict -> Bool) -> Eq Predict
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Predict -> Predict -> Bool
$c/= :: Predict -> Predict -> Bool
== :: Predict -> Predict -> Bool
$c== :: Predict -> Predict -> Bool
Prelude.Eq, ReadPrec [Predict]
ReadPrec Predict
Int -> ReadS Predict
ReadS [Predict]
(Int -> ReadS Predict)
-> ReadS [Predict]
-> ReadPrec Predict
-> ReadPrec [Predict]
-> Read Predict
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Predict]
$creadListPrec :: ReadPrec [Predict]
readPrec :: ReadPrec Predict
$creadPrec :: ReadPrec Predict
readList :: ReadS [Predict]
$creadList :: ReadS [Predict]
readsPrec :: Int -> ReadS Predict
$creadsPrec :: Int -> ReadS Predict
Prelude.Read, Int -> Predict -> ShowS
[Predict] -> ShowS
Predict -> String
(Int -> Predict -> ShowS)
-> (Predict -> String) -> ([Predict] -> ShowS) -> Show Predict
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Predict] -> ShowS
$cshowList :: [Predict] -> ShowS
show :: Predict -> String
$cshow :: Predict -> String
showsPrec :: Int -> Predict -> ShowS
$cshowsPrec :: Int -> Predict -> ShowS
Prelude.Show, (forall x. Predict -> Rep Predict x)
-> (forall x. Rep Predict x -> Predict) -> Generic Predict
forall x. Rep Predict x -> Predict
forall x. Predict -> Rep Predict x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Predict x -> Predict
$cfrom :: forall x. Predict -> Rep Predict x
Prelude.Generic)

-- |
-- Create a value of 'Predict' 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:
--
-- 'mLModelId', 'predict_mLModelId' - A unique identifier of the @MLModel@.
--
-- 'record', 'predict_record' - Undocumented member.
--
-- 'predictEndpoint', 'predict_predictEndpoint' - Undocumented member.
newPredict ::
  -- | 'mLModelId'
  Prelude.Text ->
  -- | 'predictEndpoint'
  Prelude.Text ->
  Predict
newPredict :: Text -> Text -> Predict
newPredict Text
pMLModelId_ Text
pPredictEndpoint_ =
  Predict' :: Text -> HashMap Text Text -> Text -> Predict
Predict'
    { $sel:mLModelId:Predict' :: Text
mLModelId = Text
pMLModelId_,
      $sel:record:Predict' :: HashMap Text Text
record = HashMap Text Text
forall a. Monoid a => a
Prelude.mempty,
      $sel:predictEndpoint:Predict' :: Text
predictEndpoint = Text
pPredictEndpoint_
    }

-- | A unique identifier of the @MLModel@.
predict_mLModelId :: Lens.Lens' Predict Prelude.Text
predict_mLModelId :: (Text -> f Text) -> Predict -> f Predict
predict_mLModelId = (Predict -> Text)
-> (Predict -> Text -> Predict) -> Lens Predict Predict Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Predict' {Text
mLModelId :: Text
$sel:mLModelId:Predict' :: Predict -> Text
mLModelId} -> Text
mLModelId) (\s :: Predict
s@Predict' {} Text
a -> Predict
s {$sel:mLModelId:Predict' :: Text
mLModelId = Text
a} :: Predict)

-- | Undocumented member.
predict_record :: Lens.Lens' Predict (Prelude.HashMap Prelude.Text Prelude.Text)
predict_record :: (HashMap Text Text -> f (HashMap Text Text))
-> Predict -> f Predict
predict_record = (Predict -> HashMap Text Text)
-> (Predict -> HashMap Text Text -> Predict)
-> Lens Predict Predict (HashMap Text Text) (HashMap Text Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Predict' {HashMap Text Text
record :: HashMap Text Text
$sel:record:Predict' :: Predict -> HashMap Text Text
record} -> HashMap Text Text
record) (\s :: Predict
s@Predict' {} HashMap Text Text
a -> Predict
s {$sel:record:Predict' :: HashMap Text Text
record = HashMap Text Text
a} :: Predict) ((HashMap Text Text -> f (HashMap Text Text))
 -> Predict -> f Predict)
-> ((HashMap Text Text -> f (HashMap Text Text))
    -> HashMap Text Text -> f (HashMap Text Text))
-> (HashMap Text Text -> f (HashMap Text Text))
-> Predict
-> f Predict
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (HashMap Text Text -> f (HashMap Text Text))
-> HashMap Text Text -> f (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Undocumented member.
predict_predictEndpoint :: Lens.Lens' Predict Prelude.Text
predict_predictEndpoint :: (Text -> f Text) -> Predict -> f Predict
predict_predictEndpoint = (Predict -> Text)
-> (Predict -> Text -> Predict) -> Lens Predict Predict Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Predict' {Text
predictEndpoint :: Text
$sel:predictEndpoint:Predict' :: Predict -> Text
predictEndpoint} -> Text
predictEndpoint) (\s :: Predict
s@Predict' {} Text
a -> Predict
s {$sel:predictEndpoint:Predict' :: Text
predictEndpoint = Text
a} :: Predict)

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

instance Prelude.NFData Predict

instance Core.ToHeaders Predict where
  toHeaders :: Predict -> ResponseHeaders
toHeaders =
    ResponseHeaders -> Predict -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# (ByteString
"AmazonML_20141212.Predict" :: Prelude.ByteString),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON Predict where
  toJSON :: Predict -> Value
toJSON Predict' {Text
HashMap Text Text
predictEndpoint :: Text
record :: HashMap Text Text
mLModelId :: Text
$sel:predictEndpoint:Predict' :: Predict -> Text
$sel:record:Predict' :: Predict -> HashMap Text Text
$sel:mLModelId:Predict' :: Predict -> 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
"MLModelId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
mLModelId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Record" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HashMap Text Text
record),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"PredictEndpoint" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
predictEndpoint)
          ]
      )

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

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

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

-- |
-- Create a value of 'PredictResponse' 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:
--
-- 'prediction', 'predictResponse_prediction' - Undocumented member.
--
-- 'httpStatus', 'predictResponse_httpStatus' - The response's http status code.
newPredictResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PredictResponse
newPredictResponse :: Int -> PredictResponse
newPredictResponse Int
pHttpStatus_ =
  PredictResponse' :: Maybe Prediction -> Int -> PredictResponse
PredictResponse'
    { $sel:prediction:PredictResponse' :: Maybe Prediction
prediction = Maybe Prediction
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PredictResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Undocumented member.
predictResponse_prediction :: Lens.Lens' PredictResponse (Prelude.Maybe Prediction)
predictResponse_prediction :: (Maybe Prediction -> f (Maybe Prediction))
-> PredictResponse -> f PredictResponse
predictResponse_prediction = (PredictResponse -> Maybe Prediction)
-> (PredictResponse -> Maybe Prediction -> PredictResponse)
-> Lens
     PredictResponse
     PredictResponse
     (Maybe Prediction)
     (Maybe Prediction)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PredictResponse' {Maybe Prediction
prediction :: Maybe Prediction
$sel:prediction:PredictResponse' :: PredictResponse -> Maybe Prediction
prediction} -> Maybe Prediction
prediction) (\s :: PredictResponse
s@PredictResponse' {} Maybe Prediction
a -> PredictResponse
s {$sel:prediction:PredictResponse' :: Maybe Prediction
prediction = Maybe Prediction
a} :: PredictResponse)

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

instance Prelude.NFData PredictResponse