{-# 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.GetPersonalizedRanking
-- 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)
--
-- Re-ranks a list of recommended items for the given user. The first item
-- in the list is deemed the most likely item to be of interest to the
-- user.
--
-- The solution backing the campaign must have been created using a recipe
-- of type PERSONALIZED_RANKING.
module Amazonka.PersonalizeRuntime.GetPersonalizedRanking
  ( -- * Creating a Request
    GetPersonalizedRanking (..),
    newGetPersonalizedRanking,

    -- * Request Lenses
    getPersonalizedRanking_context,
    getPersonalizedRanking_filterArn,
    getPersonalizedRanking_filterValues,
    getPersonalizedRanking_campaignArn,
    getPersonalizedRanking_inputList,
    getPersonalizedRanking_userId,

    -- * Destructuring the Response
    GetPersonalizedRankingResponse (..),
    newGetPersonalizedRankingResponse,

    -- * Response Lenses
    getPersonalizedRankingResponse_personalizedRanking,
    getPersonalizedRankingResponse_recommendationId,
    getPersonalizedRankingResponse_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:/ 'newGetPersonalizedRanking' smart constructor.
data GetPersonalizedRanking = GetPersonalizedRanking'
  { -- | 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.
    GetPersonalizedRanking -> Maybe (HashMap Text (Sensitive Text))
context :: Prelude.Maybe (Prelude.HashMap Prelude.Text (Core.Sensitive Prelude.Text)),
    -- | The Amazon Resource Name (ARN) of a filter you created to include items
    -- or exclude items from recommendations for a given user. For more
    -- information, see
    -- <https://docs.aws.amazon.com/personalize/latest/dg/filter.html Filtering Recommendations>.
    GetPersonalizedRanking -> 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>.
    GetPersonalizedRanking -> 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 generating the
    -- personalized ranking.
    GetPersonalizedRanking -> Text
campaignArn :: Prelude.Text,
    -- | A list of items (by @itemId@) to rank. If an item was not included in
    -- the training dataset, the item is appended to the end of the reranked
    -- list. The maximum is 500.
    GetPersonalizedRanking -> [Text]
inputList :: [Prelude.Text],
    -- | The user for which you want the campaign to provide a personalized
    -- ranking.
    GetPersonalizedRanking -> Text
userId :: Prelude.Text
  }
  deriving (GetPersonalizedRanking -> GetPersonalizedRanking -> Bool
(GetPersonalizedRanking -> GetPersonalizedRanking -> Bool)
-> (GetPersonalizedRanking -> GetPersonalizedRanking -> Bool)
-> Eq GetPersonalizedRanking
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetPersonalizedRanking -> GetPersonalizedRanking -> Bool
$c/= :: GetPersonalizedRanking -> GetPersonalizedRanking -> Bool
== :: GetPersonalizedRanking -> GetPersonalizedRanking -> Bool
$c== :: GetPersonalizedRanking -> GetPersonalizedRanking -> Bool
Prelude.Eq, Int -> GetPersonalizedRanking -> ShowS
[GetPersonalizedRanking] -> ShowS
GetPersonalizedRanking -> String
(Int -> GetPersonalizedRanking -> ShowS)
-> (GetPersonalizedRanking -> String)
-> ([GetPersonalizedRanking] -> ShowS)
-> Show GetPersonalizedRanking
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetPersonalizedRanking] -> ShowS
$cshowList :: [GetPersonalizedRanking] -> ShowS
show :: GetPersonalizedRanking -> String
$cshow :: GetPersonalizedRanking -> String
showsPrec :: Int -> GetPersonalizedRanking -> ShowS
$cshowsPrec :: Int -> GetPersonalizedRanking -> ShowS
Prelude.Show, (forall x. GetPersonalizedRanking -> Rep GetPersonalizedRanking x)
-> (forall x.
    Rep GetPersonalizedRanking x -> GetPersonalizedRanking)
-> Generic GetPersonalizedRanking
forall x. Rep GetPersonalizedRanking x -> GetPersonalizedRanking
forall x. GetPersonalizedRanking -> Rep GetPersonalizedRanking x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetPersonalizedRanking x -> GetPersonalizedRanking
$cfrom :: forall x. GetPersonalizedRanking -> Rep GetPersonalizedRanking x
Prelude.Generic)

