{-# 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.BatchCreateVehicle
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates 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/create-vehicles-cli.html Create multiple vehicles (AWS CLI)>
-- in the /Amazon Web Services IoT FleetWise Developer Guide/.
module Amazonka.IoTFleetWise.BatchCreateVehicle
  ( -- * Creating a Request
    BatchCreateVehicle (..),
    newBatchCreateVehicle,

    -- * Request Lenses
    batchCreateVehicle_vehicles,

    -- * Destructuring the Response
    BatchCreateVehicleResponse (..),
    newBatchCreateVehicleResponse,

    -- * Response Lenses
    batchCreateVehicleResponse_errors,
    batchCreateVehicleResponse_vehicles,
    batchCreateVehicleResponse_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:/ 'newBatchCreateVehicle' smart constructor.
data BatchCreateVehicle = BatchCreateVehicle'
  { -- | A list of information about each vehicle to create. For more
    -- information, see the API data type.
    BatchCreateVehicle -> [CreateVehicleRequestItem]
vehicles :: [CreateVehicleRequestItem]
  }
  deriving (BatchCreateVehicle -> BatchCreateVehicle -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchCreateVehicle -> BatchCreateVehicle -> Bool
$c/= :: BatchCreateVehicle -> BatchCreateVehicle -> Bool
== :: BatchCreateVehicle -> BatchCreateVehicle -> Bool
$c== :: BatchCreateVehicle -> BatchCreateVehicle -> Bool
Prelude.Eq, ReadPrec [BatchCreateVehicle]
ReadPrec BatchCreateVehicle
Int -> ReadS BatchCreateVehicle
ReadS [BatchCreateVehicle]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchCreateVehicle]
$creadListPrec :: ReadPrec [BatchCreateVehicle]
readPrec :: ReadPrec BatchCreateVehicle
$creadPrec :: ReadPrec BatchCreateVehicle
readList :: ReadS [BatchCreateVehicle]
$creadList :: ReadS [BatchCreateVehicle]
readsPrec :: Int -> ReadS BatchCreateVehicle
$creadsPrec :: Int -> ReadS BatchCreateVehicle
Prelude.Read, Int -> BatchCreateVehicle -> ShowS
[BatchCreateVehicle] -> ShowS
BatchCreateVehicle -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchCreateVehicle] -> ShowS
$cshowList :: [BatchCreateVehicle] -> ShowS
show :: BatchCreateVehicle -> String
$cshow :: BatchCreateVehicle -> String
showsPrec :: Int -> BatchCreateVehicle -> ShowS
$cshowsPrec :: Int -> BatchCreateVehicle -> ShowS
Prelude.Show, forall x. Rep BatchCreateVehicle x -> BatchCreateVehicle
forall x. BatchCreateVehicle -> Rep BatchCreateVehicle x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchCreateVehicle x -> BatchCreateVehicle
$cfrom :: forall x. BatchCreateVehicle -> Rep BatchCreateVehicle x
Prelude.Generic)

-- |
-- Create a value of 'BatchCreateVehicle' 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', 'batchCreateVehicle_vehicles' - A list of information about each vehicle to create. For more
-- information, see the API data type.
newBatchCreateVehicle ::
  BatchCreateVehicle
newBatchCreateVehicle :: BatchCreateVehicle
newBatchCreateVehicle =
  BatchCreateVehicle' {$sel:vehicles:BatchCreateVehicle' :: [CreateVehicleRequestItem]
vehicles = forall a. Monoid a => a
Prelude.mempty}

-- | A list of information about each vehicle to create. For more
-- information, see the API data type.
batchCreateVehicle_vehicles :: Lens.Lens' BatchCreateVehicle [CreateVehicleRequestItem]
batchCreateVehicle_vehicles :: Lens' BatchCreateVehicle [CreateVehicleRequestItem]
batchCreateVehicle_vehicles = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchCreateVehicle' {[CreateVehicleRequestItem]
vehicles :: [CreateVehicleRequestItem]
$sel:vehicles:BatchCreateVehicle' :: BatchCreateVehicle -> [CreateVehicleRequestItem]
vehicles} -> [CreateVehicleRequestItem]
vehicles) (\s :: BatchCreateVehicle
s@BatchCreateVehicle' {} [CreateVehicleRequestItem]
a -> BatchCreateVehicle
s {$sel:vehicles:BatchCreateVehicle' :: [CreateVehicleRequestItem]
vehicles = [CreateVehicleRequestItem]
a} :: BatchCreateVehicle) 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 BatchCreateVehicle where
  type
    AWSResponse BatchCreateVehicle =
      BatchCreateVehicleResponse
  request :: (Service -> Service)
