/**
 * Paypal Server SDKLib
 *
 * This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
 */

import { array, lazy, object, optional, Schema } from '../schema';
import {
  CheckoutPaymentIntent,
  checkoutPaymentIntentSchema,
} from './checkoutPaymentIntent';
import {
  OrderApplicationContext,
  orderApplicationContextSchema,
} from './orderApplicationContext';
import { Payer, payerSchema } from './payer';
import { PaymentSource, paymentSourceSchema } from './paymentSource';
import {
  PurchaseUnitRequest,
  purchaseUnitRequestSchema,
} from './purchaseUnitRequest';

/** The order request details. */
export interface OrderRequest {
  /** The intent to either capture payment immediately or authorize a payment for an order after order creation. */
  intent: CheckoutPaymentIntent;
  payer?: Payer;
  /** An array of purchase units. Each purchase unit establishes a contract between a payer and the payee. Each purchase unit represents either a full or partial order that the payer intends to purchase from the payee. */
  purchaseUnits: PurchaseUnitRequest[];
  /** The payment source definition. */
  paymentSource?: PaymentSource;
  /** Customizes the payer experience during the approval process for the payment with PayPal.<blockquote><strong>Note:</strong> Partners and Marketplaces might configure <code>brand_name</code> and <code>shipping_preference</code> during partner account setup, which overrides the request values.</blockquote> */
  applicationContext?: OrderApplicationContext;
}

export const orderRequestSchema: Schema<OrderRequest> = object({
  intent: ['intent', checkoutPaymentIntentSchema],
  payer: ['payer', optional(lazy(() => payerSchema))],
  purchaseUnits: [
    'purchase_units',
    array(lazy(() => purchaseUnitRequestSchema)),
  ],
  paymentSource: ['payment_source', optional(lazy(() => paymentSourceSchema))],
  applicationContext: [
    'application_context',
    optional(lazy(() => orderApplicationContextSchema)),
  ],
});