-- |
-- Create a value of 'GetPersonalizedRanking' 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', 'getPersonalizedRanking_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.
--
-- 'filterArn', 'getPersonalizedRanking_filterArn' - The Amazon Resource Name (ARN) of a filter you created to include items
-- or exclude items from recommendations for a given user. For more
-- information, see
-- <https://docs.aws.amazon.com/personalize/latest/dg/filter.html Filtering Recommendations>.
--
-- 'filterValues', 'getPersonalizedRanking_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', 'getPersonalizedRanking_campaignArn' - The Amazon Resource Name (ARN) of the campaign to use for generating the
-- personalized ranking.
--
-- 'inputList', 'getPersonalizedRanking_inputList' - A list of items (by @itemId@) to rank. If an item was not included in
-- the training dataset, the item is appended to the end of the reranked
-- list. The maximum is 500.
--
-- 'userId', 'getPersonalizedRanking_userId' - The user for which you want the campaign to provide a personalized
-- ranking.
newGetPersonalizedRanking ::
  -- | 'campaignArn'
  Prelude.Text ->
  -- | 'userId'
  Prelude.Text ->
  GetPersonalizedRanking
newGetPersonalizedRanking :: Text -> Text -> GetPersonalizedRanking
newGetPersonalizedRanking Text
pCampaignArn_ Text
pUserId_ =
  GetPersonalizedRanking' :: Maybe (HashMap Text (Sensitive Text))
-> Maybe Text
-> Maybe (HashMap Text (Sensitive Text))
-> Text
-> [Text]
-> Text
-> GetPersonalizedRanking
GetPersonalizedRanking'
    { $sel:context:GetPersonalizedRanking' :: Maybe (HashMap Text (Sensitive Text))
context = Maybe (HashMap Text (Sensitive Text))
forall a. Maybe a
Prelude.Nothing,
      $sel:filterArn:GetPersonalizedRanking' :: Maybe Text
filterArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:filterValues:GetPersonalizedRanking' :: Maybe (HashMap Text (Sensitive Text))
filterValues = Maybe (HashMap Text (Sensitive Text))
forall a. Maybe a
Prelude.Nothing,
      $sel:campaignArn:GetPersonalizedRanking' :: Text
campaignArn = Text
pCampaignArn_,
      $sel:inputList:GetPersonalizedRanking' :: [Text]
inputList = [Text]
forall a. Monoid a => a
Prelude.mempty,
      $sel:userId:GetPersonalizedRanking' :: Text
userId = Text
pUserId_
    }

-- | 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.
getPersonalizedRanking_context :: Lens.Lens' GetPersonalizedRanking (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
getPersonalizedRanking_context :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> GetPersonalizedRanking -> f GetPersonalizedRanking
getPersonalizedRanking_context = (GetPersonalizedRanking -> Maybe (HashMap Text (Sensitive Text)))
-> (GetPersonalizedRanking
    -> Maybe (HashMap Text (Sensitive Text)) -> GetPersonalizedRanking)
-> Lens
     GetPersonalizedRanking
     GetPersonalizedRanking
     (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 (\GetPersonalizedRanking' {Maybe (HashMap Text (Sensitive Text))
context :: Maybe (HashMap Text (Sensitive Text))
$sel:context:GetPersonalizedRanking' :: GetPersonalizedRanking -> Maybe (HashMap Text (Sensitive Text))
context} -> Maybe (HashMap Text (Sensitive Text))
context) (\s :: GetPersonalizedRanking
s@GetPersonalizedRanking' {} Maybe (HashMap Text (Sensitive Text))
a -> GetPersonalizedRanking
s {$sel:context:GetPersonalizedRanking' :: Maybe (HashMap Text (Sensitive Text))
context = Maybe (HashMap Text (Sensitive Text))
a} :: GetPersonalizedRanking) ((Maybe (HashMap Text (Sensitive Text))
  -> f (Maybe (HashMap Text (Sensitive Text))))
 -> GetPersonalizedRanking -> f GetPersonalizedRanking)
