{-# 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.SSM.PutInventory
-- 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)
--
-- Bulk update custom inventory items on one more instance. The request
-- adds an inventory item, if it doesn\'t already exist, or updates an
-- inventory item, if it does exist.
module Amazonka.SSM.PutInventory
  ( -- * Creating a Request
    PutInventory (..),
    newPutInventory,

    -- * Request Lenses
    putInventory_instanceId,
    putInventory_items,

    -- * Destructuring the Response
    PutInventoryResponse (..),
    newPutInventoryResponse,

    -- * Response Lenses
    putInventoryResponse_message,
    putInventoryResponse_httpStatus,
  )
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.SSM.Types

-- | /See:/ 'newPutInventory' smart constructor.
data PutInventory = PutInventory'
  { -- | An instance ID where you want to add or update inventory items.
    PutInventory -> Text
instanceId :: Prelude.Text,
    -- | The inventory items that you want to add or update on instances.
    PutInventory -> NonEmpty InventoryItem
items :: Prelude.NonEmpty InventoryItem
  }
  deriving (PutInventory -> PutInventory -> Bool
(PutInventory -> PutInventory -> Bool)
-> (PutInventory -> PutInventory -> Bool) -> Eq PutInventory
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutInventory -> PutInventory -> Bool
$c/= :: PutInventory -> PutInventory -> Bool
== :: PutInventory -> PutInventory -> Bool
$c== :: PutInventory -> PutInventory -> Bool
Prelude.Eq, ReadPrec [PutInventory]
ReadPrec PutInventory
Int -> ReadS PutInventory
ReadS [PutInventory]
(Int -> ReadS PutInventory)
-> ReadS [PutInventory]
-> ReadPrec PutInventory
-> ReadPrec [PutInventory]
-> Read PutInventory
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutInventory]
$creadListPrec :: ReadPrec [PutInventory]
readPrec :: ReadPrec PutInventory
$creadPrec :: ReadPrec PutInventory
readList :: ReadS [PutInventory]
$creadList :: ReadS [PutInventory]
readsPrec :: Int -> ReadS PutInventory
$creadsPrec :: Int -> ReadS PutInventory
Prelude.Read, Int -> PutInventory -> ShowS
[PutInventory] -> ShowS
PutInventory -> String
(Int -> PutInventory -> ShowS)
-> (PutInventory -> String)
-> ([PutInventory] -> ShowS)
-> Show PutInventory
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutInventory] -> ShowS
$cshowList :: [PutInventory] -> ShowS
show :: PutInventory -> String
$cshow :: PutInventory -> String
showsPrec :: Int -> PutInventory -> ShowS
$cshowsPrec :: Int -> PutInventory -> ShowS
Prelude.Show, (forall x. PutInventory -> Rep PutInventory x)
-> (forall x. Rep PutInventory x -> PutInventory)
-> Generic PutInventory
forall x. Rep PutInventory x -> PutInventory
forall x. PutInventory -> Rep PutInventory x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutInventory x -> PutInventory
$cfrom :: forall x. PutInventory -> Rep PutInventory x
Prelude.Generic)

-- |
-- Create a value of 'PutInventory' 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:
--
-- 'instanceId', 'putInventory_instanceId' - An instance ID where you want to add or update inventory items.
--
-- 'items', 'putInventory_items' - The inventory items that you want to add or update on instances.
newPutInventory ::
  -- | 'instanceId'
  Prelude.Text ->
  -- | 'items'
  Prelude.NonEmpty InventoryItem ->
  PutInventory
newPutInventory :: Text -> NonEmpty InventoryItem -> PutInventory
newPutInventory Text
pInstanceId_ NonEmpty InventoryItem
pItems_ =
  PutInventory' :: Text -> NonEmpty InventoryItem -> PutInventory
PutInventory'
    { $sel:instanceId:PutInventory' :: Text
instanceId = Text
pInstanceId_,
      $sel:items:PutInventory' :: NonEmpty InventoryItem
items = Tagged (NonEmpty InventoryItem) (Identity (NonEmpty InventoryItem))
-> Tagged
     (NonEmpty InventoryItem) (Identity (NonEmpty InventoryItem))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged
   (NonEmpty InventoryItem) (Identity (NonEmpty InventoryItem))
 -> Tagged
      (NonEmpty InventoryItem) (Identity (NonEmpty InventoryItem)))
-> NonEmpty InventoryItem -> NonEmpty InventoryItem
forall t b. AReview t b -> b -> t
Lens.# NonEmpty InventoryItem
pItems_
    }

