{-# 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.Outposts.CreateOrder
-- 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)
--
-- Creates an order for an Outpost.
module Amazonka.Outposts.CreateOrder
  ( -- * Creating a Request
    CreateOrder (..),
    newCreateOrder,

    -- * Request Lenses
    createOrder_paymentTerm,
    createOrder_outpostIdentifier,
    createOrder_lineItems,
    createOrder_paymentOption,

    -- * Destructuring the Response
    CreateOrderResponse (..),
    newCreateOrderResponse,

    -- * Response Lenses
    createOrderResponse_order,
    createOrderResponse_httpStatus,
  )
where

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

-- | /See:/ 'newCreateOrder' smart constructor.
data CreateOrder = CreateOrder'
  { -- | The payment terms for the order.
    CreateOrder -> Maybe PaymentTerm
paymentTerm :: Prelude.Maybe PaymentTerm,
    -- | The ID or the Amazon Resource Name (ARN) of the Outpost.
    CreateOrder -> Text
outpostIdentifier :: Prelude.Text,
    -- | The line items that make up the order.
    CreateOrder -> NonEmpty LineItemRequest
lineItems :: Prelude.NonEmpty LineItemRequest,
    -- | The payment option for the order.
    CreateOrder -> PaymentOption
paymentOption :: PaymentOption
  }
  deriving (CreateOrder -> CreateOrder -> Bool
(CreateOrder -> CreateOrder -> Bool)
-> (CreateOrder -> CreateOrder -> Bool) -> Eq CreateOrder
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateOrder -> CreateOrder -> Bool
$c/= :: CreateOrder -> CreateOrder -> Bool
== :: CreateOrder -> CreateOrder -> Bool
$c== :: CreateOrder -> CreateOrder -> Bool
Prelude.Eq, ReadPrec [CreateOrder]
ReadPrec CreateOrder
Int -> ReadS CreateOrder
ReadS [CreateOrder]
(Int -> ReadS CreateOrder)
-> ReadS [CreateOrder]
-> ReadPrec CreateOrder
-> ReadPrec [CreateOrder]
-> Read CreateOrder
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateOrder]
$creadListPrec :: ReadPrec [CreateOrder]
readPrec :: ReadPrec CreateOrder
$creadPrec :: ReadPrec CreateOrder
readList :: ReadS [CreateOrder]
$creadList :: ReadS [CreateOrder]
readsPrec :: Int -> ReadS CreateOrder
$creadsPrec :: Int -> ReadS CreateOrder
Prelude.Read, Int -> CreateOrder -> ShowS
[CreateOrder] -> ShowS
CreateOrder -> String
(Int -> CreateOrder -> ShowS)
-> (CreateOrder -> String)
-> ([CreateOrder] -> ShowS)
-> Show CreateOrder
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateOrder] -> ShowS
$cshowList :: [CreateOrder] -> ShowS
show :: CreateOrder -> String
$cshow :: CreateOrder -> String
showsPrec :: Int -> CreateOrder -> ShowS
$cshowsPrec :: Int -> CreateOrder -> ShowS
Prelude.Show, (forall x. CreateOrder -> Rep CreateOrder x)
-> (forall x. Rep CreateOrder x -> CreateOrder)
-> Generic CreateOrder
forall x. Rep CreateOrder x -> CreateOrder
forall x. CreateOrder -> Rep CreateOrder x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateOrder x -> CreateOrder
$cfrom :: forall x. CreateOrder -> Rep CreateOrder x
Prelude.Generic)

-- |
-- Create a value of 'CreateOrder' 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:
--
-- 'paymentTerm', 'createOrder_paymentTerm' - The payment terms for the order.
--
-- 'outpostIdentifier', 'createOrder_outpostIdentifier' - The ID or the Amazon Resource Name (ARN) of the Outpost.
--
-- 'lineItems', 'createOrder_lineItems' - The line items that make up the order.
--
-- 'paymentOption', 'createOrder_paymentOption' - The payment option for the order.
newCreateOrder ::
  -- | 'outpostIdentifier'
  Prelude.Text ->
  -- | 'lineItems'
  Prelude.NonEmpty LineItemRequest ->
  -- | 'paymentOption'
  PaymentOption ->
  CreateOrder
newCreateOrder :: Text -> NonEmpty LineItemRequest -> PaymentOption -> CreateOrder
newCreateOrder
  Text
pOutpostIdentifier_
  NonEmpty LineItemRequest
pLineItems_
  PaymentOption
pPaymentOption_ =
    CreateOrder' :: Maybe PaymentTerm