-> ((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)))
-> GetPersonalizedRanking
-> f GetPersonalizedRanking
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 a filter you created to include items
-- or exclude items from recommendations for a given user. For more
-- information, see
-- <https://docs.aws.amazon.com/personalize/latest/dg/filter.html Filtering Recommendations>.
getPersonalizedRanking_filterArn :: Lens.Lens' GetPersonalizedRanking (Prelude.Maybe Prelude.Text)
getPersonalizedRanking_filterArn :: (Maybe Text -> f (Maybe Text))
-> GetPersonalizedRanking -> f GetPersonalizedRanking
getPersonalizedRanking_filterArn = (GetPersonalizedRanking -> Maybe Text)
-> (GetPersonalizedRanking -> Maybe Text -> GetPersonalizedRanking)
-> Lens
     GetPersonalizedRanking
     GetPersonalizedRanking
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPersonalizedRanking' {Maybe Text
filterArn :: Maybe Text
$sel:filterArn:GetPersonalizedRanking' :: GetPersonalizedRanking -> Maybe Text
filterArn} -> Maybe Text
filterArn) (\s :: GetPersonalizedRanking
s@GetPersonalizedRanking' {} Maybe Text
a -> GetPersonalizedRanking
s {$sel:filterArn:GetPersonalizedRanking' :: Maybe Text
filterArn = Maybe Text
a} :: GetPersonalizedRanking)

-- | 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>.
getPersonalizedRanking_filterValues :: Lens.Lens' GetPersonalizedRanking (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
getPersonalizedRanking_filterValues :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> GetPersonalizedRanking -> f GetPersonalizedRanking
getPersonalizedRanking_filterValues = (GetPersonalizedRanking -> Maybe (HashMap Text (Sensitive Text)))
-> (GetPersonalizedRanking
    -> Maybe (HashMap Text (Sensitive Text)) -> GetPersonalizedRanking)
-> Lens
     GetPersonalizedRanking
     GetPersonalizedRanking
     (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 (\GetPersonalizedRanking' {Maybe (HashMap Text (Sensitive Text))
filterValues :: Maybe (HashMap Text (Sensitive Text))
$sel:filterValues:GetPersonalizedRanking' :: GetPersonalizedRanking -> Maybe (HashMap Text (Sensitive Text))
filterValues} -> Maybe (HashMap Text (Sensitive Text))
filterValues) (\s :: GetPersonalizedRanking
s@GetPersonalizedRanking' {} Maybe (HashMap Text (Sensitive Text))
a -> GetPersonalizedRanking
s {$sel:filterValues:GetPersonalizedRanking' :: Maybe (HashMap Text (Sensitive Text))
filterValues = Maybe (HashMap Text (Sensitive Text))
a} :: GetPersonalizedRanking) ((Maybe (HashMap Text (Sensitive Text))
  -> f (Maybe (HashMap Text (Sensitive Text))))
 -> GetPersonalizedRanking -> f GetPersonalizedRanking)
-> ((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)))
-> GetPersonalizedRanking
-> f GetPersonalizedRanking
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 generating the
-- personalized ranking.
getPersonalizedRanking_campaignArn :: Lens.Lens' GetPersonalizedRanking Prelude.Text
getPersonalizedRanking_campaignArn :: (Text -> f Text)
-> GetPersonalizedRanking -> f GetPersonalizedRanking
getPersonalizedRanking_campaignArn = (GetPersonalizedRanking -> Text)
-> (GetPersonalizedRanking -> Text -> GetPersonalizedRanking)
-> Lens GetPersonalizedRanking GetPersonalizedRanking Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPersonalizedRanking' {Text
campaignArn :: Text
$sel:campaignArn:GetPersonalizedRanking' :: GetPersonalizedRanking -> Text
campaignArn} -> Text
campaignArn) (\s :: GetPersonalizedRanking
s@GetPersonalizedRanking' {} Text
a -> GetPersonalizedRanking
s {$sel:campaignArn:GetPersonalizedRanking' :: Text
campaignArn = Text
a} :: GetPersonalizedRanking)

-- | A list of items (by @itemId@) to rank. If an item was not included in
-- the training dataset, the item is appended to the end of the reranked
-- list. The maximum is 500.
getPersonalizedRanking_inputList :: Lens.Lens' GetPersonalizedRanking [Prelude.Text]
getPersonalizedRanking_inputList :: ([Text] -> f [Text])
-> GetPersonalizedRanking -> f GetPersonalizedRanking
getPersonalizedRanking_inputList = (GetPersonalizedRanking -> [Text])
-> (GetPersonalizedRanking -> [Text] -> GetPersonalizedRanking)
-> Lens GetPersonalizedRanking GetPersonalizedRanking [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPersonalizedRanking' {[Text]
inputList :: [Text]
$sel:inputList:GetPersonalizedRanking' :: GetPersonalizedRanking -> [Text]
inputList} -> [Text]
inputList) (\s :: GetPersonalizedRanking
s@GetPersonalizedRanking' {} [Text]
a -> GetPersonalizedRanking
s {$sel:inputList:GetPersonalizedRanking' :: [Text]
inputList = [Text]
a} :: GetPersonalizedRanking) (([Text] -> f [Text])
 -> GetPersonalizedRanking -> f GetPersonalizedRanking)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> GetPersonalizedRanking
