{-# 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.PersonalizeRuntime.GetRecommendations
-- 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)
--
-- Returns a list of recommended items. The required input depends on the
-- recipe type used to create the solution backing the campaign, as
-- follows:
--
-- -   RELATED_ITEMS - @itemId@ required, @userId@ not used
--
-- -   USER_PERSONALIZATION - @itemId@ optional, @userId@ required
--
-- Campaigns that are backed by a solution created using a recipe of type
-- PERSONALIZED_RANKING use the API.
module Amazonka.PersonalizeRuntime.GetRecommendations
  ( -- * Creating a Request
    GetRecommendations (..),
    newGetRecommendations,

    -- * Request Lenses
    getRecommendations_context,
    getRecommendations_itemId,
    getRecommendations_userId,
    getRecommendations_numResults,
    getRecommendations_filterArn,
    getRecommendations_filterValues,
    getRecommendations_campaignArn,

    -- * Destructuring the Response
    GetRecommendationsResponse (..),
    newGetRecommendationsResponse,

    -- * Response Lenses
    getRecommendationsResponse_recommendationId,
    getRecommendationsResponse_itemList,
    getRecommendationsResponse_httpStatus,
  )
where

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

-- | /See:/ 'newGetRecommendations' smart constructor.
data GetRecommendations = GetRecommendations'
  { -- | The contextual metadata to use when getting recommendations. Contextual
    -- metadata includes any interaction information that might be relevant
    -- when getting a user\'s recommendations, such as the user\'s current
    -- location or device type.
    GetRecommendations -> Maybe (HashMap Text (Sensitive Text))
context :: Prelude.Maybe (Prelude.HashMap Prelude.Text (Core.Sensitive Prelude.Text)),
    -- | The item ID to provide recommendations for.
    --
    -- Required for @RELATED_ITEMS@ recipe type.
    GetRecommendations -> Maybe Text
itemId :: Prelude.Maybe Prelude.Text,
    -- | The user ID to provide recommendations for.
    --
    -- Required for @USER_PERSONALIZATION@ recipe type.
    GetRecommendations -> Maybe Text
userId :: Prelude.Maybe Prelude.Text,
    -- | The number of results to return. The default is 25. The maximum is 500.
    GetRecommendations -> Maybe Natural
numResults :: Prelude.Maybe Prelude.Natural,
    -- | The ARN of the filter to apply to the returned recommendations. For more
    -- information, see
    -- <https://docs.aws.amazon.com/personalize/latest/dg/filter.html Filtering Recommendations>.
    --
    -- When using this parameter, be sure the filter resource is @ACTIVE@.
    GetRecommendations -> Maybe Text
filterArn :: Prelude.Maybe Prelude.Text,
    -- | The values to use when filtering recommendations. For each placeholder
    -- parameter in your filter expression, provide the parameter name (in
    -- matching case) as a key and the filter value(s) as the corresponding
    -- value. Separate multiple values for one parameter with a comma.
    --
    -- For filter expressions that use an @INCLUDE@ element to include items,
    -- you must provide values for all parameters that are defined in the
    -- expression. For filters with expressions that use an @EXCLUDE@ element
    -- to exclude items, you can omit the @filter-values@.In this case, Amazon
    -- Personalize doesn\'t use that portion of the expression to filter
    -- recommendations.
    --
    -- For more information, see
    -- <https://docs.aws.amazon.com/personalize/latest/dg/filter.html Filtering Recommendations>.
    GetRecommendations -> Maybe (HashMap Text (Sensitive Text))
filterValues :: Prelude.Maybe (Prelude.HashMap Prelude.Text (Core.Sensitive Prelude.Text)),
    -- | The Amazon Resource Name (ARN) of the campaign to use for getting
    -- recommendations.
    GetRecommendations -> Text
campaignArn :: Prelude.Text
  }
  deriving (GetRecommendations -> GetRecommendations -> Bool
(GetRecommendations -> GetRecommendations -> Bool)
-> (GetRecommendations -> GetRecommendations -> Bool)
-> Eq GetRecommendations
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetRecommendations -> GetRecommendations -> Bool
$c/= :: GetRecommendations -> GetRecommendations -> Bool
== :: GetRecommendations -> GetRecommendations -> Bool
$c== :: GetRecommendations -> GetRecommendations -> Bool
Prelude.Eq, Int -> GetRecommendations -> ShowS
[GetRecommendations] -> ShowS
GetRecommendations -> String
(Int -> GetRecommendations -> ShowS)
-> (GetRecommendations -> String)
-> ([GetRecommendations] -> ShowS)
-> Show GetRecommendations
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetRecommendations] -> ShowS
$cshowList :: [GetRecommendations] -> ShowS
show :: GetRecommendations -> String
$cshow :: GetRecommendations -> String
showsPrec :: Int -> GetRecommendations -> ShowS
$cshowsPrec :: Int -> GetRecommendations -> ShowS
Prelude.Show, (forall x. GetRecommendations -> Rep GetRecommendations x)
-> (forall x. Rep GetRecommendations x -> GetRecommendations)
-> Generic GetRecommendations
forall x. Rep GetRecommendations x -> GetRecommendations
forall x. GetRecommendations -> Rep GetRecommendations x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetRecommendations x -> GetRecommendations
$cfrom :: forall x. GetRecommendations -> Rep GetRecommendations x
Prelude.Generic)