-> Text -> NonEmpty LineItemRequest -> PaymentOption -> CreateOrder
CreateOrder'
      { $sel:paymentTerm:CreateOrder' :: Maybe PaymentTerm
paymentTerm = Maybe PaymentTerm
forall a. Maybe a
Prelude.Nothing,
        $sel:outpostIdentifier:CreateOrder' :: Text
outpostIdentifier = Text
pOutpostIdentifier_,
        $sel:lineItems:CreateOrder' :: NonEmpty LineItemRequest
lineItems = Tagged
  (NonEmpty LineItemRequest) (Identity (NonEmpty LineItemRequest))
-> Tagged
     (NonEmpty LineItemRequest) (Identity (NonEmpty LineItemRequest))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged
   (NonEmpty LineItemRequest) (Identity (NonEmpty LineItemRequest))
 -> Tagged
      (NonEmpty LineItemRequest) (Identity (NonEmpty LineItemRequest)))
-> NonEmpty LineItemRequest -> NonEmpty LineItemRequest
forall t b. AReview t b -> b -> t
Lens.# NonEmpty LineItemRequest
pLineItems_,
        $sel:paymentOption:CreateOrder' :: PaymentOption
paymentOption = PaymentOption
pPaymentOption_
      }

-- | The payment terms for the order.
createOrder_paymentTerm :: Lens.Lens' CreateOrder (Prelude.Maybe PaymentTerm)
createOrder_paymentTerm :: (Maybe PaymentTerm -> f (Maybe PaymentTerm))
-> CreateOrder -> f CreateOrder
createOrder_paymentTerm = (CreateOrder -> Maybe PaymentTerm)
-> (CreateOrder -> Maybe PaymentTerm -> CreateOrder)
-> Lens
     CreateOrder CreateOrder (Maybe PaymentTerm) (Maybe PaymentTerm)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateOrder' {Maybe PaymentTerm
paymentTerm :: Maybe PaymentTerm
$sel:paymentTerm:CreateOrder' :: CreateOrder -> Maybe PaymentTerm
paymentTerm} -> Maybe PaymentTerm
paymentTerm) (\s :: CreateOrder
s@CreateOrder' {} Maybe PaymentTerm
a -> CreateOrder
s {$sel:paymentTerm:CreateOrder' :: Maybe PaymentTerm
paymentTerm = Maybe PaymentTerm
a} :: CreateOrder)

-- | The ID or the Amazon Resource Name (ARN) of the Outpost.
createOrder_outpostIdentifier :: Lens.Lens' CreateOrder Prelude.Text
createOrder_outpostIdentifier :: (Text -> f Text) -> CreateOrder -> f CreateOrder
createOrder_outpostIdentifier = (CreateOrder -> Text)
-> (CreateOrder -> Text -> CreateOrder)
-> Lens CreateOrder CreateOrder Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateOrder' {Text
outpostIdentifier :: Text
$sel:outpostIdentifier:CreateOrder' :: CreateOrder -> Text
outpostIdentifier} -> Text
outpostIdentifier) (\s :: CreateOrder
s@CreateOrder' {} Text
a -> CreateOrder
s {$sel:outpostIdentifier:CreateOrder' :: Text
outpostIdentifier = Text
a} :: CreateOrder)

-- | The line items that make up the order.
createOrder_lineItems :: Lens.Lens' CreateOrder (Prelude.NonEmpty LineItemRequest)
createOrder_lineItems :: (NonEmpty LineItemRequest -> f (NonEmpty LineItemRequest))
-> CreateOrder -> f CreateOrder
createOrder_lineItems = (CreateOrder -> NonEmpty LineItemRequest)
-> (CreateOrder -> NonEmpty LineItemRequest -> CreateOrder)
-> Lens
     CreateOrder
     CreateOrder
     (NonEmpty LineItemRequest)
     (NonEmpty LineItemRequest)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateOrder' {NonEmpty LineItemRequest
lineItems :: NonEmpty LineItemRequest
$sel:lineItems:CreateOrder' :: CreateOrder -> NonEmpty LineItemRequest
lineItems} -> NonEmpty LineItemRequest
lineItems) (\s :: CreateOrder
s@CreateOrder' {} NonEmpty LineItemRequest
a -> CreateOrder
s {$sel:lineItems:CreateOrder' :: NonEmpty LineItemRequest
lineItems = NonEmpty LineItemRequest
a} :: CreateOrder) ((NonEmpty LineItemRequest -> f (NonEmpty LineItemRequest))
 -> CreateOrder -> f CreateOrder)
-> ((NonEmpty LineItemRequest -> f (NonEmpty LineItemRequest))
    -> NonEmpty LineItemRequest -> f (NonEmpty LineItemRequest))