-> f GetPersonalizedRanking
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The user for which you want the campaign to provide a personalized
-- ranking.
getPersonalizedRanking_userId :: Lens.Lens' GetPersonalizedRanking Prelude.Text
getPersonalizedRanking_userId :: (Text -> f Text)
-> GetPersonalizedRanking -> f GetPersonalizedRanking
getPersonalizedRanking_userId = (GetPersonalizedRanking -> Text)
-> (GetPersonalizedRanking -> Text -> GetPersonalizedRanking)
-> Lens GetPersonalizedRanking GetPersonalizedRanking Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPersonalizedRanking' {Text
userId :: Text
$sel:userId:GetPersonalizedRanking' :: GetPersonalizedRanking -> Text
userId} -> Text
userId) (\s :: GetPersonalizedRanking
s@GetPersonalizedRanking' {} Text
a -> GetPersonalizedRanking
s {$sel:userId:GetPersonalizedRanking' :: Text
userId = Text
a} :: GetPersonalizedRanking)

instance Core.AWSRequest GetPersonalizedRanking where
  type
    AWSResponse GetPersonalizedRanking =
      GetPersonalizedRankingResponse
  request :: GetPersonalizedRanking -> Request GetPersonalizedRanking
request = Service -> GetPersonalizedRanking -> Request GetPersonalizedRanking
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetPersonalizedRanking
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetPersonalizedRanking)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetPersonalizedRanking))
-> Logger
-> Service
-> Proxy GetPersonalizedRanking
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetPersonalizedRanking)))
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 [PredictedItem]
-> Maybe Text -> Int -> GetPersonalizedRankingResponse
GetPersonalizedRankingResponse'
            (Maybe [PredictedItem]
 -> Maybe Text -> Int -> GetPersonalizedRankingResponse)
-> Either String (Maybe [PredictedItem])
-> Either
     String (Maybe Text -> Int -> GetPersonalizedRankingResponse)
forall (f :: * -> *) a b. Functor 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
"personalizedRanking"
                            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 (Maybe Text -> Int -> GetPersonalizedRankingResponse)
-> Either String (Maybe Text)
-> Either String (Int -> GetPersonalizedRankingResponse)
forall (f :: * -> *) a b. Applicative f => 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 (Int -> GetPersonalizedRankingResponse)
-> Either String Int
-> Either String GetPersonalizedRankingResponse
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 GetPersonalizedRanking

instance Prelude.NFData GetPersonalizedRanking

instance Core.ToHeaders GetPersonalizedRanking where
  toHeaders :: GetPersonalizedRanking -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetPersonalizedRanking -> 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 GetPersonalizedRanking where
  toJSON :: GetPersonalizedRanking -> Value
toJSON GetPersonalizedRanking' {[Text]
Maybe Text
Maybe (HashMap Text (Sensitive Text))
Text
userId :: Text
inputList :: [Text]
campaignArn :: Text
filterValues :: Maybe (HashMap Text (Sensitive Text))
filterArn :: Maybe Text
context :: Maybe (HashMap Text (Sensitive Text))
$sel:userId:GetPersonalizedRanking' :: GetPersonalizedRanking -> Text
$sel:inputList:GetPersonalizedRanking' :: GetPersonalizedRanking -> [Text]
$sel:campaignArn:GetPersonalizedRanking' :: GetPersonalizedRanking -> Text
$sel:filterValues:GetPersonalizedRanking' :: GetPersonalizedRanking -> Maybe (HashMap Text (Sensitive Text))
$sel:filterArn:GetPersonalizedRanking' :: GetPersonalizedRanking -> Maybe Text
$sel:context:GetPersonalizedRanking' :: GetPersonalizedRanking -> 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
"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),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"inputList" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
inputList),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"userId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
userId)
          ]
      )

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

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