-- |
-- Create a value of 'GetRecommendations' 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:
--
-- 'context', 'getRecommendations_context' - The contextual metadata to use when getting recommendations. Contextual
-- metadata includes any interaction information that might be relevant
-- when getting a user\'s recommendations, such as the user\'s current
-- location or device type.
--
-- 'itemId', 'getRecommendations_itemId' - The item ID to provide recommendations for.
--
-- Required for @RELATED_ITEMS@ recipe type.
--
-- 'userId', 'getRecommendations_userId' - The user ID to provide recommendations for.
--
-- Required for @USER_PERSONALIZATION@ recipe type.
--
-- 'numResults', 'getRecommendations_numResults' - The number of results to return. The default is 25. The maximum is 500.
--
-- 'filterArn', 'getRecommendations_filterArn' - The ARN of the filter to apply to the returned recommendations. For more
-- information, see
-- <https://docs.aws.amazon.com/personalize/latest/dg/filter.html Filtering Recommendations>.
--
-- When using this parameter, be sure the filter resource is @ACTIVE@.
--
-- 'filterValues', 'getRecommendations_filterValues' - The values to use when filtering recommendations. For each placeholder
-- parameter in your filter expression, provide the parameter name (in
-- matching case) as a key and the filter value(s) as the corresponding
-- value. Separate multiple values for one parameter with a comma.
--
-- For filter expressions that use an @INCLUDE@ element to include items,
-- you must provide values for all parameters that are defined in the
-- expression. For filters with expressions that use an @EXCLUDE@ element
-- to exclude items, you can omit the @filter-values@.In this case, Amazon
-- Personalize doesn\'t use that portion of the expression to filter
-- recommendations.
--
-- For more information, see
-- <https://docs.aws.amazon.com/personalize/latest/dg/filter.html Filtering Recommendations>.
--
-- 'campaignArn', 'getRecommendations_campaignArn' - The Amazon Resource Name (ARN) of the campaign to use for getting
-- recommendations.
newGetRecommendations ::
  -- | 'campaignArn'
  Prelude.Text ->
  GetRecommendations
newGetRecommendations :: Text -> GetRecommendations
newGetRecommendations Text
pCampaignArn_ =
  GetRecommendations' :: Maybe (HashMap Text (Sensitive Text))
-> Maybe Text
-> Maybe Text
-> Maybe Natural
-> Maybe Text
-> Maybe (HashMap Text (Sensitive Text))
-> Text
-> GetRecommendations
GetRecommendations'
    { $sel:context:GetRecommendations' :: Maybe (HashMap Text (Sensitive Text))
context = Maybe (HashMap Text (Sensitive Text))
forall a. Maybe a
Prelude.Nothing,
      $sel:itemId:GetRecommendations' :: Maybe Text
itemId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:userId:GetRecommendations' :: Maybe Text
userId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:numResults:GetRecommendations' :: Maybe Natural
numResults = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:filterArn:GetRecommendations' :: Maybe Text
filterArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:filterValues:GetRecommendations' :: Maybe (HashMap Text (Sensitive Text))
filterValues = Maybe (HashMap Text (Sensitive Text))
forall a. Maybe a
Prelude.Nothing,
      $sel:campaignArn:GetRecommendations' :: Text
campaignArn = Text
pCampaignArn_
    }

