{-# 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.SageMakerFeatureStoreRuntime.GetRecord
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Use for @OnlineStore@ serving from a @FeatureStore@. Only the latest
-- records stored in the @OnlineStore@ can be retrieved. If no Record with
-- @RecordIdentifierValue@ is found, then an empty result is returned.
module Amazonka.SageMakerFeatureStoreRuntime.GetRecord
  ( -- * Creating a Request
    GetRecord (..),
    newGetRecord,

    -- * Request Lenses
    getRecord_featureNames,
    getRecord_featureGroupName,
    getRecord_recordIdentifierValueAsString,

    -- * Destructuring the Response
    GetRecordResponse (..),
    newGetRecordResponse,

    -- * Response Lenses
    getRecordResponse_record,
    getRecordResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.SageMakerFeatureStoreRuntime.Types

-- | /See:/ 'newGetRecord' smart constructor.
data GetRecord = GetRecord'
  { -- | List of names of Features to be retrieved. If not specified, the latest
    -- value for all the Features are returned.
    GetRecord -> Maybe (NonEmpty Text)
featureNames :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | The name of the feature group from which you want to retrieve a record.
    GetRecord -> Text
featureGroupName :: Prelude.Text,
    -- | The value that corresponds to @RecordIdentifier@ type and uniquely
    -- identifies the record in the @FeatureGroup@.
    GetRecord -> Text
recordIdentifierValueAsString :: Prelude.Text
  }
  deriving (GetRecord -> GetRecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetRecord -> GetRecord -> Bool
$c/= :: GetRecord -> GetRecord -> Bool
== :: GetRecord -> GetRecord -> Bool
$c== :: GetRecord -> GetRecord -> Bool
Prelude.Eq, ReadPrec [GetRecord]
ReadPrec GetRecord
Int -> ReadS GetRecord
ReadS [GetRecord]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetRecord]
$creadListPrec :: ReadPrec [GetRecord]
readPrec :: ReadPrec GetRecord
$creadPrec :: ReadPrec GetRecord
readList :: ReadS [GetRecord]
$creadList :: ReadS [GetRecord]
readsPrec :: Int -> ReadS GetRecord
$creadsPrec :: Int -> ReadS GetRecord
Prelude.Read, Int -> GetRecord -> ShowS
[GetRecord] -> ShowS
GetRecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetRecord] -> ShowS
$cshowList :: [GetRecord] -> ShowS
show :: GetRecord -> String
$cshow :: GetRecord -> String
showsPrec :: Int -> GetRecord -> ShowS
$cshowsPrec :: Int -> GetRecord -> ShowS
Prelude.Show, forall x. Rep GetRecord x -> GetRecord
forall x. GetRecord -> Rep GetRecord x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetRecord x -> GetRecord
$cfrom :: forall x. GetRecord -> Rep GetRecord x
Prelude.Generic)

-- |
-- Create a value of 'GetRecord' 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:
--
-- 'featureNames', 'getRecord_featureNames' - List of names of Features to be retrieved. If not specified, the latest
-- value for all the Features are returned.
--
-- 'featureGroupName', 'getRecord_featureGroupName' - The name of the feature group from which you want to retrieve a record.
--
-- 'recordIdentifierValueAsString', 'getRecord_recordIdentifierValueAsString' - The value that corresponds to @RecordIdentifier@ type and uniquely
-- identifies the record in the @FeatureGroup@.
newGetRecord ::
  -- | 'featureGroupName'
  Prelude.Text ->
  -- | 'recordIdentifierValueAsString'
  Prelude.Text ->
  GetRecord
newGetRecord :: Text -> Text -> GetRecord
newGetRecord
  Text
pFeatureGroupName_
  Text
pRecordIdentifierValueAsString_ =
    GetRecord'
      { $sel:featureNames:GetRecord' :: Maybe (NonEmpty Text)
featureNames = forall a. Maybe a
Prelude.Nothing,
        $sel:featureGroupName:GetRecord' :: Text
featureGroupName = Text
pFeatureGroupName_,
        $sel:recordIdentifierValueAsString:GetRecord' :: Text
recordIdentifierValueAsString =
          Text
pRecordIdentifierValueAsString_
      }

