{-# 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.IoTFleetWise.BatchUpdateVehicle
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Updates a group, or batch, of vehicles.
--
-- You must specify a decoder manifest and a vehicle model (model manifest)
-- for each vehicle.
--
-- For more information, see
-- <https://docs.aws.amazon.com/iot-fleetwise/latest/developerguide/update-vehicles-cli.html Update multiple vehicles (AWS CLI)>
-- in the /Amazon Web Services IoT FleetWise Developer Guide/.
module Amazonka.IoTFleetWise.BatchUpdateVehicle
  ( -- * Creating a Request
    BatchUpdateVehicle (..),
    newBatchUpdateVehicle,

    -- * Request Lenses
    batchUpdateVehicle_vehicles,

    -- * Destructuring the Response
    BatchUpdateVehicleResponse (..),
    newBatchUpdateVehicleResponse,

    -- * Response Lenses
    batchUpdateVehicleResponse_errors,
    batchUpdateVehicleResponse_vehicles,
    batchUpdateVehicleResponse_httpStatus,
  )
where

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

-- | /See:/ 'newBatchUpdateVehicle' smart constructor.
data BatchUpdateVehicle = BatchUpdateVehicle'
  { -- | A list of information about the vehicles to update. For more
    -- information, see the API data type.
    BatchUpdateVehicle -> [UpdateVehicleRequestItem]
vehicles :: [UpdateVehicleRequestItem]
  }
  deriving (BatchUpdateVehicle -> BatchUpdateVehicle -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchUpdateVehicle -> BatchUpdateVehicle -> Bool
$c/= :: BatchUpdateVehicle -> BatchUpdateVehicle -> Bool
== :: BatchUpdateVehicle -> BatchUpdateVehicle -> Bool
$c== :: BatchUpdateVehicle -> BatchUpdateVehicle -> Bool
Prelude.Eq, ReadPrec [BatchUpdateVehicle]
ReadPrec BatchUpdateVehicle
Int -> ReadS BatchUpdateVehicle
ReadS [BatchUpdateVehicle]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchUpdateVehicle]
$creadListPrec :: ReadPrec [BatchUpdateVehicle]
readPrec :: ReadPrec BatchUpdateVehicle
$creadPrec :: ReadPrec BatchUpdateVehicle
readList :: ReadS [BatchUpdateVehicle]
$creadList :: ReadS [BatchUpdateVehicle]
readsPrec :: Int -> ReadS BatchUpdateVehicle
$creadsPrec :: Int -> ReadS BatchUpdateVehicle
Prelude.Read, Int -> BatchUpdateVehicle -> ShowS
[BatchUpdateVehicle] -> ShowS
BatchUpdateVehicle -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchUpdateVehicle] -> ShowS
$cshowList :: [BatchUpdateVehicle] -> ShowS
show :: BatchUpdateVehicle -> String
$cshow :: BatchUpdateVehicle -> String
showsPrec :: Int -> BatchUpdateVehicle -> ShowS
$cshowsPrec :: Int -> BatchUpdateVehicle -> ShowS
Prelude.Show, forall x. Rep BatchUpdateVehicle x -> BatchUpdateVehicle
forall x. BatchUpdateVehicle -> Rep BatchUpdateVehicle x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchUpdateVehicle x -> BatchUpdateVehicle
$cfrom :: forall x. BatchUpdateVehicle -> Rep BatchUpdateVehicle x
Prelude.Generic)

-- |
-- Create a value of 'BatchUpdateVehicle' 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:
--
-- 'vehicles', 'batchUpdateVehicle_vehicles' - A list of information about the vehicles to update. For more
-- information, see the API data type.
newBatchUpdateVehicle ::
  BatchUpdateVehicle
newBatchUpdateVehicle :: BatchUpdateVehicle
newBatchUpdateVehicle =
  BatchUpdateVehicle' {$sel:vehicles:BatchUpdateVehicle' :: [UpdateVehicleRequestItem]
vehicles = forall a. Monoid a => a
Prelude.mempty}

-- | A list of information about the vehicles to update. For more
-- information, see the API data type.
batchUpdateVehicle_vehicles :: Lens.Lens' BatchUpdateVehicle [UpdateVehicleRequestItem]
batchUpdateVehicle_vehicles :: Lens' BatchUpdateVehicle [UpdateVehicleRequestItem]
batchUpdateVehicle_vehicles = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchUpdateVehicle' {[UpdateVehicleRequestItem]
vehicles :: [UpdateVehicleRequestItem]
$sel:vehicles:BatchUpdateVehicle' :: BatchUpdateVehicle -> [UpdateVehicleRequestItem]
vehicles} -> [UpdateVehicleRequestItem]
vehicles) (\s :: BatchUpdateVehicle
s@BatchUpdateVehicle' {} [UpdateVehicleRequestItem]
a -> BatchUpdateVehicle
s {$sel:vehicles:BatchUpdateVehicle' :: [UpdateVehicleRequestItem]
vehicles = [UpdateVehicleRequestItem]
a} :: BatchUpdateVehicle) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest BatchUpdateVehicle where
  type
    AWSResponse BatchUpdateVehicle =
      BatchUpdateVehicleResponse
  request :: (Service -> Service)