-- | The contextual metadata to use when getting recommendations. Contextual
-- metadata includes any interaction information that might be relevant
-- when getting a user\'s recommendations, such as the user\'s current
-- location or device type.
getRecommendations_context :: Lens.Lens' GetRecommendations (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
getRecommendations_context :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> GetRecommendations -> f GetRecommendations
getRecommendations_context = (GetRecommendations -> Maybe (HashMap Text (Sensitive Text)))
-> (GetRecommendations
    -> Maybe (HashMap Text (Sensitive Text)) -> GetRecommendations)
-> Lens
     GetRecommendations
     GetRecommendations
     (Maybe (HashMap Text (Sensitive Text)))
     (Maybe (HashMap Text (Sensitive Text)))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRecommendations' {Maybe (HashMap Text (Sensitive Text))
context :: Maybe (HashMap Text (Sensitive Text))
$sel:context:GetRecommendations' :: GetRecommendations -> Maybe (HashMap Text (Sensitive Text))
context} -> Maybe (HashMap Text (Sensitive Text))
context) (\s :: GetRecommendations
s@GetRecommendations' {} Maybe (HashMap Text (Sensitive Text))
a -> GetRecommendations
s {$sel:context:GetRecommendations' :: Maybe (HashMap Text (Sensitive Text))
context = Maybe (HashMap Text (Sensitive Text))
a} :: GetRecommendations) ((Maybe (HashMap Text (Sensitive Text))
  -> f (Maybe (HashMap Text (Sensitive Text))))
 -> GetRecommendations -> f GetRecommendations)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text (Sensitive Text))
    -> f (Maybe (HashMap Text (Sensitive Text))))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> GetRecommendations
-> f GetRecommendations
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text (Sensitive Text))
  (HashMap Text (Sensitive Text))
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text (Sensitive Text)))
     (Maybe (HashMap Text (Sensitive Text)))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text (Sensitive Text))
  (HashMap Text (Sensitive Text))
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The item ID to provide recommendations for.
--
-- Required for @RELATED_ITEMS@ recipe type.
getRecommendations_itemId :: Lens.Lens' GetRecommendations (Prelude.Maybe Prelude.Text)
getRecommendations_itemId :: (Maybe Text -> f (Maybe Text))
-> GetRecommendations -> f GetRecommendations
getRecommendations_itemId = (GetRecommendations -> Maybe Text)
-> (GetRecommendations -> Maybe Text -> GetRecommendations)
-> Lens
     GetRecommendations GetRecommendations (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRecommendations' {Maybe Text
itemId :: Maybe Text
$sel:itemId:GetRecommendations' :: GetRecommendations -> Maybe Text
itemId} -> Maybe Text
itemId) (\s :: GetRecommendations
s@GetRecommendations' {} Maybe Text
a -> GetRecommendations
s {$sel:itemId:GetRecommendations' :: Maybe Text
itemId = Maybe Text
a} :: GetRecommendations)

-- | The user ID to provide recommendations for.
--
-- Required for @USER_PERSONALIZATION@ recipe type.
getRecommendations_userId :: Lens.Lens' GetRecommendations (Prelude.Maybe Prelude.Text)
getRecommendations_userId :: (Maybe Text -> f (Maybe Text))
-> GetRecommendations -> f GetRecommendations
getRecommendations_userId = (GetRecommendations -> Maybe Text)
-> (GetRecommendations -> Maybe Text -> GetRecommendations)
-> Lens
     GetRecommendations GetRecommendations (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRecommendations' {Maybe Text
userId :: Maybe Text
$sel:userId:GetRecommendations' :: GetRecommendations -> Maybe Text
userId} -> Maybe Text
userId) (\s :: GetRecommendations
s@GetRecommendations' {} Maybe Text
a -> GetRecommendations
s {$sel:userId:GetRecommendations' :: Maybe Text
userId = Maybe Text
a} :: GetRecommendations)

