{-# 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.PutRecord
-- 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)
--
-- Used for data ingestion into the @FeatureStore@. The @PutRecord@ API
-- writes to both the @OnlineStore@ and @OfflineStore@. If the record is
-- the latest record for the @recordIdentifier@, the record is written to
-- both the @OnlineStore@ and @OfflineStore@. If the record is a historic
-- record, it is written only to the @OfflineStore@.
module Amazonka.SageMakerFeatureStoreRuntime.PutRecord
  ( -- * Creating a Request
    PutRecord (..),
    newPutRecord,

    -- * Request Lenses
    putRecord_featureGroupName,
    putRecord_record,

    -- * Destructuring the Response
    PutRecordResponse (..),
    newPutRecordResponse,
  )
where

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

-- | /See:/ 'newPutRecord' smart constructor.
data PutRecord = PutRecord'
  { -- | The name of the feature group that you want to insert the record into.
    PutRecord -> Text
featureGroupName :: Prelude.Text,
    -- | List of FeatureValues to be inserted. This will be a full over-write. If
    -- you only want to update few of the feature values, do the following:
    --
    -- -   Use @GetRecord@ to retrieve the latest record.
    --
    -- -   Update the record returned from @GetRecord@.
    --
    -- -   Use @PutRecord@ to update feature values.
    PutRecord -> NonEmpty FeatureValue
record :: Prelude.NonEmpty FeatureValue
  }
  deriving (PutRecord -> PutRecord -> Bool
(PutRecord -> PutRecord -> Bool)
-> (PutRecord -> PutRecord -> Bool) -> Eq PutRecord
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutRecord -> PutRecord -> Bool
$c/= :: PutRecord -> PutRecord -> Bool
== :: PutRecord -> PutRecord -> Bool
$c== :: PutRecord -> PutRecord -> Bool
Prelude.Eq, ReadPrec [PutRecord]
ReadPrec PutRecord
Int -> ReadS PutRecord
ReadS [PutRecord]
(Int -> ReadS PutRecord)
-> ReadS [PutRecord]
-> ReadPrec PutRecord
-> ReadPrec [PutRecord]
-> Read PutRecord
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutRecord]
$creadListPrec :: ReadPrec [PutRecord]
readPrec :: ReadPrec PutRecord
$creadPrec :: ReadPrec PutRecord
readList :: ReadS [PutRecord]
$creadList :: ReadS [PutRecord]
readsPrec :: Int -> ReadS PutRecord
$creadsPrec :: Int -> ReadS PutRecord
Prelude.Read, Int -> PutRecord -> ShowS
[PutRecord] -> ShowS
PutRecord -> String
(Int -> PutRecord -> ShowS)
-> (PutRecord -> String)
-> ([PutRecord] -> ShowS)
-> Show PutRecord
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutRecord] -> ShowS
$cshowList :: [PutRecord] -> ShowS
show :: PutRecord -> String
$cshow :: PutRecord -> String
showsPrec :: Int -> PutRecord -> ShowS
$cshowsPrec :: Int -> PutRecord -> ShowS
Prelude.Show, (forall x. PutRecord -> Rep PutRecord x)
-> (forall x. Rep PutRecord x -> PutRecord) -> Generic PutRecord
forall x. Rep PutRecord x -> PutRecord
forall x. PutRecord -> Rep PutRecord x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutRecord x -> PutRecord
$cfrom :: forall x. PutRecord -> Rep PutRecord x
Prelude.Generic)

-- |
-- Create a value of 'PutRecord' 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:
--
-- 'featureGroupName', 'putRecord_featureGroupName' - The name of the feature group that you want to insert the record into.
--
-- 'record', 'putRecord_record' - List of FeatureValues to be inserted. This will be a full over-write. If
-- you only want to update few of the feature values, do the following:
--
-- -   Use @GetRecord@ to retrieve the latest record.
--
-- -   Update the record returned from @GetRecord@.
--
-- -   Use @PutRecord@ to update feature values.
newPutRecord ::
  -- | 'featureGroupName'
  Prelude.Text ->
  -- | 'record'
  Prelude.NonEmpty FeatureValue ->
  PutRecord