-- | /See:/ 'newGetPersonalizedRankingResponse' smart constructor.
data GetPersonalizedRankingResponse = GetPersonalizedRankingResponse'
  { -- | A list of items in order of most likely interest to the user. The
    -- maximum is 500.
    GetPersonalizedRankingResponse -> Maybe [PredictedItem]
personalizedRanking :: Prelude.Maybe [PredictedItem],
    -- | The ID of the recommendation.
    GetPersonalizedRankingResponse -> Maybe Text
recommendationId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetPersonalizedRankingResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetPersonalizedRankingResponse
-> GetPersonalizedRankingResponse -> Bool
(GetPersonalizedRankingResponse
 -> GetPersonalizedRankingResponse -> Bool)
-> (GetPersonalizedRankingResponse
    -> GetPersonalizedRankingResponse -> Bool)
-> Eq GetPersonalizedRankingResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetPersonalizedRankingResponse
-> GetPersonalizedRankingResponse -> Bool
$c/= :: GetPersonalizedRankingResponse
-> GetPersonalizedRankingResponse -> Bool
== :: GetPersonalizedRankingResponse
-> GetPersonalizedRankingResponse -> Bool
$c== :: GetPersonalizedRankingResponse
-> GetPersonalizedRankingResponse -> Bool
Prelude.Eq, ReadPrec [GetPersonalizedRankingResponse]
ReadPrec GetPersonalizedRankingResponse
Int -> ReadS GetPersonalizedRankingResponse
ReadS [GetPersonalizedRankingResponse]
(Int -> ReadS GetPersonalizedRankingResponse)
-> ReadS [GetPersonalizedRankingResponse]
-> ReadPrec GetPersonalizedRankingResponse
-> ReadPrec [GetPersonalizedRankingResponse]
-> Read GetPersonalizedRankingResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetPersonalizedRankingResponse]
$creadListPrec :: ReadPrec [GetPersonalizedRankingResponse]
readPrec :: ReadPrec GetPersonalizedRankingResponse
$creadPrec :: ReadPrec GetPersonalizedRankingResponse
readList :: ReadS [GetPersonalizedRankingResponse]
$creadList :: ReadS [GetPersonalizedRankingResponse]
readsPrec :: Int -> ReadS GetPersonalizedRankingResponse
$creadsPrec :: Int -> ReadS GetPersonalizedRankingResponse
Prelude.Read, Int -> GetPersonalizedRankingResponse -> ShowS
[GetPersonalizedRankingResponse] -> ShowS
GetPersonalizedRankingResponse -> String
(Int -> GetPersonalizedRankingResponse -> ShowS)
-> (GetPersonalizedRankingResponse -> String)
-> ([GetPersonalizedRankingResponse] -> ShowS)
-> Show GetPersonalizedRankingResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetPersonalizedRankingResponse] -> ShowS
$cshowList :: [GetPersonalizedRankingResponse] -> ShowS
show :: GetPersonalizedRankingResponse -> String
$cshow :: GetPersonalizedRankingResponse -> String
showsPrec :: Int -> GetPersonalizedRankingResponse -> ShowS
$cshowsPrec :: Int -> GetPersonalizedRankingResponse -> ShowS
Prelude.Show, (forall x.
 GetPersonalizedRankingResponse
 -> Rep GetPersonalizedRankingResponse x)
-> (forall x.
    Rep GetPersonalizedRankingResponse x
    -> GetPersonalizedRankingResponse)
-> Generic GetPersonalizedRankingResponse
forall x.
Rep GetPersonalizedRankingResponse x
-> GetPersonalizedRankingResponse
forall x.
GetPersonalizedRankingResponse
-> Rep GetPersonalizedRankingResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetPersonalizedRankingResponse x
-> GetPersonalizedRankingResponse
$cfrom :: forall x.
GetPersonalizedRankingResponse
-> Rep GetPersonalizedRankingResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetPersonalizedRankingResponse' 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:
--
-- 'personalizedRanking', 'getPersonalizedRankingResponse_personalizedRanking' - A list of items in order of most likely interest to the user. The
-- maximum is 500.
--
-- 'recommendationId', 'getPersonalizedRankingResponse_recommendationId' - The ID of the recommendation.
--
-- 'httpStatus', 'getPersonalizedRankingResponse_httpStatus' - The response's http status code.
newGetPersonalizedRankingResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetPersonalizedRankingResponse
newGetPersonalizedRankingResponse :: Int -> GetPersonalizedRankingResponse
newGetPersonalizedRankingResponse Int
pHttpStatus_ =
  GetPersonalizedRankingResponse' :: Maybe [PredictedItem]