-- | The number of results to return. The default is 25. The maximum is 500.
getRecommendations_numResults :: Lens.Lens' GetRecommendations (Prelude.Maybe Prelude.Natural)
getRecommendations_numResults :: (Maybe Natural -> f (Maybe Natural))
-> GetRecommendations -> f GetRecommendations
getRecommendations_numResults = (GetRecommendations -> Maybe Natural)
-> (GetRecommendations -> Maybe Natural -> GetRecommendations)
-> Lens
     GetRecommendations
     GetRecommendations
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRecommendations' {Maybe Natural
numResults :: Maybe Natural
$sel:numResults:GetRecommendations' :: GetRecommendations -> Maybe Natural
numResults} -> Maybe Natural
numResults) (\s :: GetRecommendations
s@GetRecommendations' {} Maybe Natural
a -> GetRecommendations
s {$sel:numResults:GetRecommendations' :: Maybe Natural
numResults = Maybe Natural
a} :: GetRecommendations)

-- | The ARN of the filter to apply to the returned recommendations. For more
-- information, see
-- <https://docs.aws.amazon.com/personalize/latest/dg/filter.html Filtering Recommendations>.
--
-- When using this parameter, be sure the filter resource is @ACTIVE@.
getRecommendations_filterArn :: Lens.Lens' GetRecommendations (Prelude.Maybe Prelude.Text)
getRecommendations_filterArn :: (Maybe Text -> f (Maybe Text))
-> GetRecommendations -> f GetRecommendations
getRecommendations_filterArn = (GetRecommendations -> Maybe Text)
-> (GetRecommendations -> Maybe Text -> GetRecommendations)
-> Lens
     GetRecommendations GetRecommendations (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRecommendations' {Maybe Text
filterArn :: Maybe Text
$sel:filterArn:GetRecommendations' :: GetRecommendations -> Maybe Text
filterArn} -> Maybe Text
filterArn) (\s :: GetRecommendations
s@GetRecommendations' {} Maybe Text
a -> GetRecommendations
s {$sel:filterArn:GetRecommendations' :: Maybe Text
filterArn = Maybe Text
a} :: GetRecommendations)

-- | The values to use when filtering recommendations. For each placeholder
-- parameter in your filter expression, provide the parameter name (in
-- matching case) as a key and the filter value(s) as the corresponding
-- value. Separate multiple values for one parameter with a comma.
--
-- For filter expressions that use an @INCLUDE@ element to include items,
-- you must provide values for all parameters that are defined in the
-- expression. For filters with expressions that use an @EXCLUDE@ element
-- to exclude items, you can omit the @filter-values@.In this case, Amazon
-- Personalize doesn\'t use that portion of the expression to filter
-- recommendations.
--
-- For more information, see
-- <https://docs.aws.amazon.com/personalize/latest/dg/filter.html Filtering Recommendations>.
getRecommendations_filterValues :: Lens.Lens' GetRecommendations (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
getRecommendations_filterValues :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> GetRecommendations -> f GetRecommendations
getRecommendations_filterValues = (GetRecommendations -> Maybe (HashMap Text (Sensitive Text)))
-> (GetRecommendations
    -> Maybe (HashMap Text (Sensitive Text)) -> GetRecommendations)
-> Lens
     GetRecommendations
     GetRecommendations
     (Maybe (HashMap Text (Sensitive Text)))
     (Maybe (HashMap Text (Sensitive Text)))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRecommendations' {Maybe (HashMap Text (Sensitive Text))
filterValues :: Maybe (HashMap Text (Sensitive Text))
$sel:filterValues:GetRecommendations' :: GetRecommendations -> Maybe (HashMap Text (Sensitive Text))
filterValues} -> Maybe (HashMap Text (Sensitive Text))
filterValues) (\s :: GetRecommendations
s@GetRecommendations' {} Maybe (HashMap Text (Sensitive Text))
a -> GetRecommendations
s {$sel:filterValues:GetRecommendations' :: Maybe (HashMap Text (Sensitive Text))
filterValues = Maybe (HashMap Text (Sensitive Text))
a} :: GetRecommendations) ((Maybe (HashMap Text (Sensitive Text))
  -> f (Maybe (HashMap Text (Sensitive Text))))
 -> GetRecommendations -> f GetRecommendations)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text (Sensitive Text))
    -> f (Maybe (HashMap Text (Sensitive Text))))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> GetRecommendations