newPutRecord :: Text -> NonEmpty FeatureValue -> PutRecord
newPutRecord Text
pFeatureGroupName_ NonEmpty FeatureValue
pRecord_ =
  PutRecord' :: Text -> NonEmpty FeatureValue -> PutRecord
PutRecord'
    { $sel:featureGroupName:PutRecord' :: Text
featureGroupName = Text
pFeatureGroupName_,
      $sel:record:PutRecord' :: NonEmpty FeatureValue
record = Tagged (NonEmpty FeatureValue) (Identity (NonEmpty FeatureValue))
-> Tagged
     (NonEmpty FeatureValue) (Identity (NonEmpty FeatureValue))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty FeatureValue) (Identity (NonEmpty FeatureValue))
 -> Tagged
      (NonEmpty FeatureValue) (Identity (NonEmpty FeatureValue)))
-> NonEmpty FeatureValue -> NonEmpty FeatureValue
forall t b. AReview t b -> b -> t
Lens.# NonEmpty FeatureValue
pRecord_
    }

-- | The name of the feature group that you want to insert the record into.
putRecord_featureGroupName :: Lens.Lens' PutRecord Prelude.Text
putRecord_featureGroupName :: (Text -> f Text) -> PutRecord -> f PutRecord
putRecord_featureGroupName = (PutRecord -> Text)
-> (PutRecord -> Text -> PutRecord)
-> Lens PutRecord PutRecord Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRecord' {Text
featureGroupName :: Text
$sel:featureGroupName:PutRecord' :: PutRecord -> Text
featureGroupName} -> Text
featureGroupName) (\s :: PutRecord
s@PutRecord' {} Text
a -> PutRecord
s {$sel:featureGroupName:PutRecord' :: Text
featureGroupName = Text
a} :: PutRecord)

-- | List of FeatureValues to be inserted. This will be a full over-write. If
-- you only want to update few of the feature values, do the following:
--
-- -   Use @GetRecord@ to retrieve the latest record.
--
-- -   Update the record returned from @GetRecord@.
--
-- -   Use @PutRecord@ to update feature values.
putRecord_record :: Lens.Lens' PutRecord (Prelude.NonEmpty FeatureValue)
putRecord_record :: (NonEmpty FeatureValue -> f (NonEmpty FeatureValue))
-> PutRecord -> f PutRecord
putRecord_record = (PutRecord -> NonEmpty FeatureValue)
-> (PutRecord -> NonEmpty FeatureValue -> PutRecord)
-> Lens
     PutRecord PutRecord (NonEmpty FeatureValue) (NonEmpty FeatureValue)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRecord' {NonEmpty FeatureValue
record :: NonEmpty FeatureValue
$sel:record:PutRecord' :: PutRecord -> NonEmpty FeatureValue
record} -> NonEmpty FeatureValue
record) (\s :: PutRecord
s@PutRecord' {} NonEmpty FeatureValue
a -> PutRecord
s {$sel:record:PutRecord' :: NonEmpty FeatureValue
record = NonEmpty FeatureValue
a} :: PutRecord) ((NonEmpty FeatureValue -> f (NonEmpty FeatureValue))
 -> PutRecord -> f PutRecord)
-> ((NonEmpty FeatureValue -> f (NonEmpty FeatureValue))
    -> NonEmpty FeatureValue -> f (NonEmpty FeatureValue))
-> (NonEmpty FeatureValue -> f (NonEmpty FeatureValue))
-> PutRecord
-> f PutRecord
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty FeatureValue -> f (NonEmpty FeatureValue))
-> NonEmpty FeatureValue -> f (NonEmpty FeatureValue)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest PutRecord where
  type AWSResponse PutRecord = PutRecordResponse
  request :: PutRecord -> Request PutRecord