-> BatchCreateVehicle -> Request BatchCreateVehicle
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 BatchCreateVehicle
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse BatchCreateVehicle)))
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 [CreateVehicleError]
-> Maybe [CreateVehicleResponseItem]
-> Int
-> BatchCreateVehicleResponse
BatchCreateVehicleResponse'
            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 BatchCreateVehicle where
  hashWithSalt :: Int -> BatchCreateVehicle -> Int
hashWithSalt Int
_salt BatchCreateVehicle' {[CreateVehicleRequestItem]
vehicles :: [CreateVehicleRequestItem]
$sel:vehicles:BatchCreateVehicle' :: BatchCreateVehicle -> [CreateVehicleRequestItem]
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [CreateVehicleRequestItem]
vehicles

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

instance Data.ToHeaders BatchCreateVehicle where
  toHeaders :: BatchCreateVehicle -> 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.BatchCreateVehicle" ::
                          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 BatchCreateVehicle where
  toJSON :: BatchCreateVehicle -> Value
toJSON BatchCreateVehicle' {[CreateVehicleRequestItem]
vehicles :: [CreateVehicleRequestItem]
$sel:vehicles:BatchCreateVehicle' :: BatchCreateVehicle -> [CreateVehicleRequestItem]
..} =
    [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..= [CreateVehicleRequestItem]
vehicles)]
      )

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

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

-- | /See:/ 'newBatchCreateVehicleResponse' smart constructor.
data BatchCreateVehicleResponse = BatchCreateVehicleResponse'
  { -- | A list of information about creation errors, or an empty list if there
    -- aren\'t any errors.
    BatchCreateVehicleResponse -> Maybe [CreateVehicleError]
errors :: Prelude.Maybe [CreateVehicleError],
    -- | A list of information about a batch of created vehicles. For more
    -- information, see the API data type.
    BatchCreateVehicleResponse -> Maybe [CreateVehicleResponseItem]
vehicles :: Prelude.Maybe [CreateVehicleResponseItem],
    -- | The response's http status code.
    BatchCreateVehicleResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (BatchCreateVehicleResponse -> BatchCreateVehicleResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchCreateVehicleResponse -> BatchCreateVehicleResponse -> Bool
$c/= :: BatchCreateVehicleResponse -> BatchCreateVehicleResponse -> Bool
== :: BatchCreateVehicleResponse -> BatchCreateVehicleResponse -> Bool
$c== :: BatchCreateVehicleResponse -> BatchCreateVehicleResponse -> Bool
Prelude.Eq, ReadPrec [BatchCreateVehicleResponse]
ReadPrec BatchCreateVehicleResponse
Int -> ReadS BatchCreateVehicleResponse
ReadS [BatchCreateVehicleResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchCreateVehicleResponse]
$creadListPrec :: ReadPrec [BatchCreateVehicleResponse]
readPrec :: ReadPrec BatchCreateVehicleResponse
$creadPrec :: ReadPrec BatchCreateVehicleResponse
readList :: ReadS [BatchCreateVehicleResponse]
$creadList :: ReadS [BatchCreateVehicleResponse]
readsPrec :: Int -> ReadS BatchCreateVehicleResponse
$creadsPrec :: Int -> ReadS BatchCreateVehicleResponse
Prelude.Read, Int -> BatchCreateVehicleResponse -> ShowS
[BatchCreateVehicleResponse] -> ShowS
BatchCreateVehicleResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchCreateVehicleResponse] -> ShowS
$cshowList :: [BatchCreateVehicleResponse] -> ShowS
show :: BatchCreateVehicleResponse -> String
$cshow :: BatchCreateVehicleResponse -> String
showsPrec :: Int -> BatchCreateVehicleResponse -> ShowS
$cshowsPrec :: Int -> BatchCreateVehicleResponse -> ShowS
Prelude.Show, forall x.
Rep BatchCreateVehicleResponse x -> BatchCreateVehicleResponse
forall x.
BatchCreateVehicleResponse -> Rep BatchCreateVehicleResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep BatchCreateVehicleResponse x -> BatchCreateVehicleResponse
$cfrom :: forall x.
BatchCreateVehicleResponse -> Rep BatchCreateVehicleResponse x
Prelude.Generic)