-- | List of names of Features to be retrieved. If not specified, the latest
-- value for all the Features are returned.
getRecord_featureNames :: Lens.Lens' GetRecord (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
getRecord_featureNames :: Lens' GetRecord (Maybe (NonEmpty Text))
getRecord_featureNames = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRecord' {Maybe (NonEmpty Text)
featureNames :: Maybe (NonEmpty Text)
$sel:featureNames:GetRecord' :: GetRecord -> Maybe (NonEmpty Text)
featureNames} -> Maybe (NonEmpty Text)
featureNames) (\s :: GetRecord
s@GetRecord' {} Maybe (NonEmpty Text)
a -> GetRecord
s {$sel:featureNames:GetRecord' :: Maybe (NonEmpty Text)
featureNames = Maybe (NonEmpty Text)
a} :: GetRecord) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the feature group from which you want to retrieve a record.
getRecord_featureGroupName :: Lens.Lens' GetRecord Prelude.Text
getRecord_featureGroupName :: Lens' GetRecord Text
getRecord_featureGroupName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRecord' {Text
featureGroupName :: Text
$sel:featureGroupName:GetRecord' :: GetRecord -> Text
featureGroupName} -> Text
featureGroupName) (\s :: GetRecord
s@GetRecord' {} Text
a -> GetRecord
s {$sel:featureGroupName:GetRecord' :: Text
featureGroupName = Text
a} :: GetRecord)

-- | The value that corresponds to @RecordIdentifier@ type and uniquely
-- identifies the record in the @FeatureGroup@.
getRecord_recordIdentifierValueAsString :: Lens.Lens' GetRecord Prelude.Text
getRecord_recordIdentifierValueAsString :: Lens' GetRecord Text
getRecord_recordIdentifierValueAsString = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRecord' {Text
recordIdentifierValueAsString :: Text
$sel:recordIdentifierValueAsString:GetRecord' :: GetRecord -> Text
recordIdentifierValueAsString} -> Text
recordIdentifierValueAsString) (\s :: GetRecord
s@GetRecord' {} Text
a -> GetRecord
s {$sel:recordIdentifierValueAsString:GetRecord' :: Text
recordIdentifierValueAsString = Text
a} :: GetRecord)

instance Core.AWSRequest GetRecord where
  type AWSResponse GetRecord = GetRecordResponse
  request :: (Service -> Service) -> GetRecord -> Request GetRecord
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetRecord
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetRecord)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe (NonEmpty FeatureValue) -> Int -> GetRecordResponse
GetRecordResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"Record")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable GetRecord where
  hashWithSalt :: Int -> GetRecord -> Int
hashWithSalt Int
_salt GetRecord' {Maybe (NonEmpty Text)
Text
recordIdentifierValueAsString :: Text
featureGroupName :: Text
featureNames :: Maybe (NonEmpty Text)
$sel:recordIdentifierValueAsString:GetRecord' :: GetRecord -> Text
$sel:featureGroupName:GetRecord' :: GetRecord -> Text
$sel:featureNames:GetRecord' :: GetRecord -> Maybe (NonEmpty Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Text)
featureNames
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
featureGroupName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
recordIdentifierValueAsString

instance Prelude.NFData GetRecord where
  rnf :: GetRecord -> ()
rnf GetRecord' {Maybe (NonEmpty Text)
Text
recordIdentifierValueAsString :: Text
featureGroupName :: Text
featureNames :: Maybe (NonEmpty Text)
$sel:recordIdentifierValueAsString:GetRecord' :: GetRecord -> Text
$sel:featureGroupName:GetRecord' :: GetRecord -> Text
$sel:featureNames:GetRecord' :: GetRecord -> Maybe (NonEmpty Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Text)
featureNames
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
featureGroupName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
recordIdentifierValueAsString

instance Data.ToHeaders GetRecord where
  toHeaders :: GetRecord -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToPath GetRecord where
  toPath :: GetRecord -> ByteString
toPath GetRecord' {Maybe (NonEmpty Text)
Text
recordIdentifierValueAsString :: Text
featureGroupName :: Text
featureNames :: Maybe (NonEmpty Text)
$sel:recordIdentifierValueAsString:GetRecord' :: GetRecord -> Text
$sel:featureGroupName:GetRecord' :: GetRecord -> Text
$sel:featureNames:GetRecord' :: GetRecord -> Maybe (NonEmpty Text)
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/FeatureGroup/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
featureGroupName]

instance Data.ToQuery GetRecord where
  toQuery :: GetRecord -> QueryString
toQuery GetRecord' {Maybe (NonEmpty Text)
Text
recordIdentifierValueAsString :: Text
featureGroupName :: Text
featureNames :: Maybe (NonEmpty Text)
$sel:recordIdentifierValueAsString:GetRecord' :: GetRecord -> Text
$sel:featureGroupName:GetRecord' :: GetRecord -> Text
$sel:featureNames:GetRecord' :: GetRecord -> Maybe (NonEmpty Text)
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"FeatureName"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: forall a. ToQuery a => a -> QueryString
Data.toQuery
            (forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Data.toQueryList ByteString
"member" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
featureNames),
        ByteString
"RecordIdentifierValueAsString"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
recordIdentifierValueAsString
      ]

-- | /See:/ 'newGetRecordResponse' smart constructor.
data GetRecordResponse = GetRecordResponse'
  { -- | The record you requested. A list of @FeatureValues@.
    GetRecordResponse -> Maybe (NonEmpty FeatureValue)
record :: Prelude.Maybe (Prelude.NonEmpty FeatureValue),
    -- | The response's http status code.
    GetRecordResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetRecordResponse -> GetRecordResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetRecordResponse -> GetRecordResponse -> Bool
$c/= :: GetRecordResponse -> GetRecordResponse -> Bool
== :: GetRecordResponse -> GetRecordResponse -> Bool
$c== :: GetRecordResponse -> GetRecordResponse -> Bool
Prelude.Eq, ReadPrec [GetRecordResponse]
ReadPrec GetRecordResponse
Int -> ReadS GetRecordResponse
ReadS [GetRecordResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetRecordResponse]
$creadListPrec :: ReadPrec [GetRecordResponse]
readPrec :: ReadPrec GetRecordResponse
$creadPrec :: ReadPrec GetRecordResponse
readList :: ReadS [GetRecordResponse]
$creadList :: ReadS [GetRecordResponse]
readsPrec :: Int -> ReadS GetRecordResponse
$creadsPrec :: Int -> ReadS GetRecordResponse
Prelude.Read, Int -> GetRecordResponse -> ShowS
[GetRecordResponse] -> ShowS
GetRecordResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetRecordResponse] -> ShowS
$cshowList :: [GetRecordResponse] -> ShowS
show :: GetRecordResponse -> String
$cshow :: GetRecordResponse -> String
showsPrec :: Int -> GetRecordResponse -> ShowS
$cshowsPrec :: Int -> GetRecordResponse -> ShowS
Prelude.Show, forall x. Rep GetRecordResponse x -> GetRecordResponse
forall x. GetRecordResponse -> Rep GetRecordResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetRecordResponse x -> GetRecordResponse
$cfrom :: forall x. GetRecordResponse -> Rep GetRecordResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetRecordResponse' 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:
--
-- 'record', 'getRecordResponse_record' - The record you requested. A list of @FeatureValues@.
--
-- 'httpStatus', 'getRecordResponse_httpStatus' - The response's http status code.
newGetRecordResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetRecordResponse
newGetRecordResponse :: Int -> GetRecordResponse
newGetRecordResponse Int
pHttpStatus_ =
  GetRecordResponse'
    { $sel:record:GetRecordResponse' :: Maybe (NonEmpty FeatureValue)
record = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetRecordResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The record you requested. A list of @FeatureValues@.
getRecordResponse_record :: Lens.Lens' GetRecordResponse (Prelude.Maybe (Prelude.NonEmpty FeatureValue))
getRecordResponse_record :: Lens' GetRecordResponse (Maybe (NonEmpty FeatureValue))
getRecordResponse_record = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRecordResponse' {Maybe (NonEmpty FeatureValue)
record :: Maybe (NonEmpty FeatureValue)
$sel:record:GetRecordResponse' :: GetRecordResponse -> Maybe (NonEmpty FeatureValue)
record} -> Maybe (NonEmpty FeatureValue)
record) (\s :: GetRecordResponse
s@GetRecordResponse' {} Maybe (NonEmpty FeatureValue)
a -> GetRecordResponse
s {$sel:record:GetRecordResponse' :: Maybe (NonEmpty FeatureValue)
record = Maybe (NonEmpty FeatureValue)
a} :: GetRecordResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData GetRecordResponse where
  rnf :: GetRecordResponse -> ()
rnf GetRecordResponse' {Int
Maybe (NonEmpty FeatureValue)
httpStatus :: Int
record :: Maybe (NonEmpty FeatureValue)
$sel:httpStatus:GetRecordResponse' :: GetRecordResponse -> Int
$sel:record:GetRecordResponse' :: GetRecordResponse -> Maybe (NonEmpty FeatureValue)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty FeatureValue)
record
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus