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

import { lazy, object, optional, Schema, string } from '../schema';
import {
  ApplePayAttributes,
  applePayAttributesSchema,
} from './applePayAttributes';
import {
  ApplePayDecryptedTokenData,
  applePayDecryptedTokenDataSchema,
} from './applePayDecryptedTokenData';
import {
  CardStoredCredential,
  cardStoredCredentialSchema,
} from './cardStoredCredential';
import { PhoneNumber, phoneNumberSchema } from './phoneNumber';

/** Information needed to pay using ApplePay. */
export interface ApplePayRequest {
  /** ApplePay transaction identifier, this will be the unique identifier for this transaction provided by Apple. The pattern is defined by an external party and supports Unicode. */
  id?: string;
  /** The full name representation like Mr J Smith. */
  name?: string;
  /** The internationalized email address.<blockquote><strong>Note:</strong> Up to 64 characters are allowed before and 255 characters are allowed after the <code>@</code> sign. However, the generally accepted maximum length for an email address is 254 characters. The pattern verifies that an unquoted <code>@</code> sign exists.</blockquote> */
  emailAddress?: string;
  /** The phone number in its canonical international [E.164 numbering plan format](https://www.itu.int/rec/T-REC-E.164/en). */
  phoneNumber?: PhoneNumber;
  /** Information about the Payment data obtained by decrypting Apple Pay token. */
  decryptedToken?: ApplePayDecryptedTokenData;
  /** Provides additional details to process a payment using a `card` that has been stored or is intended to be stored (also referred to as stored_credential or card-on-file).<br/>Parameter compatibility:<br/><ul><li>`payment_type=ONE_TIME` is compatible only with `payment_initiator=CUSTOMER`.</li><li>`usage=FIRST` is compatible only with `payment_initiator=CUSTOMER`.</li><li>`previous_transaction_reference` or `previous_network_transaction_reference` is compatible only with `payment_initiator=MERCHANT`.</li><li>Only one of the parameters - `previous_transaction_reference` and `previous_network_transaction_reference` - can be present in the request.</li></ul> */
  storedCredential?: CardStoredCredential;
  /** The PayPal-generated ID for the vaulted payment source. This ID should be stored on the merchant's server so the saved payment source can be used for future transactions. */
  vaultId?: string;
  /** Additional attributes associated with apple pay. */
  attributes?: ApplePayAttributes;
}

export const applePayRequestSchema: Schema<ApplePayRequest> = object({
  id: ['id', optional(string())],
  name: ['name', optional(string())],
  emailAddress: ['email_address', optional(string())],
  phoneNumber: ['phone_number', optional(lazy(() => phoneNumberSchema))],
  decryptedToken: [
    'decrypted_token',
    optional(lazy(() => applePayDecryptedTokenDataSchema)),
  ],
  storedCredential: [
    'stored_credential',
    optional(lazy(() => cardStoredCredentialSchema)),
  ],
  vaultId: ['vault_id', optional(string())],
  attributes: ['attributes', optional(lazy(() => applePayAttributesSchema))],
});