-> f GetRecommendations
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text (Sensitive Text))
  (HashMap Text (Sensitive Text))
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text (Sensitive Text)))
     (Maybe (HashMap Text (Sensitive Text)))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text (Sensitive Text))
  (HashMap Text (Sensitive Text))
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The Amazon Resource Name (ARN) of the campaign to use for getting
-- recommendations.
getRecommendations_campaignArn :: Lens.Lens' GetRecommendations Prelude.Text
getRecommendations_campaignArn :: (Text -> f Text) -> GetRecommendations -> f GetRecommendations
getRecommendations_campaignArn = (GetRecommendations -> Text)
-> (GetRecommendations -> Text -> GetRecommendations)
-> Lens GetRecommendations GetRecommendations Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRecommendations' {Text
campaignArn :: Text
$sel:campaignArn:GetRecommendations' :: GetRecommendations -> Text
campaignArn} -> Text
campaignArn) (\s :: GetRecommendations
s@GetRecommendations' {} Text
a -> GetRecommendations
s {$sel:campaignArn:GetRecommendations' :: Text
campaignArn = Text
a} :: GetRecommendations)

instance Core.AWSRequest GetRecommendations where
  type
    AWSResponse GetRecommendations =
      GetRecommendationsResponse
  request :: GetRecommendations -> Request GetRecommendations
request = Service -> GetRecommendations -> Request GetRecommendations
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetRecommendations
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetRecommendations)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetRecommendations))
-> Logger
-> Service
-> Proxy GetRecommendations
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetRecommendations)))
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
-> Maybe [PredictedItem] -> Int -> GetRecommendationsResponse
GetRecommendationsResponse'
            (Maybe Text
 -> Maybe [PredictedItem] -> Int -> GetRecommendationsResponse)
-> Either String (Maybe Text)
-> Either
     String (Maybe [PredictedItem] -> Int -> GetRecommendationsResponse)
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
"recommendationId")
            Either
  String (Maybe [PredictedItem] -> Int -> GetRecommendationsResponse)
-> Either String (Maybe [PredictedItem])
-> Either String (Int -> GetRecommendationsResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe (Maybe [PredictedItem]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"itemList" Either String (Maybe (Maybe [PredictedItem]))
-> Maybe [PredictedItem] -> Either String (Maybe [PredictedItem])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [PredictedItem]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> GetRecommendationsResponse)
-> Either String Int -> Either String GetRecommendationsResponse
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 GetRecommendations

instance Prelude.NFData GetRecommendations

instance Core.ToHeaders GetRecommendations where
  toHeaders :: GetRecommendations -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetRecommendations -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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 GetRecommendations where
  toJSON :: GetRecommendations -> Value
toJSON GetRecommendations' {Maybe Natural
Maybe Text
Maybe (HashMap Text (Sensitive Text))
Text
campaignArn :: Text
filterValues :: Maybe (HashMap Text (Sensitive Text))
filterArn :: Maybe Text
numResults :: Maybe Natural
userId :: Maybe Text
itemId :: Maybe Text
context :: Maybe (HashMap Text (Sensitive Text))
$sel:campaignArn:GetRecommendations' :: GetRecommendations -> Text
$sel:filterValues:GetRecommendations' :: GetRecommendations -> Maybe (HashMap Text (Sensitive Text))
$sel:filterArn:GetRecommendations' :: GetRecommendations -> Maybe Text
$sel:numResults:GetRecommendations' :: GetRecommendations -> Maybe Natural
$sel:userId:GetRecommendations' :: GetRecommendations -> Maybe Text
$sel:itemId:GetRecommendations' :: GetRecommendations -> Maybe Text
$sel:context:GetRecommendations' :: GetRecommendations -> Maybe (HashMap Text (Sensitive Text))
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"context" Text -> HashMap Text (Sensitive Text) -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text (Sensitive Text) -> Pair)
-> Maybe (HashMap Text (Sensitive Text)) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text (Sensitive Text))
context,
            (Text
"itemId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
itemId,
            (Text
"userId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
userId,
            (Text
"numResults" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
numResults,
            (Text
"filterArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
filterArn,
            (Text
"filterValues" Text -> HashMap Text (Sensitive Text) -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text (Sensitive Text) -> Pair)
-> Maybe (HashMap Text (Sensitive Text)) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text (Sensitive Text))
filterValues,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"campaignArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
campaignArn)
          ]
      )

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

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

