/**
 * Account and Transaction API SpecificationLib
 *
 * This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
 */

import { lazy, number, object, optional, Schema, string } from '../schema';
import { InstructedAmount, instructedAmountSchema } from './instructedAmount';

/** Set of elements used to provide details on the currency exchange. */
export interface CurrencyExchange {
  /** Currency from which an amount is to be converted in a currency conversion. */
  sourceCurrency: string;
  /** Currency from which an amount is to be converted in a currency conversion. */
  targetCurrency?: string;
  /** Currency from which an amount is to be converted in a currency conversion. */
  unitCurrency?: string;
  /**
   * Factor used to convert an amount from one currency into another. This reflects the price at which one currency was bought with another currency.
   * Usage: ExchangeRate expresses the ratio between UnitCurrency and QuotedCurrency (ExchangeRate = UnitCurrency/QuotedCurrency).
   */
  exchangeRate: number;
  /** Unique identification to unambiguously identify the foreign exchange contract. */
  contractIdentification?: string;
  /**
   * Date and time at which an exchange rate is quoted.
   * All dates in the JSON payloads are represented in ISO 8601 date-time format.
   * All date-time fields in responses must include the timezone. An example is below:
   * 2017-04-05T10:43:07+00:00
   */
  quotationDate?: string;
  /** Amount of money of the cash balance after a transaction entry is applied to the account.. */
  instructedAmount?: InstructedAmount;
}

export const currencyExchangeSchema: Schema<CurrencyExchange> = object({
  sourceCurrency: ['SourceCurrency', string()],
  targetCurrency: ['TargetCurrency', optional(string())],
  unitCurrency: ['UnitCurrency', optional(string())],
  exchangeRate: ['ExchangeRate', number()],
  contractIdentification: ['ContractIdentification', optional(string())],
  quotationDate: ['QuotationDate', optional(string())],
  instructedAmount: [
    'InstructedAmount',
    optional(lazy(() => instructedAmountSchema)),
  ],
});