-> Maybe Text -> Int -> GetPersonalizedRankingResponse
GetPersonalizedRankingResponse'
    { $sel:personalizedRanking:GetPersonalizedRankingResponse' :: Maybe [PredictedItem]
personalizedRanking =
        Maybe [PredictedItem]
forall a. Maybe a
Prelude.Nothing,
      $sel:recommendationId:GetPersonalizedRankingResponse' :: Maybe Text
recommendationId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetPersonalizedRankingResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A list of items in order of most likely interest to the user. The
-- maximum is 500.
getPersonalizedRankingResponse_personalizedRanking :: Lens.Lens' GetPersonalizedRankingResponse (Prelude.Maybe [PredictedItem])
getPersonalizedRankingResponse_personalizedRanking :: (Maybe [PredictedItem] -> f (Maybe [PredictedItem]))
-> GetPersonalizedRankingResponse
-> f GetPersonalizedRankingResponse
getPersonalizedRankingResponse_personalizedRanking = (GetPersonalizedRankingResponse -> Maybe [PredictedItem])
-> (GetPersonalizedRankingResponse
    -> Maybe [PredictedItem] -> GetPersonalizedRankingResponse)
-> Lens
     GetPersonalizedRankingResponse
     GetPersonalizedRankingResponse
     (Maybe [PredictedItem])
     (Maybe [PredictedItem])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPersonalizedRankingResponse' {Maybe [PredictedItem]
personalizedRanking :: Maybe [PredictedItem]
$sel:personalizedRanking:GetPersonalizedRankingResponse' :: GetPersonalizedRankingResponse -> Maybe [PredictedItem]
personalizedRanking} -> Maybe [PredictedItem]
personalizedRanking) (\s :: GetPersonalizedRankingResponse
s@GetPersonalizedRankingResponse' {} Maybe [PredictedItem]
a -> GetPersonalizedRankingResponse
s {$sel:personalizedRanking:GetPersonalizedRankingResponse' :: Maybe [PredictedItem]
personalizedRanking = Maybe [PredictedItem]
a} :: GetPersonalizedRankingResponse) ((Maybe [PredictedItem] -> f (Maybe [PredictedItem]))
 -> GetPersonalizedRankingResponse
 -> f GetPersonalizedRankingResponse)
-> ((Maybe [PredictedItem] -> f (Maybe [PredictedItem]))
    -> Maybe [PredictedItem] -> f (Maybe [PredictedItem]))
-> (Maybe [PredictedItem] -> f (Maybe [PredictedItem]))
-> GetPersonalizedRankingResponse
-> f GetPersonalizedRankingResponse
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 ID of the recommendation.
getPersonalizedRankingResponse_recommendationId :: Lens.Lens' GetPersonalizedRankingResponse (Prelude.Maybe Prelude.Text)
getPersonalizedRankingResponse_recommendationId :: (Maybe Text -> f (Maybe Text))
-> GetPersonalizedRankingResponse
-> f GetPersonalizedRankingResponse
getPersonalizedRankingResponse_recommendationId = (GetPersonalizedRankingResponse -> Maybe Text)
-> (GetPersonalizedRankingResponse
    -> Maybe Text -> GetPersonalizedRankingResponse)
-> Lens
     GetPersonalizedRankingResponse
     GetPersonalizedRankingResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPersonalizedRankingResponse' {Maybe Text
recommendationId :: Maybe Text
$sel:recommendationId:GetPersonalizedRankingResponse' :: GetPersonalizedRankingResponse -> Maybe Text
recommendationId} -> Maybe Text
recommendationId) (\s :: GetPersonalizedRankingResponse
s@GetPersonalizedRankingResponse' {} Maybe Text
a -> GetPersonalizedRankingResponse
s {$sel:recommendationId:GetPersonalizedRankingResponse' :: Maybe Text
recommendationId = Maybe Text
a} :: GetPersonalizedRankingResponse)

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

instance
  Prelude.NFData
    GetPersonalizedRankingResponse