-- | /See:/ 'newGetRecommendationsResponse' smart constructor.
data GetRecommendationsResponse = GetRecommendationsResponse'
  { -- | The ID of the recommendation.
    GetRecommendationsResponse -> Maybe Text
recommendationId :: Prelude.Maybe Prelude.Text,
    -- | A list of recommendations sorted in ascending order by prediction score.
    -- There can be a maximum of 500 items in the list.
    GetRecommendationsResponse -> Maybe [PredictedItem]
itemList :: Prelude.Maybe [PredictedItem],
    -- | The response's http status code.
    GetRecommendationsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetRecommendationsResponse -> GetRecommendationsResponse -> Bool
(GetRecommendationsResponse -> GetRecommendationsResponse -> Bool)
-> (GetRecommendationsResponse
    -> GetRecommendationsResponse -> Bool)
-> Eq GetRecommendationsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetRecommendationsResponse -> GetRecommendationsResponse -> Bool
$c/= :: GetRecommendationsResponse -> GetRecommendationsResponse -> Bool
== :: GetRecommendationsResponse -> GetRecommendationsResponse -> Bool
$c== :: GetRecommendationsResponse -> GetRecommendationsResponse -> Bool
Prelude.Eq, ReadPrec [GetRecommendationsResponse]
ReadPrec GetRecommendationsResponse
Int -> ReadS GetRecommendationsResponse
ReadS [GetRecommendationsResponse]
(Int -> ReadS GetRecommendationsResponse)
-> ReadS [GetRecommendationsResponse]
-> ReadPrec GetRecommendationsResponse
-> ReadPrec [GetRecommendationsResponse]
-> Read GetRecommendationsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetRecommendationsResponse]
$creadListPrec :: ReadPrec [GetRecommendationsResponse]
readPrec :: ReadPrec GetRecommendationsResponse
$creadPrec :: ReadPrec GetRecommendationsResponse
readList :: ReadS [GetRecommendationsResponse]
$creadList :: ReadS [GetRecommendationsResponse]
readsPrec :: Int -> ReadS GetRecommendationsResponse
$creadsPrec :: Int -> ReadS GetRecommendationsResponse
Prelude.Read, Int -> GetRecommendationsResponse -> ShowS
[GetRecommendationsResponse] -> ShowS
GetRecommendationsResponse -> String
(Int -> GetRecommendationsResponse -> ShowS)
-> (GetRecommendationsResponse -> String)
-> ([GetRecommendationsResponse] -> ShowS)
-> Show GetRecommendationsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetRecommendationsResponse] -> ShowS
$cshowList :: [GetRecommendationsResponse] -> ShowS
show :: GetRecommendationsResponse -> String
$cshow :: GetRecommendationsResponse -> String
showsPrec :: Int -> GetRecommendationsResponse -> ShowS
$cshowsPrec :: Int -> GetRecommendationsResponse -> ShowS
Prelude.Show, (forall x.
 GetRecommendationsResponse -> Rep GetRecommendationsResponse x)
-> (forall x.
    Rep GetRecommendationsResponse x -> GetRecommendationsResponse)
-> Generic GetRecommendationsResponse
forall x.
Rep GetRecommendationsResponse x -> GetRecommendationsResponse
forall x.
GetRecommendationsResponse -> Rep GetRecommendationsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetRecommendationsResponse x -> GetRecommendationsResponse
$cfrom :: forall x.
GetRecommendationsResponse -> Rep GetRecommendationsResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetRecommendationsResponse' 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:
--
-- 'recommendationId', 'getRecommendationsResponse_recommendationId' - The ID of the recommendation.
--
-- 'itemList', 'getRecommendationsResponse_itemList' - A list of recommendations sorted in ascending order by prediction score.
-- There can be a maximum of 500 items in the list.
--
-- 'httpStatus', 'getRecommendationsResponse_httpStatus' - The response's http status code.
newGetRecommendationsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetRecommendationsResponse
newGetRecommendationsResponse :: Int -> GetRecommendationsResponse
newGetRecommendationsResponse Int
pHttpStatus_ =
  GetRecommendationsResponse' :: Maybe Text