-- |
-- Create a value of 'BatchCreateVehicleResponse' 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', 'batchCreateVehicleResponse_errors' - A list of information about creation errors, or an empty list if there
-- aren\'t any errors.
--
-- 'vehicles', 'batchCreateVehicleResponse_vehicles' - A list of information about a batch of created vehicles. For more
-- information, see the API data type.
--
-- 'httpStatus', 'batchCreateVehicleResponse_httpStatus' - The response's http status code.
newBatchCreateVehicleResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  BatchCreateVehicleResponse
newBatchCreateVehicleResponse :: Int -> BatchCreateVehicleResponse
newBatchCreateVehicleResponse Int
pHttpStatus_ =
  BatchCreateVehicleResponse'
    { $sel:errors:BatchCreateVehicleResponse' :: Maybe [CreateVehicleError]
errors =
        forall a. Maybe a
Prelude.Nothing,
      $sel:vehicles:BatchCreateVehicleResponse' :: Maybe [CreateVehicleResponseItem]
vehicles = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:BatchCreateVehicleResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A list of information about creation errors, or an empty list if there
-- aren\'t any errors.
batchCreateVehicleResponse_errors :: Lens.Lens' BatchCreateVehicleResponse (Prelude.Maybe [CreateVehicleError])
batchCreateVehicleResponse_errors :: Lens' BatchCreateVehicleResponse (Maybe [CreateVehicleError])
batchCreateVehicleResponse_errors = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchCreateVehicleResponse' {Maybe [CreateVehicleError]
errors :: Maybe [CreateVehicleError]
$sel:errors:BatchCreateVehicleResponse' :: BatchCreateVehicleResponse -> Maybe [CreateVehicleError]
errors} -> Maybe [CreateVehicleError]
errors) (\s :: BatchCreateVehicleResponse
s@BatchCreateVehicleResponse' {} Maybe [CreateVehicleError]
a -> BatchCreateVehicleResponse
s {$sel:errors:BatchCreateVehicleResponse' :: Maybe [CreateVehicleError]
errors = Maybe [CreateVehicleError]
a} :: BatchCreateVehicleResponse) 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 a batch of created vehicles. For more
-- information, see the API data type.
batchCreateVehicleResponse_vehicles :: Lens.Lens' BatchCreateVehicleResponse (Prelude.Maybe [CreateVehicleResponseItem])
batchCreateVehicleResponse_vehicles :: Lens'
  BatchCreateVehicleResponse (Maybe [CreateVehicleResponseItem])
batchCreateVehicleResponse_vehicles = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchCreateVehicleResponse' {Maybe [CreateVehicleResponseItem]
vehicles :: Maybe [CreateVehicleResponseItem]
$sel:vehicles:BatchCreateVehicleResponse' :: BatchCreateVehicleResponse -> Maybe [CreateVehicleResponseItem]
vehicles} -> Maybe [CreateVehicleResponseItem]
vehicles) (\s :: BatchCreateVehicleResponse
s@BatchCreateVehicleResponse' {} Maybe [CreateVehicleResponseItem]
a -> BatchCreateVehicleResponse
s {$sel:vehicles:BatchCreateVehicleResponse' :: Maybe [CreateVehicleResponseItem]
vehicles = Maybe [CreateVehicleResponseItem]
a} :: BatchCreateVehicleResponse) 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.
batchCreateVehicleResponse_httpStatus :: Lens.Lens' BatchCreateVehicleResponse Prelude.Int
batchCreateVehicleResponse_httpStatus :: Lens' BatchCreateVehicleResponse Int
batchCreateVehicleResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchCreateVehicleResponse' {Int
httpStatus :: Int
$sel:httpStatus:BatchCreateVehicleResponse' :: BatchCreateVehicleResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: BatchCreateVehicleResponse
s@BatchCreateVehicleResponse' {} Int
a -> BatchCreateVehicleResponse
s {$sel:httpStatus:BatchCreateVehicleResponse' :: Int
httpStatus = Int
a} :: BatchCreateVehicleResponse)

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