-- | An instance ID where you want to add or update inventory items.
putInventory_instanceId :: Lens.Lens' PutInventory Prelude.Text
putInventory_instanceId :: (Text -> f Text) -> PutInventory -> f PutInventory
putInventory_instanceId = (PutInventory -> Text)
-> (PutInventory -> Text -> PutInventory)
-> Lens PutInventory PutInventory Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutInventory' {Text
instanceId :: Text
$sel:instanceId:PutInventory' :: PutInventory -> Text
instanceId} -> Text
instanceId) (\s :: PutInventory
s@PutInventory' {} Text
a -> PutInventory
s {$sel:instanceId:PutInventory' :: Text
instanceId = Text
a} :: PutInventory)

-- | The inventory items that you want to add or update on instances.
putInventory_items :: Lens.Lens' PutInventory (Prelude.NonEmpty InventoryItem)
putInventory_items :: (NonEmpty InventoryItem -> f (NonEmpty InventoryItem))
-> PutInventory -> f PutInventory
putInventory_items = (PutInventory -> NonEmpty InventoryItem)
-> (PutInventory -> NonEmpty InventoryItem -> PutInventory)
-> Lens
     PutInventory
     PutInventory
     (NonEmpty InventoryItem)
     (NonEmpty InventoryItem)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutInventory' {NonEmpty InventoryItem
items :: NonEmpty InventoryItem
$sel:items:PutInventory' :: PutInventory -> NonEmpty InventoryItem
items} -> NonEmpty InventoryItem
items) (\s :: PutInventory
s@PutInventory' {} NonEmpty InventoryItem
a -> PutInventory
s {$sel:items:PutInventory' :: NonEmpty InventoryItem
items = NonEmpty InventoryItem
a} :: PutInventory) ((NonEmpty InventoryItem -> f (NonEmpty InventoryItem))
 -> PutInventory -> f PutInventory)
-> ((NonEmpty InventoryItem -> f (NonEmpty InventoryItem))
    -> NonEmpty InventoryItem -> f (NonEmpty InventoryItem))
-> (NonEmpty InventoryItem -> f (NonEmpty InventoryItem))
-> PutInventory
-> f PutInventory
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty InventoryItem -> f (NonEmpty InventoryItem))
-> NonEmpty InventoryItem -> f (NonEmpty InventoryItem)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest PutInventory where
  type AWSResponse PutInventory = PutInventoryResponse
  request :: PutInventory -> Request PutInventory
request = Service -> PutInventory -> Request PutInventory
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutInventory
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutInventory)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse PutInventory))
-> Logger
-> Service
-> Proxy PutInventory
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutInventory)))
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 -> Int -> PutInventoryResponse
PutInventoryResponse'
            (Maybe Text -> Int -> PutInventoryResponse)
-> Either String (Maybe Text)
-> Either String (Int -> PutInventoryResponse)
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
"Message")
            Either String (Int -> PutInventoryResponse)
-> Either String Int -> Either String PutInventoryResponse
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 PutInventory

instance Prelude.NFData PutInventory

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

instance Core.ToJSON PutInventory where
  toJSON :: PutInventory -> Value
toJSON PutInventory' {NonEmpty InventoryItem
Text
items :: NonEmpty InventoryItem
instanceId :: Text
$sel:items:PutInventory' :: PutInventory -> NonEmpty InventoryItem
$sel:instanceId:PutInventory' :: PutInventory -> 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
"InstanceId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
instanceId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Items" Text -> NonEmpty InventoryItem -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty InventoryItem
items)
          ]
      )

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

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

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

-- |
-- Create a value of 'PutInventoryResponse' 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:
--
-- 'message', 'putInventoryResponse_message' - Information about the request.
--
-- 'httpStatus', 'putInventoryResponse_httpStatus' - The response's http status code.
newPutInventoryResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutInventoryResponse
newPutInventoryResponse :: Int -> PutInventoryResponse
newPutInventoryResponse Int
pHttpStatus_ =
  PutInventoryResponse' :: Maybe Text -> Int -> PutInventoryResponse
PutInventoryResponse'
    { $sel:message:PutInventoryResponse' :: Maybe Text
message = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PutInventoryResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about the request.
putInventoryResponse_message :: Lens.Lens' PutInventoryResponse (Prelude.Maybe Prelude.Text)
putInventoryResponse_message :: (Maybe Text -> f (Maybe Text))
-> PutInventoryResponse -> f PutInventoryResponse
putInventoryResponse_message = (PutInventoryResponse -> Maybe Text)
-> (PutInventoryResponse -> Maybe Text -> PutInventoryResponse)
-> Lens
     PutInventoryResponse PutInventoryResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutInventoryResponse' {Maybe Text
message :: Maybe Text
$sel:message:PutInventoryResponse' :: PutInventoryResponse -> Maybe Text
message} -> Maybe Text
message) (\s :: PutInventoryResponse
s@PutInventoryResponse' {} Maybe Text
a -> PutInventoryResponse
s {$sel:message:PutInventoryResponse' :: Maybe Text
message = Maybe Text
a} :: PutInventoryResponse)

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

instance Prelude.NFData PutInventoryResponse