-> Maybe [PredictedItem] -> Int -> GetRecommendationsResponse
GetRecommendationsResponse'
    { $sel:recommendationId:GetRecommendationsResponse' :: Maybe Text
recommendationId =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:itemList:GetRecommendationsResponse' :: Maybe [PredictedItem]
itemList = Maybe [PredictedItem]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetRecommendationsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The ID of the recommendation.
getRecommendationsResponse_recommendationId :: Lens.Lens' GetRecommendationsResponse (Prelude.Maybe Prelude.Text)
getRecommendationsResponse_recommendationId :: (Maybe Text -> f (Maybe Text))
-> GetRecommendationsResponse -> f GetRecommendationsResponse
getRecommendationsResponse_recommendationId = (GetRecommendationsResponse -> Maybe Text)
-> (GetRecommendationsResponse
    -> Maybe Text -> GetRecommendationsResponse)
-> Lens
     GetRecommendationsResponse
     GetRecommendationsResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRecommendationsResponse' {Maybe Text
recommendationId :: Maybe Text
$sel:recommendationId:GetRecommendationsResponse' :: GetRecommendationsResponse -> Maybe Text
recommendationId} -> Maybe Text
recommendationId) (\s :: GetRecommendationsResponse
s@GetRecommendationsResponse' {} Maybe Text
a -> GetRecommendationsResponse
s {$sel:recommendationId:GetRecommendationsResponse' :: Maybe Text
recommendationId = Maybe Text
a} :: GetRecommendationsResponse)

-- | A list of recommendations sorted in ascending order by prediction score.
-- There can be a maximum of 500 items in the list.
getRecommendationsResponse_itemList :: Lens.Lens' GetRecommendationsResponse (Prelude.Maybe [PredictedItem])
getRecommendationsResponse_itemList :: (Maybe [PredictedItem] -> f (Maybe [PredictedItem]))
-> GetRecommendationsResponse -> f GetRecommendationsResponse
getRecommendationsResponse_itemList = (GetRecommendationsResponse -> Maybe [PredictedItem])
-> (GetRecommendationsResponse
    -> Maybe [PredictedItem] -> GetRecommendationsResponse)
-> Lens
     GetRecommendationsResponse
     GetRecommendationsResponse
     (Maybe [PredictedItem])
     (Maybe [PredictedItem])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRecommendationsResponse' {Maybe [PredictedItem]
itemList :: Maybe [PredictedItem]
$sel:itemList:GetRecommendationsResponse' :: GetRecommendationsResponse -> Maybe [PredictedItem]
itemList} -> Maybe [PredictedItem]
itemList) (\s :: GetRecommendationsResponse
s@GetRecommendationsResponse' {} Maybe [PredictedItem]
a -> GetRecommendationsResponse
s {$sel:itemList:GetRecommendationsResponse' :: Maybe [PredictedItem]
itemList = Maybe [PredictedItem]
a} :: GetRecommendationsResponse) ((Maybe [PredictedItem] -> f (Maybe [PredictedItem]))
 -> GetRecommendationsResponse -> f GetRecommendationsResponse)
-> ((Maybe [PredictedItem] -> f (Maybe [PredictedItem]))
    -> Maybe [PredictedItem] -> f (Maybe [PredictedItem]))
-> (Maybe [PredictedItem] -> f (Maybe [PredictedItem]))
-> GetRecommendationsResponse
-> f GetRecommendationsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [PredictedItem] [PredictedItem] [PredictedItem] [PredictedItem]
-> Iso
     (Maybe [PredictedItem])
     (Maybe [PredictedItem])
     (Maybe [PredictedItem])
     (Maybe [PredictedItem])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [PredictedItem] [PredictedItem] [PredictedItem] [PredictedItem]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData GetRecommendationsResponse