request = Service -> PutRecord -> Request PutRecord
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutRecord
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutRecord)))
response = AWSResponse PutRecord
-> Logger
-> Service
-> Proxy PutRecord
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutRecord)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse PutRecord
PutRecordResponse
PutRecordResponse'

instance Prelude.Hashable PutRecord

instance Prelude.NFData PutRecord

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

instance Core.ToJSON PutRecord where
  toJSON :: PutRecord -> Value
toJSON PutRecord' {NonEmpty FeatureValue
Text
record :: NonEmpty FeatureValue
featureGroupName :: Text
$sel:record:PutRecord' :: PutRecord -> NonEmpty FeatureValue
$sel:featureGroupName:PutRecord' :: PutRecord -> 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
"Record" Text -> NonEmpty FeatureValue -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty FeatureValue
record)]
      )

instance Core.ToPath PutRecord where
  toPath :: PutRecord -> ByteString
toPath PutRecord' {NonEmpty FeatureValue
Text
record :: NonEmpty FeatureValue
featureGroupName :: Text
$sel:record:PutRecord' :: PutRecord -> NonEmpty FeatureValue
$sel:featureGroupName:PutRecord' :: PutRecord -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/FeatureGroup/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
featureGroupName]

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

-- | /See:/ 'newPutRecordResponse' smart constructor.
data PutRecordResponse = PutRecordResponse'
  {
  }
  deriving (PutRecordResponse -> PutRecordResponse -> Bool
(PutRecordResponse -> PutRecordResponse -> Bool)
-> (PutRecordResponse -> PutRecordResponse -> Bool)
-> Eq PutRecordResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutRecordResponse -> PutRecordResponse -> Bool
$c/= :: PutRecordResponse -> PutRecordResponse -> Bool
== :: PutRecordResponse -> PutRecordResponse -> Bool
$c== :: PutRecordResponse -> PutRecordResponse -> Bool
Prelude.Eq, ReadPrec [PutRecordResponse]
ReadPrec PutRecordResponse
Int -> ReadS PutRecordResponse
ReadS [PutRecordResponse]
(Int -> ReadS PutRecordResponse)
-> ReadS [PutRecordResponse]
-> ReadPrec PutRecordResponse
-> ReadPrec [PutRecordResponse]
-> Read PutRecordResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutRecordResponse]
$creadListPrec :: ReadPrec [PutRecordResponse]
readPrec :: ReadPrec PutRecordResponse
$creadPrec :: ReadPrec PutRecordResponse
readList :: ReadS [PutRecordResponse]
$creadList :: ReadS [PutRecordResponse]
readsPrec :: Int -> ReadS PutRecordResponse
$creadsPrec :: Int -> ReadS PutRecordResponse
Prelude.Read, Int -> PutRecordResponse -> ShowS
[PutRecordResponse] -> ShowS
PutRecordResponse -> String
(Int -> PutRecordResponse -> ShowS)
-> (PutRecordResponse -> String)
-> ([PutRecordResponse] -> ShowS)
-> Show PutRecordResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutRecordResponse] -> ShowS
$cshowList :: [PutRecordResponse] -> ShowS
show :: PutRecordResponse -> String
$cshow :: PutRecordResponse -> String
showsPrec :: Int -> PutRecordResponse -> ShowS
$cshowsPrec :: Int -> PutRecordResponse -> ShowS
Prelude.Show, (forall x. PutRecordResponse -> Rep PutRecordResponse x)
-> (forall x. Rep PutRecordResponse x -> PutRecordResponse)
-> Generic PutRecordResponse
forall x. Rep PutRecordResponse x -> PutRecordResponse
forall x. PutRecordResponse -> Rep PutRecordResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutRecordResponse x -> PutRecordResponse
$cfrom :: forall x. PutRecordResponse -> Rep PutRecordResponse x
Prelude.Generic)

-- |
-- Create a value of 'PutRecordResponse' 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.
newPutRecordResponse ::
  PutRecordResponse
newPutRecordResponse :: PutRecordResponse
newPutRecordResponse = PutRecordResponse
PutRecordResponse'

instance Prelude.NFData PutRecordResponse