-> BatchUpdateVehicle -> Request BatchUpdateVehicle
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy BatchUpdateVehicle
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse BatchUpdateVehicle)))
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 [UpdateVehicleError]
-> Maybe [UpdateVehicleResponseItem]
-> Int
-> BatchUpdateVehicleResponse
BatchUpdateVehicleResponse'
            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
"errors" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"vehicles" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            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 BatchUpdateVehicle where
  hashWithSalt :: Int -> BatchUpdateVehicle -> Int
hashWithSalt Int
_salt BatchUpdateVehicle' {[UpdateVehicleRequestItem]
vehicles :: [UpdateVehicleRequestItem]
$sel:vehicles:BatchUpdateVehicle' :: BatchUpdateVehicle -> [UpdateVehicleRequestItem]
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [UpdateVehicleRequestItem]
vehicles

instance Prelude.NFData BatchUpdateVehicle where
  rnf :: BatchUpdateVehicle -> ()
rnf BatchUpdateVehicle' {[UpdateVehicleRequestItem]
vehicles :: [UpdateVehicleRequestItem]
$sel:vehicles:BatchUpdateVehicle' :: BatchUpdateVehicle -> [UpdateVehicleRequestItem]
..} = forall a. NFData a => a -> ()
Prelude.rnf [UpdateVehicleRequestItem]
vehicles

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

instance Data.ToJSON BatchUpdateVehicle where
  toJSON :: BatchUpdateVehicle -> Value
toJSON BatchUpdateVehicle' {[UpdateVehicleRequestItem]
vehicles :: [UpdateVehicleRequestItem]
$sel:vehicles:BatchUpdateVehicle' :: BatchUpdateVehicle -> [UpdateVehicleRequestItem]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"vehicles" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [UpdateVehicleRequestItem]
vehicles)]
      )

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

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

-- | /See:/ 'newBatchUpdateVehicleResponse' smart constructor.
data BatchUpdateVehicleResponse = BatchUpdateVehicleResponse'
  { -- | A list of information about errors returned while updating a batch of
    -- vehicles, or, if there aren\'t any errors, an empty list.
    BatchUpdateVehicleResponse -> Maybe [UpdateVehicleError]
errors :: Prelude.Maybe [UpdateVehicleError],
    -- | A list of information about the batch of updated vehicles.
    --
    -- This list contains only unique IDs for the vehicles that were updated.
    BatchUpdateVehicleResponse -> Maybe [UpdateVehicleResponseItem]
vehicles :: Prelude.Maybe [UpdateVehicleResponseItem],
    -- | The response's http status code.
    BatchUpdateVehicleResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (BatchUpdateVehicleResponse -> BatchUpdateVehicleResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchUpdateVehicleResponse -> BatchUpdateVehicleResponse -> Bool
$c/= :: BatchUpdateVehicleResponse -> BatchUpdateVehicleResponse -> Bool
== :: BatchUpdateVehicleResponse -> BatchUpdateVehicleResponse -> Bool
$c== :: BatchUpdateVehicleResponse -> BatchUpdateVehicleResponse -> Bool
Prelude.Eq, ReadPrec [BatchUpdateVehicleResponse]
ReadPrec BatchUpdateVehicleResponse
Int -> ReadS BatchUpdateVehicleResponse
ReadS [BatchUpdateVehicleResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchUpdateVehicleResponse]
$creadListPrec :: ReadPrec [BatchUpdateVehicleResponse]
readPrec :: ReadPrec BatchUpdateVehicleResponse
$creadPrec :: ReadPrec BatchUpdateVehicleResponse
readList :: ReadS [BatchUpdateVehicleResponse]
$creadList :: ReadS [BatchUpdateVehicleResponse]
readsPrec :: Int -> ReadS BatchUpdateVehicleResponse
$creadsPrec :: Int -> ReadS BatchUpdateVehicleResponse
Prelude.Read, Int -> BatchUpdateVehicleResponse -> ShowS
[BatchUpdateVehicleResponse] -> ShowS
BatchUpdateVehicleResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchUpdateVehicleResponse] -> ShowS
$cshowList :: [BatchUpdateVehicleResponse] -> ShowS
show :: BatchUpdateVehicleResponse -> String
$cshow :: BatchUpdateVehicleResponse -> String
showsPrec :: Int -> BatchUpdateVehicleResponse -> ShowS
$cshowsPrec :: Int -> BatchUpdateVehicleResponse -> ShowS
Prelude.Show, forall x.
Rep BatchUpdateVehicleResponse x -> BatchUpdateVehicleResponse
forall x.
BatchUpdateVehicleResponse -> Rep BatchUpdateVehicleResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep BatchUpdateVehicleResponse x -> BatchUpdateVehicleResponse
$cfrom :: forall x.
BatchUpdateVehicleResponse -> Rep BatchUpdateVehicleResponse x
Prelude.Generic)

-- |
-- Create a value of 'BatchUpdateVehicleResponse' 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:
--
-- 'errors', 'batchUpdateVehicleResponse_errors' - A list of information about errors returned while updating a batch of
-- vehicles, or, if there aren\'t any errors, an empty list.
--
-- 'vehicles', 'batchUpdateVehicleResponse_vehicles' - A list of information about the batch of updated vehicles.
--
-- This list contains only unique IDs for the vehicles that were updated.
--
-- 'httpStatus', 'batchUpdateVehicleResponse_httpStatus' - The response's http status code.
newBatchUpdateVehicleResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  BatchUpdateVehicleResponse
newBatchUpdateVehicleResponse :: Int -> BatchUpdateVehicleResponse
newBatchUpdateVehicleResponse Int
pHttpStatus_ =
  BatchUpdateVehicleResponse'
    { $sel:errors:BatchUpdateVehicleResponse' :: Maybe [UpdateVehicleError]
errors =
        forall a. Maybe a
Prelude.Nothing,
      $sel:vehicles:BatchUpdateVehicleResponse' :: Maybe [UpdateVehicleResponseItem]
vehicles = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:BatchUpdateVehicleResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A list of information about errors returned while updating a batch of
-- vehicles, or, if there aren\'t any errors, an empty list.
batchUpdateVehicleResponse_errors :: Lens.Lens' BatchUpdateVehicleResponse (Prelude.Maybe [UpdateVehicleError])
batchUpdateVehicleResponse_errors :: Lens' BatchUpdateVehicleResponse (Maybe [UpdateVehicleError])
batchUpdateVehicleResponse_errors = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchUpdateVehicleResponse' {Maybe [UpdateVehicleError]
errors :: Maybe [UpdateVehicleError]
$sel:errors:BatchUpdateVehicleResponse' :: BatchUpdateVehicleResponse -> Maybe [UpdateVehicleError]
errors} -> Maybe [UpdateVehicleError]
errors) (\s :: BatchUpdateVehicleResponse
s@BatchUpdateVehicleResponse' {} Maybe [UpdateVehicleError]
a -> BatchUpdateVehicleResponse
s {$sel:errors:BatchUpdateVehicleResponse' :: Maybe [UpdateVehicleError]
errors = Maybe [UpdateVehicleError]
a} :: BatchUpdateVehicleResponse) 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

-- | A list of information about the batch of updated vehicles.
--
-- This list contains only unique IDs for the vehicles that were updated.
batchUpdateVehicleResponse_vehicles :: Lens.Lens' BatchUpdateVehicleResponse (Prelude.Maybe [UpdateVehicleResponseItem])
batchUpdateVehicleResponse_vehicles :: Lens'
  BatchUpdateVehicleResponse (Maybe [UpdateVehicleResponseItem])
batchUpdateVehicleResponse_vehicles = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchUpdateVehicleResponse' {Maybe [UpdateVehicleResponseItem]
vehicles :: Maybe [UpdateVehicleResponseItem]
$sel:vehicles:BatchUpdateVehicleResponse' :: BatchUpdateVehicleResponse -> Maybe [UpdateVehicleResponseItem]
vehicles} -> Maybe [UpdateVehicleResponseItem]
vehicles) (\s :: BatchUpdateVehicleResponse
s@BatchUpdateVehicleResponse' {} Maybe [UpdateVehicleResponseItem]
a -> BatchUpdateVehicleResponse
s {$sel:vehicles:BatchUpdateVehicleResponse' :: Maybe [UpdateVehicleResponseItem]
vehicles = Maybe [UpdateVehicleResponseItem]
a} :: BatchUpdateVehicleResponse) 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.
batchUpdateVehicleResponse_httpStatus :: Lens.Lens' BatchUpdateVehicleResponse Prelude.Int
batchUpdateVehicleResponse_httpStatus :: Lens' BatchUpdateVehicleResponse Int
batchUpdateVehicleResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchUpdateVehicleResponse' {Int
httpStatus :: Int
$sel:httpStatus:BatchUpdateVehicleResponse' :: BatchUpdateVehicleResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: BatchUpdateVehicleResponse
s@BatchUpdateVehicleResponse' {} Int
a -> BatchUpdateVehicleResponse
s {$sel:httpStatus:BatchUpdateVehicleResponse' :: Int
httpStatus = Int
a} :: BatchUpdateVehicleResponse)

instance Prelude.NFData BatchUpdateVehicleResponse where
  rnf :: BatchUpdateVehicleResponse -> ()
rnf BatchUpdateVehicleResponse' {Int
Maybe [UpdateVehicleError]
Maybe [UpdateVehicleResponseItem]
httpStatus :: Int
vehicles :: Maybe [UpdateVehicleResponseItem]
errors :: Maybe [UpdateVehicleError]
$sel:httpStatus:BatchUpdateVehicleResponse' :: BatchUpdateVehicleResponse -> Int
$sel:vehicles:BatchUpdateVehicleResponse' :: BatchUpdateVehicleResponse -> Maybe [UpdateVehicleResponseItem]
$sel:errors:BatchUpdateVehicleResponse' :: BatchUpdateVehicleResponse -> Maybe [UpdateVehicleError]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [UpdateVehicleError]
errors
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [UpdateVehicleResponseItem]
vehicles
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus