/* tslint:disable */
/* eslint-disable */
/**
 * Ringer Business API
 * This API provides comprehensive endpoints for the Ringer Business system. It includes functionality for managing customer accounts, addresses, sites, phone numbers, payments, users, and other business resources.  Operations typically require authentication and appropriate permissions. 
 *
 * The version of the OpenAPI document: 1.0.6
 * Contact: support@ringer.tel
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


import * as runtime from '../runtime';
import type {
  PaymentListResponse,
  PaymentResponse,
  PaymentsComponentsSchemasError,
} from '../models/index';
import {
    PaymentListResponseFromJSON,
    PaymentListResponseToJSON,
    PaymentResponseFromJSON,
    PaymentResponseToJSON,
    PaymentsComponentsSchemasErrorFromJSON,
    PaymentsComponentsSchemasErrorToJSON,
} from '../models/index';

export interface CreatePaymentRequest {
    amountInDollars: number;
}

export interface ListPaymentsRequest {
    pageSize?: number;
    page?: number;
}

/**
 * 
 */
export class PaymentsApi extends runtime.BaseAPI {

    /**
     * Initiates a new payment on the authenticated account. The payment is typically made using the account\'s default or highest priority verified payment method. The request specifies the amount to be paid. 
     * Create a Payment
     */
    async createPaymentRaw(requestParameters: CreatePaymentRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<PaymentResponse>> {
        if (requestParameters['amountInDollars'] == null) {
            throw new runtime.RequiredError(
                'amountInDollars',
                'Required parameter "amountInDollars" was null or undefined when calling createPayment().'
            );
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.accessToken) {
            // oauth required
            headerParameters["Authorization"] = await this.configuration.accessToken("oAuth2", []);
        }

        const consumes: runtime.Consume[] = [
            { contentType: 'application/x-www-form-urlencoded' },
        ];
        // @ts-ignore: canConsumeForm may be unused
        const canConsumeForm = runtime.canConsumeForm(consumes);

        let formParams: { append(param: string, value: any): any };
        let useForm = false;
        if (useForm) {
            formParams = new FormData();
        } else {
            formParams = new URLSearchParams();
        }

        if (requestParameters['amountInDollars'] != null) {
            formParams.append('amount_in_dollars', requestParameters['amountInDollars'] as any);
        }

        const response = await this.request({
            path: `/payments`,
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
            body: formParams,
        }, initOverrides);

        return new runtime.JSONApiResponse(response, (jsonValue) => PaymentResponseFromJSON(jsonValue));
    }

    /**
     * Initiates a new payment on the authenticated account. The payment is typically made using the account\'s default or highest priority verified payment method. The request specifies the amount to be paid. 
     * Create a Payment
     */
    async createPayment(requestParameters: CreatePaymentRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<PaymentResponse> {
        const response = await this.createPaymentRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Retrieves a paginated list of payments made on the authenticated account. The list is typically ordered by creation date, with the most recent payments first. 
     * List Payments
     */
    async listPaymentsRaw(requestParameters: ListPaymentsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<PaymentListResponse>> {
        const queryParameters: any = {};

        if (requestParameters['pageSize'] != null) {
            queryParameters['page_size'] = requestParameters['pageSize'];
        }

        if (requestParameters['page'] != null) {
            queryParameters['page'] = requestParameters['page'];
        }

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.accessToken) {
            // oauth required
            headerParameters["Authorization"] = await this.configuration.accessToken("oAuth2", []);
        }

        const response = await this.request({
            path: `/payments`,
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.JSONApiResponse(response, (jsonValue) => PaymentListResponseFromJSON(jsonValue));
    }

    /**
     * Retrieves a paginated list of payments made on the authenticated account. The list is typically ordered by creation date, with the most recent payments first. 
     * List Payments
     */
    async listPayments(requestParameters: ListPaymentsRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<PaymentListResponse> {
        const response = await this.listPaymentsRaw(requestParameters, initOverrides);
        return await response.value();
    }

}