-> (NonEmpty LineItemRequest -> f (NonEmpty LineItemRequest))
-> CreateOrder
-> f CreateOrder
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty LineItemRequest -> f (NonEmpty LineItemRequest))
-> NonEmpty LineItemRequest -> f (NonEmpty LineItemRequest)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The payment option for the order.
createOrder_paymentOption :: Lens.Lens' CreateOrder PaymentOption
createOrder_paymentOption :: (PaymentOption -> f PaymentOption) -> CreateOrder -> f CreateOrder
createOrder_paymentOption = (CreateOrder -> PaymentOption)
-> (CreateOrder -> PaymentOption -> CreateOrder)
-> Lens CreateOrder CreateOrder PaymentOption PaymentOption
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateOrder' {PaymentOption
paymentOption :: PaymentOption
$sel:paymentOption:CreateOrder' :: CreateOrder -> PaymentOption
paymentOption} -> PaymentOption
paymentOption) (\s :: CreateOrder
s@CreateOrder' {} PaymentOption
a -> CreateOrder
s {$sel:paymentOption:CreateOrder' :: PaymentOption
paymentOption = PaymentOption
a} :: CreateOrder)

instance Core.AWSRequest CreateOrder where
  type AWSResponse CreateOrder = CreateOrderResponse
  request :: CreateOrder -> Request CreateOrder
request = Service -> CreateOrder -> Request CreateOrder
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateOrder
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateOrder)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateOrder))
-> Logger
-> Service
-> Proxy CreateOrder
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateOrder)))
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 Order -> Int -> CreateOrderResponse
CreateOrderResponse'
            (Maybe Order -> Int -> CreateOrderResponse)
-> Either String (Maybe Order)
-> Either String (Int -> CreateOrderResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Order)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Order")
            Either String (Int -> CreateOrderResponse)
-> Either String Int -> Either String CreateOrderResponse
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 CreateOrder

instance Prelude.NFData CreateOrder

instance Core.ToHeaders CreateOrder where
  toHeaders :: CreateOrder -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateOrder -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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 CreateOrder where
  toJSON :: CreateOrder -> Value
toJSON CreateOrder' {Maybe PaymentTerm
NonEmpty LineItemRequest
Text
PaymentOption
paymentOption :: PaymentOption
lineItems :: NonEmpty LineItemRequest
outpostIdentifier :: Text
paymentTerm :: Maybe PaymentTerm
$sel:paymentOption:CreateOrder' :: CreateOrder -> PaymentOption
$sel:lineItems:CreateOrder' :: CreateOrder -> NonEmpty LineItemRequest
$sel:outpostIdentifier:CreateOrder' :: CreateOrder -> Text
$sel:paymentTerm:CreateOrder' :: CreateOrder -> Maybe PaymentTerm
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"PaymentTerm" Text -> PaymentTerm -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (PaymentTerm -> Pair) -> Maybe PaymentTerm -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe PaymentTerm
paymentTerm,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"OutpostIdentifier" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
outpostIdentifier),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"LineItems" Text -> NonEmpty LineItemRequest -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty LineItemRequest
lineItems),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"PaymentOption" Text -> PaymentOption -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= PaymentOption
paymentOption)
          ]
      )

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

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

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

-- |
-- Create a value of 'CreateOrderResponse' 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:
--
-- 'order', 'createOrderResponse_order' - Information about this order.
--
-- 'httpStatus', 'createOrderResponse_httpStatus' - The response's http status code.
newCreateOrderResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateOrderResponse
newCreateOrderResponse :: Int -> CreateOrderResponse
newCreateOrderResponse Int
pHttpStatus_ =
  CreateOrderResponse' :: Maybe Order -> Int -> CreateOrderResponse
CreateOrderResponse'
    { $sel:order:CreateOrderResponse' :: Maybe Order
order = Maybe Order
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateOrderResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about this order.
createOrderResponse_order :: Lens.Lens' CreateOrderResponse (Prelude.Maybe Order)
createOrderResponse_order :: (Maybe Order -> f (Maybe Order))
-> CreateOrderResponse -> f CreateOrderResponse
createOrderResponse_order = (CreateOrderResponse -> Maybe Order)
-> (CreateOrderResponse -> Maybe Order -> CreateOrderResponse)
-> Lens
     CreateOrderResponse CreateOrderResponse (Maybe Order) (Maybe Order)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateOrderResponse' {Maybe Order
order :: Maybe Order
$sel:order:CreateOrderResponse' :: CreateOrderResponse -> Maybe Order
order} -> Maybe Order
order) (\s :: CreateOrderResponse
s@CreateOrderResponse' {} Maybe Order
a -> CreateOrderResponse
s {$sel:order:CreateOrderResponse' :: Maybe Order
order = Maybe Order
a} :: CreateOrderResponse)

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

instance Prelude.NFData CreateOrderResponse